From 5f68fd9dfd4f043623848a6f5e033db92960e64c Mon Sep 17 00:00:00 2001 From: vlorenzo Date: Tue, 14 May 2013 12:31:42 +0000 Subject: 407986: [Table 2] The user must be able to disconnect the slave axis (automatic addition of axis on the slave) https://bugs.eclipse.org/bugs/show_bug.cgi?id=407986 Change the dialog to choose visible columns to manage the property disconnect slave --- .../editors/MultipleValueSelectorDialog.java | 13 +- .../MultipleValueSelectorDialogWithCheckBox.java | 201 +++++++++++++++++++++ .../dialog/DisplayedAxisSelectorDialog.java | 127 +++++++++++++ .../manager/table/NattableModelManager.java | 39 +++- .../papyrus/infra/nattable/messages/Messages.java | 8 + .../infra/nattable/messages/messages.properties | 4 + 6 files changed, 385 insertions(+), 7 deletions(-) create mode 100644 plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialogWithCheckBox.java create mode 100644 sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/dialog/DisplayedAxisSelectorDialog.java diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java index 01abc8a35b9..9dd432901c6 100644 --- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java +++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java @@ -261,7 +261,16 @@ public class MultipleValueSelectorDialog extends SelectionDialog implements ISel @Override public void create() { super.create(); + createDialogContents(); + getShell().pack(); + updateControls(); + } + + /** + * Create the contents of the dialog + */ + protected void createDialogContents() { Composite parent = getDialogArea(); GridLayout layout = (GridLayout)parent.getLayout(); layout.numColumns = 2; @@ -279,10 +288,6 @@ public class MultipleValueSelectorDialog extends SelectionDialog implements ISel createControlsSection(selectorPane); createListSection(selectedPane); createRightButtonsSection(selectedPane); - - getShell().pack(); - - updateControls(); } /** diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialogWithCheckBox.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialogWithCheckBox.java new file mode 100644 index 00000000000..2dde6d3fcf6 --- /dev/null +++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialogWithCheckBox.java @@ -0,0 +1,201 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.widgets.editors; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/** + * This dialog adds a checkbox at the end of the {@link MultipleValueSelectorDialog} + * + * @author vl222926 + * + */ +public class MultipleValueSelectorDialogWithCheckBox extends MultipleValueSelectorDialog { + + /** boolean indicating if the checkbox is checked */ + protected boolean isChecked; + + /** The text to display for the checkbox */ + protected String text; + + /** the tooltip to display for the checkbox */ + protected String tooltip; + + /** indicates if the checkbox must be displayed or not */ + protected boolean displayCheckBox = true; + + /** + * + * Constructor. + * + * @param parentShell + * @param selector + * @param unique + */ + public MultipleValueSelectorDialogWithCheckBox(Shell parentShell, IElementSelector selector, boolean unique) { + super(parentShell, selector, unique); + } + + /** + * + * Constructor. + * + * @param parentShell + * @param selector + * @param title + * @param unique + * @param ordered + * @param upperBound + */ + public MultipleValueSelectorDialogWithCheckBox(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered, int upperBound) { + super(parentShell, selector, title, unique, ordered, upperBound); + } + + /** + * + * Constructor. + * + * @param parentShell + * @param selector + * @param title + * @param unique + * @param ordered + */ + public MultipleValueSelectorDialogWithCheckBox(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered) { + super(parentShell, selector, title, unique, ordered); + } + + /** + * + * Constructor. + * + * @param parentShell + * @param selector + * @param title + */ + public MultipleValueSelectorDialogWithCheckBox(Shell parentShell, IElementSelector selector, String title) { + super(parentShell, selector, title); + } + + /** + * + * Constructor. + * + * @param parentShell + * @param selector + */ + public MultipleValueSelectorDialogWithCheckBox(Shell parentShell, IElementSelector selector) { + super(parentShell, selector); + } + + /** + * + * @param text + * the text to display near the checkbox + * @param tooltip + * the tooltip to display for the checkbox + * @param isChecked + * the initial state of the checkbox + */ + public void setCheckBoxValues(final String text, final String tooltip, final boolean isChecked) { + this.text = text; + this.tooltip = tooltip; + this.isChecked = isChecked; + } + + /** + * this method allows to display or hide the checkbox + */ + public void setDisplayCheckBox(boolean displayCheckBox) { + this.displayCheckBox = displayCheckBox; + } + + /** + * + * @return + * true if the disalog is displaying the checkbox + */ + public boolean isDisplayingCheckBox() { + return this.displayCheckBox; + } + + /** + * We Add a checkbox at the end of the dialog + * + * @see org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog#createDialogContents() + * + */ + @Override + protected void createDialogContents() { + super.createDialogContents(); + if(this.displayCheckBox) { + final Composite parent = getDialogArea(); + final Button button = new Button(parent, SWT.CHECK); + button.setText(this.text); + button.setToolTipText(this.tooltip); + button.setSelection(true); + final SelectionListener listener = new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + isChecked = button.getSelection(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + button.addSelectionListener(listener); + } + } + + + /** + * + * @return + * the state of the checkbox button + */ + public boolean isChecked() { + return this.isChecked; + } + + + /** + * + * @see org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog#okPressed() + * + */ + @Override + protected void okPressed() { + boolean mustContinue = true;; + if(displayCheckBox && !isChecked) { + final String title = "Axis Selection Question"; + final String message = String.format("The checkbox '%s' has not been checked, so the next row addition could be followed by a column addition, ignoring your current column selection. \n \n Do you want to continue?", this.text); + mustContinue = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), title, message); + } + if(mustContinue) { + super.okPressed(); + } + } + +} diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/dialog/DisplayedAxisSelectorDialog.java b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/dialog/DisplayedAxisSelectorDialog.java new file mode 100644 index 00000000000..72391a24b7e --- /dev/null +++ b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/dialog/DisplayedAxisSelectorDialog.java @@ -0,0 +1,127 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.dialog; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialogWithCheckBox; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/** + * This dialog adds a specific action on the okPressed() (opening a dialog) + * + * @author vl222926 + * + */ +public class DisplayedAxisSelectorDialog extends MultipleValueSelectorDialogWithCheckBox { + + /** + * the title of the information dialog + */ + private String informationDialogTitle; + + /** + * the message of the information dialog + */ + private String informationDialogMessage; + + /** + * Constructor. + * + * @param parentShell + * @param selector + * @param unique + */ + public DisplayedAxisSelectorDialog(Shell parentShell, IElementSelector selector, boolean unique) { + super(parentShell, selector, unique); + } + + /** + * Constructor. + * + * @param parentShell + * @param selector + * @param title + * @param unique + * @param ordered + * @param upperBound + */ + public DisplayedAxisSelectorDialog(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered, int upperBound) { + super(parentShell, selector, title, unique, ordered, upperBound); + } + + /** + * Constructor. + * + * @param parentShell + * @param selector + * @param title + * @param unique + * @param ordered + */ + public DisplayedAxisSelectorDialog(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered) { + super(parentShell, selector, title, unique, ordered); + } + + /** + * Constructor. + * + * @param parentShell + * @param selector + * @param title + */ + public DisplayedAxisSelectorDialog(Shell parentShell, IElementSelector selector, String title) { + super(parentShell, selector, title); + } + + /** + * Constructor. + * + * @param parentShell + * @param selector + */ + public DisplayedAxisSelectorDialog(Shell parentShell, IElementSelector selector) { + super(parentShell, selector); + } + + /** + * + * @param title + * the title for the information dialog + * @param message + * the message for the information dialog + */ + public void setInformationDialogValues(final String title, final String message) { + this.informationDialogTitle = title; + this.informationDialogMessage = message; + } + + /** + * + * @see org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog#okPressed() + * + */ + @Override + protected void okPressed() { + boolean mustContinue = true;; + if(displayCheckBox && !isChecked) { + mustContinue = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), informationDialogTitle, informationDialogMessage); + } + if(mustContinue) { + super.okPressed(); + } + } + +} diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java index e89955a1a21..3e2b0c84eec 100644 --- a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java +++ b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java @@ -31,6 +31,8 @@ import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.edit.command.SetCommand; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ViewerComparator; @@ -38,11 +40,13 @@ import org.eclipse.jface.window.Window; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.data.IDataProvider; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.core.services.ServiceException; import org.eclipse.papyrus.infra.core.services.ServicesRegistry; import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; import org.eclipse.papyrus.infra.nattable.Activator; import org.eclipse.papyrus.infra.nattable.command.CommandIds; +import org.eclipse.papyrus.infra.nattable.dialog.DisplayedAxisSelectorDialog; import org.eclipse.papyrus.infra.nattable.manager.axis.AxisManagerFactory; import org.eclipse.papyrus.infra.nattable.manager.axis.CompositeAxisManager; import org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager; @@ -56,6 +60,7 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfigurati import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.IMasterAxisProvider; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.ISlaveAxisProvider; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.CellEditorDeclaration; import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.FeatureLabelProviderConfiguration; import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ILabelProviderConfiguration; @@ -64,8 +69,9 @@ import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils; import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes; import org.eclipse.papyrus.infra.nattable.utils.StringComparator; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; -import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog; import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; @@ -114,10 +120,19 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen private FocusListener focusListener; /** - * we need to keep it to be able to remove listener (required when we destory the context of the table) + * we need to keep it to be able to remove listener (required when we destroy the context of the table) */ private TransactionalEditingDomain contextEditingDomain; + /** message used in the Add/Remove axis dialog */ + private static final String AXIS_MANAGER_DIALOG_CHECKBOX_TEXT = Messages.NattableModelManager_DisconnectAxisManagerCheckBoxMessage; + + private static final String AXIS_MANAGER_ROW_DIALOG_CHECKBOX_TOOLTIP = Messages.NattableModelManager_DisconnectAxisManagerCheckBoxTooltip; + + private static final String AXIS_MANAGER_INFORMATION_DIALOG_TITLE = Messages.NattableModelManager_DisconnectAxisManagerInformationDialogTitle; + + private static final String AXIS_MANAGER_COLUMN_INFORMATION_DIALOG_MESSAGE = String.format(Messages.NattableModelManager_DisconnectAxisManagerInformationDialogMessage, AXIS_MANAGER_DIALOG_CHECKBOX_TEXT); + /** * * Constructor. @@ -847,7 +862,15 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen if(provider != null) {//FIXME : the action must be hidden when it is not possible to select the columns selector.setContentProvider(new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider)provider, selector)); - MultipleValueSelectorDialog dialog = new MultipleValueSelectorDialog(Display.getDefault().getActiveShell(), selector, Messages.NattableModelManager_SelectColumns, true, false, -1); + final DisplayedAxisSelectorDialog dialog = new DisplayedAxisSelectorDialog(Display.getDefault().getActiveShell(), selector, Messages.NattableModelManager_SelectColumns, true, false, -1); + boolean displayCheckBox = columnProvider instanceof ISlaveAxisProvider; + boolean checkboxValue = ((IMasterAxisProvider)rowProvider).isDisconnectSlave(); + dialog.setDisplayCheckBox(displayCheckBox); + if(displayCheckBox) { + dialog.setCheckBoxValues(AXIS_MANAGER_DIALOG_CHECKBOX_TEXT, AXIS_MANAGER_ROW_DIALOG_CHECKBOX_TOOLTIP, checkboxValue); + } + + dialog.setInformationDialogValues(AXIS_MANAGER_INFORMATION_DIALOG_TITLE, AXIS_MANAGER_COLUMN_INFORMATION_DIALOG_MESSAGE); dialog.setLabelProvider(serv.getLabelProvider()); dialog.setInitialElementSelections(new ArrayList(this.columnManager.getAllManagedAxis())); @@ -872,8 +895,18 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen Command destroyColumnElementCommand = getDestroyColumnElementCommand(columnsToDelete); compoundCommand.append(destroyColumnElementCommand); } + + final boolean newState = dialog.isChecked(); + if(displayCheckBox && checkboxValue != newState) { + final TransactionalEditingDomain domain = (TransactionalEditingDomain)getTableEditingDomain(); + final IEditCommandRequest request = new SetRequest(domain, rowProvider, NattableaxisproviderPackage.eINSTANCE.getIMasterAxisProvider_DisconnectSlave(), newState); + final IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(rowProvider); + compoundCommand.append(new GMFtoEMFCommandWrapper(commandProvider.getEditCommand(request))); + } + if(!compoundCommand.isEmpty()) { getContextEditingDomain().getCommandStack().execute(compoundCommand); + updateToggleActionState(); } } } else { diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java index 79bf06603d3..d497756c6a7 100644 --- a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java +++ b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java @@ -73,6 +73,14 @@ public class Messages extends NLS { public static String NattableModelManager_CreateDestroyAxis; + public static String NattableModelManager_DisconnectAxisManagerCheckBoxMessage; + + public static String NattableModelManager_DisconnectAxisManagerCheckBoxTooltip; + + public static String NattableModelManager_DisconnectAxisManagerInformationDialogMessage; + + public static String NattableModelManager_DisconnectAxisManagerInformationDialogTitle; + public static String NattableModelManager_EditingDomainNotFound; public static String NattableModelManager_SelectColumns; diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties index 047979cdad8..60d1d11c1aa 100644 --- a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties +++ b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties @@ -25,6 +25,10 @@ CompositeAxisManager_DestroyAxisCommand=Destroy column command NattableModelManager_AddRowCommand=Add rows command NattableModelManager_AtLeastOfOneTheAxisManagerMustBeAMaster=At least one of the AxisManager must be a Master NattableModelManager_CreateDestroyAxis=Create / Destroy Axis +NattableModelManager_DisconnectAxisManagerCheckBoxMessage=Disconnect this axis manager +NattableModelManager_DisconnectAxisManagerCheckBoxTooltip=Disable the automatic addition of columns when a row is added. +NattableModelManager_DisconnectAxisManagerInformationDialogMessage=The checkbox '%s' has not been checked, so the next row addition could be followed by a columns addition, ignoring your current selection of columns. \n \n Do you want to continue? +NattableModelManager_DisconnectAxisManagerInformationDialogTitle=Axis Selection Question NattableModelManager_EditingDomainNotFound=EditingDomain not found NattableModelManager_SelectColumns=Select Columns NattableModelManager_ServiceRegistryNotFound=ServiceRegistry not found -- cgit v1.2.3