Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2017-09-28 15:37:26 +0000
committervincent lorenzo2018-07-02 11:24:30 +0000
commitb7f5326f25235c700f27a7e14c3812c8b7d73345 (patch)
tree29ccccbac7e9c3aa3ccd6052027cbac24c61c8ba /plugins/infra/ui
parent93d12bb72802f36f0e2f5a8855d4626cb434824f (diff)
downloadorg.eclipse.papyrus-b7f5326f25235c700f27a7e14c3812c8b7d73345.tar.gz
org.eclipse.papyrus-b7f5326f25235c700f27a7e14c3812c8b7d73345.tar.xz
org.eclipse.papyrus-b7f5326f25235c700f27a7e14c3812c8b7d73345.zip
Bug 517190: [Properties][MultiEditor] The editor for the multi primitive
types must be modified https://bugs.eclipse.org/bugs/show_bug.cgi?id=517190 - Manage the multiple value as 2 classes: - one for the right and buttons management - the second for the selection widget + widget from the first one Change-Id: I736be0a5331fcccdab5bf94d747d51ff2eadf801 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr> Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/infra/ui')
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/pom.xml2
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractMultipleValueEditor.java30
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java13
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueDialog.java318
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectionDialog.java201
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java7
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueSelectionWidget.java617
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueWidget.java736
9 files changed, 1134 insertions, 792 deletions
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF
index 689007d266e..9eb5a99c0d4 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF
@@ -31,7 +31,7 @@ Export-Package: org.eclipse.papyrus.infra.widgets,
org.eclipse.papyrus.infra.widgets.wizard.pages
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
-Bundle-Version: 3.2.0.qualifier
+Bundle-Version: 3.3.0.qualifier
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-ManifestVersion: 2
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/pom.xml b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/pom.xml
index fc6cb9084f4..d2af3253c1f 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/pom.xml
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/pom.xml
@@ -8,6 +8,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.widgets</artifactId>
- <version>3.2.0-SNAPSHOT</version>
+ <version>3.3.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractMultipleValueEditor.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractMultipleValueEditor.java
index 5ede8613120..ffd08a0941b 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractMultipleValueEditor.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractMultipleValueEditor.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2017 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2010, 2017, 2018 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -13,7 +13,8 @@
* Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - manage buttons visibility and enable.
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 515808
* Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 521902, Bug 526304
- *
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 517190
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.editors;
@@ -250,11 +251,35 @@ public abstract class AbstractMultipleValueEditor<T extends IElementSelector> ex
* @param label
* The editor's label.
* @return The new dialog for this editor
+ *
+ * @deprecated since 3.3 Use/override the {@link #createMultipleValueDialog(Composite, IElementSelector, boolean, boolean, String)} instead.
+ *
*/
+ @Deprecated
protected MultipleValueSelectionDialog createMultipleValueSelectionDialog(Composite parent, IElementSelector selector, boolean ordered, boolean unique, String label) {
return new MultipleValueSelectionDialog(parent.getShell(), selector, label, unique, ordered);
}
+ /**
+ * Creates the dialog for this editor
+ *
+ * @param parent
+ * The Composite in which the dialog should be displayed
+ * @param selector
+ * The element selector for this dialog
+ * @param ordered
+ * Specify if the observed collection is ordered. If true, Up and Down controls are displayed.
+ * @param unique
+ * Specify if the observed collection values are unique.
+ * @param label
+ * The editor's label.
+ * @return The new dialog for this editor
+ * @since 3.3
+ */
+ protected MultipleValueDialog createMultipleValueDialog(Composite parent, IElementSelector selector, boolean ordered, boolean unique, String label) {
+ return new MultipleValueSelectionDialog(parent.getShell(), selector, label, unique, ordered);
+ }
+
@Override
protected GridData getLabelLayoutData() {
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
@@ -869,4 +894,5 @@ public abstract class AbstractMultipleValueEditor<T extends IElementSelector> ex
// nothing to do here
}
+
}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java
index 3013dd34df5..3f2cb89fdb1 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2017 CEA LIST.
+ * Copyright (c) 2010, 2017, 2018 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 521902, Bug 526304
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 517190
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.editors;
@@ -237,6 +238,16 @@ public class MultipleStringEditor<T extends StringSelector> extends MultipleValu
super(parent, style, new StringSelector(), label);
init();
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractMultipleValueEditor#createMultipleValueDialog(org.eclipse.swt.widgets.Composite, org.eclipse.papyrus.infra.widgets.editors.IElementSelector, boolean, boolean, java.lang.String)
+ */
+ @Override
+ protected MultipleValueDialog createMultipleValueDialog(Composite parent, IElementSelector selector, boolean ordered, boolean unique, String label) {
+ return new MultipleValueDialog(parent.getShell(), selector, label, unique, ordered);
+ }
private void init() {
setFactory(new StringEditionFactory());
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueDialog.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueDialog.java
new file mode 100644
index 00000000000..71510bd3497
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueDialog.java
@@ -0,0 +1,318 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.editors;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.infra.widgets.util.ValueUtils;
+import org.eclipse.papyrus.infra.widgets.widgets.MultipleValueSelectionWidget;
+import org.eclipse.papyrus.infra.widgets.widgets.MultipleValueWidget;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+/**
+ * Object Chooser. Defines a standard popup for selecting
+ * multiple values. If this dialog is used to select or create model
+ * elements to be added to or removed from some element that is being
+ * edited, then it is important to {@linkplain #setContextElement(Object) set that contextual element} in this dialog.
+ *
+ * @see #setContextElement(Object)
+ *
+ * @since 3.2
+ */
+public class MultipleValueDialog extends SelectionDialog {
+
+ /**
+ * the widget providing the contents of the dialog
+ */
+ protected MultipleValueWidget widget;
+
+ /**
+ * Constructor.
+ *
+ * @param parentShell
+ * The shell in which this dialog should be opened
+ * @param selector
+ * The element selector used by this dialog
+ */
+ public MultipleValueDialog(Shell parentShell, IElementSelector selector) {
+ this(parentShell, selector, null, false, false);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param parentShell
+ * The shell in which this dialog should be opened
+ * @param selector
+ * The element selector used by this dialog
+ * @param title
+ * The title of this dialog
+ */
+ public MultipleValueDialog(Shell parentShell, IElementSelector selector, String title) {
+ this(parentShell, selector, title, false, false);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * The shell in which this dialog should be opened
+ * @param selector
+ * The element selector used by this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ */
+ public MultipleValueDialog(Shell parentShell, IElementSelector selector, boolean unique) {
+ this(parentShell, selector, null, unique, false);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * The shell in which this dialog should be opened
+ * @param selector
+ * The element selector used by this dialog
+ * @param title
+ * The title of this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ */
+ public MultipleValueDialog(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered) {
+ this(parentShell, selector, title, unique, ordered, ValueUtils.MANY);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * The shell in which this dialog should be opened
+ * @param selector
+ * The element selector used by this dialog
+ * @param title
+ * The title of this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ * @param upperBound
+ * The maximum number of values selected.
+ */
+ public MultipleValueDialog(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered, int upperBound) {
+ super(parentShell);
+ Assert.isNotNull(selector, "The element selector should be defined"); //$NON-NLS-1$
+ setHelpAvailable(false);
+ setTitle(title);
+ this.widget = createWidget(selector, unique, ordered, upperBound);
+ }
+
+ /**
+ *
+ * @param selector
+ * The element selector used by this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ * @param ordered
+ * <code>true</code> if the edited feature is ordered
+ * @param upperBound
+ * The maximum number of values selected.
+ */
+ protected MultipleValueWidget createWidget(IElementSelector selector, boolean unique, boolean ordered, int upperBound) {
+ return new MultipleValueWidget(selector, unique, ordered, upperBound);
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.dialogs.SelectionDialog#configureShell(org.eclipse.swt.widgets.Shell)
+ *
+ * @param shell
+ */
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.ui.dialogs.SelectionDialog#setInitialElementSelections(java.util.List)
+ *
+ * @param selectedElements
+ */
+ @Override
+ public void setInitialElementSelections(@SuppressWarnings("rawtypes") List selectedElements) {
+ super.setInitialElementSelections(selectedElements);
+ widget.setInitialSelections(getInitialElementSelections());
+ }
+
+
+ /**
+ * @see org.eclipse.ui.dialogs.SelectionDialog#setInitialSelections(java.lang.Object[])
+ *
+ * @param selectedElements
+ */
+ @Override
+ public void setInitialSelections(Object[] selectedElements) {
+ super.setInitialSelections(selectedElements);
+ widget.setInitialSelections(getInitialElementSelections());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void create() {
+ super.create();
+ createDialogContents();
+ getShell().pack();
+
+ this.widget.updateControls();
+
+ }
+
+ /**
+ * Create the contents of the dialog
+ */
+ protected void createDialogContents() {
+ Composite parent = getDialogArea();
+ this.widget.create(parent);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Composite getDialogArea() {
+ return (Composite) super.getDialogArea();
+ }
+
+
+ /**
+ * Sets the {@link ReferenceValueFactory} for this editor. The {@link ReferenceValueFactory} is used to create
+ * new instances and edit existing ones.
+ *
+ * @param factory
+ * The {@link ReferenceValueFactory} to be used by this editor
+ */
+ public void setFactory(ReferenceValueFactory factory) {
+ this.widget.setFactory(factory);
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ *
+ */
+ @Override
+ protected void okPressed() {
+ setResult(this.widget.getSelection());
+ super.okPressed();
+ }
+
+ /**
+ * Indicates if the selected values should be unique (According to Object.equals())
+ *
+ * @param unique
+ */
+ public void setUnique(boolean unique) {
+ this.widget.setUnique(unique);
+ }
+
+ /**
+ * Indicates if the selected elements should be ordered
+ *
+ * @param ordered
+ */
+ public void setOrdered(boolean ordered) {
+ this.widget.setOrdered(ordered);
+ }
+
+ /**
+ * Set the selector to use
+ *
+ * @param selector
+ * the selector to use in the dialog
+ */
+ public void setSelector(IElementSelector selector) {
+ this.widget.setSelector(selector);
+ }
+
+ /**
+ * Set the maximum number of values selected.
+ *
+ * @param upperBound
+ */
+ public void setUpperBound(int upperBound) {
+ this.widget.setUpperBound(upperBound);
+ }
+
+ /**
+ * Sets the optional context of the element that is being edited, in which others will be added and removed.
+ *
+ * @param contextElement
+ * the model element that is being edited
+ */
+ public void setContextElement(Object contextElement) {
+ this.widget.setContextElement(contextElement);
+ }
+
+ /**
+ * Queries the optional context of the element that is being edited, in which others will be added and removed.
+ *
+ * @return the model element that is being edited
+ */
+ public Object getContextElement() {
+ return this.widget.getContextElement();
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#close()
+ *
+ * @return
+ */
+ @Override
+ public boolean close() {
+ if (this.widget != null) {
+ this.widget.dispose();
+ }
+ return super.close();
+ }
+
+ /**
+ * Sets the label provider used to display the selected elements
+ *
+ * @param labelProvider
+ */
+ public void setLabelProvider(ILabelProvider labelProvider) {
+ this.widget.setLabelProvider(labelProvider);
+ }
+
+ /**
+ *
+ * @return
+ * the widget
+ * @deprecated since 3.2, the field widget is not necessary a MultipleValueSelectionWidget
+ */
+ protected MultipleValueSelectionWidget getWidget() {// for backward compatibility and mainly to avoid API break
+ if (this.widget instanceof MultipleValueSelectionWidget) {
+ return (MultipleValueSelectionWidget) this.widget;
+ }
+ return null;
+ }
+}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectionDialog.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectionDialog.java
index eee67c3795b..ca21f1e1e18 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectionDialog.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectionDialog.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2017 CEA LIST, Esterel Technologies SAS and others.
+ * Copyright (c) 2010, 2017, 2018 CEA LIST, Esterel Technologies SAS and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,20 +10,13 @@
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Adapted code from MultipleValueSelectorDialog
* Sebastien Gabel (Esterel Technologies SAS) - Bug 526302
- *
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 517190
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.editors;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.util.ValueUtils;
import org.eclipse.papyrus.infra.widgets.widgets.MultipleValueSelectionWidget;
-import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.SelectionDialog;
/**
* Object Chooser. Defines a standard popup for selecting
@@ -36,12 +29,7 @@ import org.eclipse.ui.dialogs.SelectionDialog;
* @see #setContextElement(Object)
*
*/
-public class MultipleValueSelectionDialog extends SelectionDialog {
-
- /**
- * the widget providing the contents of the dialog
- */
- protected MultipleValueSelectionWidget widget;
+public class MultipleValueSelectionDialog extends MultipleValueDialog {
/**
* Constructor.
@@ -121,11 +109,7 @@ public class MultipleValueSelectionDialog extends SelectionDialog {
* The maximum number of values selected.
*/
public MultipleValueSelectionDialog(Shell parentShell, IElementSelector selector, String title, boolean unique, boolean ordered, int upperBound) {
- super(parentShell);
- Assert.isNotNull(selector, "The element selector should be defined"); //$NON-NLS-1$
- setHelpAvailable(false);
- setTitle(title);
- this.widget = createWidget(selector, unique, ordered, upperBound);
+ super(parentShell, selector, title, unique, ordered, upperBound);
}
/**
@@ -139,182 +123,9 @@ public class MultipleValueSelectionDialog extends SelectionDialog {
* @param upperBound
* The maximum number of values selected.
*/
+ @Override
protected MultipleValueSelectionWidget createWidget(IElementSelector selector, boolean unique, boolean ordered, int upperBound) {
return new MultipleValueSelectionWidget(selector, unique, ordered, upperBound);
}
-
- /**
- *
- * @see org.eclipse.ui.dialogs.SelectionDialog#configureShell(org.eclipse.swt.widgets.Shell)
- *
- * @param shell
- */
- @Override
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$
- }
-
- /**
- * @see org.eclipse.ui.dialogs.SelectionDialog#setInitialElementSelections(java.util.List)
- *
- * @param selectedElements
- */
- @Override
- public void setInitialElementSelections(@SuppressWarnings("rawtypes") List selectedElements) {
- super.setInitialElementSelections(selectedElements);
- widget.setInitialSelections(getInitialElementSelections());
- }
-
-
- /**
- * @see org.eclipse.ui.dialogs.SelectionDialog#setInitialSelections(java.lang.Object[])
- *
- * @param selectedElements
- */
- @Override
- public void setInitialSelections(Object[] selectedElements) {
- super.setInitialSelections(selectedElements);
- widget.setInitialSelections(getInitialElementSelections());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void create() {
- super.create();
- createDialogContents();
- getShell().pack();
-
- this.widget.updateControls();
-
- }
-
- /**
- * Create the contents of the dialog
- */
- protected void createDialogContents() {
- Composite parent = getDialogArea();
- this.widget.create(parent);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Composite getDialogArea() {
- return (Composite) super.getDialogArea();
- }
-
-
- /**
- * Sets the {@link ReferenceValueFactory} for this editor. The {@link ReferenceValueFactory} is used to create
- * new instances and edit existing ones.
- *
- * @param factory
- * The {@link ReferenceValueFactory} to be used by this editor
- */
- public void setFactory(ReferenceValueFactory factory) {
- this.widget.setFactory(factory);
- }
-
- /**
- *
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
- *
- */
- @Override
- protected void okPressed() {
- setResult(this.widget.getSelection());
- super.okPressed();
- }
-
- /**
- * Indicates if the selected values should be unique (According to Object.equals())
- *
- * @param unique
- */
- public void setUnique(boolean unique) {
- this.widget.setUnique(unique);
- }
-
- /**
- * Indicates if the selected elements should be ordered
- *
- * @param ordered
- */
- public void setOrdered(boolean ordered) {
- this.widget.setOrdered(ordered);
- }
-
- /**
- * Set the selector to use
- *
- * @param selector
- * the selector to use in the dialog
- */
- public void setSelector(IElementSelector selector) {
- this.widget.setSelector(selector);
- }
-
- /**
- * Set the maximum number of values selected.
- *
- * @param upperBound
- */
- public void setUpperBound(int upperBound) {
- this.widget.setUpperBound(upperBound);
- }
-
- /**
- * Sets the optional context of the element that is being edited, in which others will be added and removed.
- *
- * @param contextElement
- * the model element that is being edited
- */
- public void setContextElement(Object contextElement) {
- this.widget.setContextElement(contextElement);
- }
-
- /**
- * Queries the optional context of the element that is being edited, in which others will be added and removed.
- *
- * @return the model element that is being edited
- */
- public Object getContextElement() {
- return this.widget.getContextElement();
- }
-
- /**
- *
- * @see org.eclipse.jface.dialogs.Dialog#close()
- *
- * @return
- */
- @Override
- public boolean close() {
- if (this.widget != null) {
- this.widget.dispose();
- }
- return super.close();
- }
-
- /**
- * Sets the label provider used to display the selected elements
- *
- * @param labelProvider
- */
- public void setLabelProvider(ILabelProvider labelProvider) {
- this.widget.setLabelProvider(labelProvider);
- }
-
- /**
- *
- * @return
- * the widget
- */
- protected MultipleValueSelectionWidget getWidget() {
- return this.widget;
- }
+
}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java
index d04b218a17b..4d8e6152740 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 2018 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 517190
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.selectors;
@@ -277,7 +278,9 @@ public class ReferenceSelector implements IElementSelector {
*/
public void refresh() {
((SelectionFilteredBrowseStrategy) contentProvider.getBrowseStrategy()).refresh();
- treeViewer.refresh();
+ if (treeViewer != null) {
+ treeViewer.refresh();
+ }
}
/**
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueSelectionWidget.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueSelectionWidget.java
index d042b77bffa..a2240ce49d8 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueSelectionWidget.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueSelectionWidget.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST and others.
+ * Copyright (c) 2014, 2018 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,61 +9,30 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Adapted code from Camille Letavernier (CEA LIST) in MultipleValueSelectorDialog
- *
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 517190
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.widgets;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.papyrus.infra.widgets.Activator;
-import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
-import org.eclipse.papyrus.infra.widgets.editors.IElementSelectionListener;
import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
import org.eclipse.papyrus.infra.widgets.messages.Messages;
-import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
import org.eclipse.papyrus.infra.widgets.util.ValueUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.services.IDisposable;
+import org.eclipse.swt.widgets.Layout;
/**
* @author Vincent Lorenzo
* Class extracted from MultipleValueSelectorDialog
*
*/
-public class MultipleValueSelectionWidget implements ISelectionChangedListener, IDoubleClickListener, IElementSelectionListener, SelectionListener, IDisposable {
-
- /**
- * The object selector
- */
- protected IElementSelector selector;
+public class MultipleValueSelectionWidget extends MultipleValueWidget {
/**
* The SWT Composite in which the selector is drawn
@@ -76,36 +45,11 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
protected Composite buttonsSection;
/**
- * The up/down buttons section
- */
- protected Composite rightButtonsSection;
-
- /**
- * The listViewer for chosen elements
- */
- protected TreeViewer selectedElementsViewer;
-
- /**
- * The list for chosen elements
- */
- protected Tree selectedElements;
-
- /**
* The add action button
*/
protected Button add;
/**
- * The create action button
- */
- protected Button create;
-
- /**
- * The delete action button
- */
- protected Button delete;
-
- /**
* The remove action button
*/
protected Button remove;
@@ -121,62 +65,6 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
protected Button removeAll;
/**
- * the up action button
- */
- protected Button up;
-
- /**
- * the down action button
- */
- protected Button down;
-
- /**
- * The label provider for the listViewer of chosen elements
- */
- protected ILabelProvider labelProvider;
-
- /**
- * The currently chosen elements
- */
- protected final Collection<Object> allElements;
-
- /**
- * Indicates if the values should be unique (according to Object.equals())
- */
- protected boolean unique;
-
- /**
- * Indicates if the list is ordered
- */
- protected boolean ordered;
-
- /**
- * The factory for creating new elements
- */
- protected ReferenceValueFactory factory;
-
- /**
- * The model element being edited (if any), to which elements are to be added or removed.
- */
- protected Object contextElement;
-
- /**
- * The list of newly created objects
- */
- protected Set<Object> newObjects = new HashSet<Object>();
-
-
- /**
- * The maximum number of values selected.
- */
- protected int upperBound;
-
- /**
- * the initial selection
- */
- protected List<?> initialSelection;
-
- /**
* Constructor.
*
* @param selector
@@ -224,14 +112,7 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
* The maximum number of values selected.
*/
public MultipleValueSelectionWidget(IElementSelector selector, boolean unique, boolean ordered, int upperBound) {
- Assert.isNotNull(selector, "The element selector should be defined"); //$NON-NLS-1$
- this.selector = selector;
- allElements = unique ? new LinkedHashSet<Object>() : new LinkedList<Object>();
- this.unique = unique;
- this.ordered = ordered;
- this.upperBound = upperBound;
- selector.addElementSelectionListener(this);
- init();
+ super(selector, unique, ordered, upperBound);
}
/**
@@ -242,73 +123,30 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
}
/**
- * Create the contents of the dialog
- *
- * @return
- * the the composite which encapsulate all the sub composite
+ * @see org.eclipse.papyrus.infra.widgets.widgets.MultipleValueWidget#createSections(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
*/
- public final Composite create(Composite composite) {
- Composite parent = createContents(composite);
- updateControls();
- return parent;
- }
+ @Override
+ protected void createSections(final Composite parent) {
- /**
- * Create the contents of the dialog
- *
- * @return
- * the the composite which encapsulate all the sub composite
- */
- protected Composite createContents(Composite parent) {
- Object parentLayout = parent.getLayout();
- GridLayout layout = null;
+ Layout parentLayout = parent.getLayout();
if (parentLayout instanceof GridLayout) {
- layout = (GridLayout) parentLayout;
- } else {
- parent = new Composite(parent, SWT.NONE);
- layout = new GridLayout();
- parent.setLayout(layout);
- }
-
- layout.numColumns = 2;
- layout.makeColumnsEqualWidth = true;
+ GridLayout layout = (GridLayout) parentLayout;
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = true;
- Composite selectorPane = new Composite(parent, SWT.NONE);
- selectorPane.setLayout(new GridLayout(2, false));
- selectorPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ Composite selectorPane = new Composite(parent, SWT.NONE);
+ selectorPane.setLayout(new GridLayout(2, false));
+ selectorPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- Composite selectedPane = new Composite(parent, SWT.NONE);
- selectedPane.setLayout(new GridLayout(2, false));
- selectedPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- createSelectorSection(selectorPane);
- createControlsSection(selectorPane);
- createListSection(selectedPane);
- createRightButtonsSection(selectedPane);
-
- allElements.clear();
- allElements.addAll(getInitialElementSelections());
- return parent;
- }
-
-
-
-
- public void setInitialSelections(List<?> selectedElements) {
- this.initialSelection = selectedElements;
- allElements.clear();
- allElements.addAll(getInitialElementSelections());
- }
-
- /**
- * @return
- */
- private Collection<? extends Object> getInitialElementSelections() {
- if (this.initialSelection == null) {
- return Collections.emptyList();
+ createSelectorSection(selectorPane);
+ createControlsSection(selectorPane);
}
- return this.initialSelection;
+
+ super.createSections(parent);
}
+
/**
* Creates the selector section
@@ -360,84 +198,6 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
removeAll.setToolTipText(Messages.MultipleValueSelectorDialog_RemoveAllElements);
}
- /**
- * Creates the list displaying the currently selected elements
- *
- * @param parent
- * The composite in which the section is created
- */
- private void createListSection(Composite parent) {
-
- selectedElements = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
- // selectedElements.addSelectionListener(this);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- selectedElements.setLayoutData(data);
- selectedElementsViewer = new TreeViewer(selectedElements);
-
- selectedElementsViewer.addSelectionChangedListener(this);
- selectedElementsViewer.addDoubleClickListener(this);
-
- selectedElementsViewer.setContentProvider(createListSectionContentProvider());
-
- if (labelProvider != null) {
- selectedElementsViewer.setLabelProvider(labelProvider);
- }
-
- selectedElementsViewer.setInput(allElements);
- selector.setSelectedElements(allElements.toArray());
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.wizard.pages.MultipleValueSelectionWizard#createListSectionContentProvider()
- *
- * @return
- * the content provider to use in the list section (right part)
- */
- protected IContentProvider createListSectionContentProvider() {
- return CollectionContentProvider.instance;
- }
-
- /**
- * Creates the up/down controls section
- *
- * @param parent
- * The composite in which the section is created
- */
- protected void createRightButtonsSection(Composite parent) {
- rightButtonsSection = new Composite(parent, SWT.NONE);
- rightButtonsSection.setLayout(new GridLayout(1, true));
-
- up = new Button(rightButtonsSection, SWT.PUSH);
- up.setImage(Activator.getDefault().getImage("/icons/Up_12x12.gif")); //$NON-NLS-1$
- up.addSelectionListener(this);
- up.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsUp);
-
- down = new Button(rightButtonsSection, SWT.PUSH);
- down.setImage(Activator.getDefault().getImage("/icons/Down_12x12.gif")); //$NON-NLS-1$
- down.addSelectionListener(this);
- down.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsDown);
-
- create = new Button(rightButtonsSection, SWT.PUSH);
- create.setImage(Activator.getDefault().getImage("/icons/Add_12x12.gif")); //$NON-NLS-1$
- create.addSelectionListener(this);
- create.setToolTipText(Messages.MultipleValueSelectorDialog_CreateNewElement);
-
- delete = new Button(rightButtonsSection, SWT.PUSH);
- delete.setImage(Activator.getDefault().getImage("/icons/Delete_12x12.gif")); //$NON-NLS-1$
- delete.addSelectionListener(this);
- delete.setToolTipText(Messages.MultipleValueSelectorDialog_DeleteNewElement);
- delete.setEnabled(false);
- }
-
- /**
- * Sets the label provider used to display the selected elements
- *
- * @param labelProvider
- */
- public void setLabelProvider(ILabelProvider labelProvider) {
- this.labelProvider = labelProvider;
- }
/**
* {@inheritDoc} Handles the events on one of the control buttons
@@ -457,30 +217,11 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
addAllAction();
} else if (e.widget == removeAll) {
removeAllAction();
- } else if (e.widget == up) {
- upAction();
- } else if (e.widget == down) {
- downAction();
- } else if (e.widget == create) {
- createAction();
- } else if (e.widget == delete) {
- deleteAction();
}
- updateControls();
+ super.widgetSelected(e);
}
- /**
- * Sets the {@link ReferenceValueFactory} for this editor. The {@link ReferenceValueFactory} is used to create
- * new instances and edit existing ones.
- *
- * @param factory
- * The {@link ReferenceValueFactory} to be used by this editor
- */
- public void setFactory(ReferenceValueFactory factory) {
- this.factory = factory;
- updateControls();
- }
/**
* Handles the "Add" action
@@ -491,136 +232,6 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
}
/**
- * Handles the "Up" action
- */
- protected void upAction() {
- IStructuredSelection selection = (IStructuredSelection) selectedElementsViewer.getSelection();
-
- // We need a list to move objects. LinkedHashSet can't do that
- java.util.List<Object> list = new LinkedList<Object>(allElements);
- for (Object o : selection.toArray()) {
- int oldIndex = list.indexOf(o);
- if (oldIndex > 0) {
- move(list, oldIndex, oldIndex - 1);
- }
- }
-
- allElements.clear();
- allElements.addAll(list);
-
- IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray());
- selectedElementsViewer.setSelection(selectionCopy);
- selectedElementsViewer.refresh();
- }
-
- /**
- * Handles the "Down" action
- */
- protected void downAction() {
- IStructuredSelection selection = (IStructuredSelection) selectedElementsViewer.getSelection();
-
- // We need a list to move objects. LinkedHashSet can't do that
- java.util.List<Object> list = new LinkedList<Object>(allElements);
-
- int maxIndex = list.size() - 1;
-
- Object[] selectionArray = selection.toArray();
- for (int i = selectionArray.length - 1; i >= 0; i--) {
- Object o = selectionArray[i];
- int oldIndex = list.indexOf(o);
- if (oldIndex < maxIndex) {
- move(list, oldIndex, oldIndex + 1);
- }
- }
-
- allElements.clear();
- allElements.addAll(list);
-
- IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray());
- selectedElementsViewer.setSelection(selectionCopy);
- selectedElementsViewer.refresh();
- }
-
- /**
- * Handles the "Create" action
- */
- protected void createAction() {
- if (factory == null) {
- return;
- }
-
- Object newObject;
-
- try {
- newObject = factory.createObject(this.create, this.contextElement);
- } catch (OperationCanceledException e) {
- // The user cancelled and we rolled back pending model changes
- newObject = null;
- }
-
- if (newObject == null) {
- return;
- }
-
- newObjects.add(newObject);
- selector.newObjectCreated(newObject);
-
- Object[] createdObjects = new Object[] { newObject };
- addElements(createdObjects);
-
- selector.setSelectedElements(allElements.toArray());
- }
-
-
- /**
- * Moves an element from oldIndex to newIndex
- *
- * @param list
- * The list in which to move the object
- * @param oldIndex
- * @param newIndex
- */
- private void move(java.util.List<Object> list, int oldIndex, int newIndex) {
- int size = list.size();
-
- if (oldIndex < 0 || oldIndex >= size) {
- throw new IndexOutOfBoundsException("oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (newIndex < 0 || newIndex >= size) {
- throw new IndexOutOfBoundsException("newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$
- }
- Object element = list.remove(oldIndex);
- list.add(newIndex, element);
- }
-
- /**
- * Handles the "Remove" action
- */
- protected void removeAction() {
- if (canRemove()) {
- IStructuredSelection selection = (IStructuredSelection) selectedElementsViewer.getSelection();
- if (selection.isEmpty()) {
- return;
- }
-
- for (Object element : selection.toArray()) {
- allElements.remove(element);
- }
-
- selector.setSelectedElements(allElements.toArray());
- selectedElementsViewer.setSelection(null);
- selectedElementsViewer.refresh();
- }
- }
-
- /**
- * Handles the "Delete" action
- */
- protected void deleteAction() {
- // nothing to do here
- }
-
- /**
* Handles the "Remove all" action
*/
protected void removeAllAction() {
@@ -638,191 +249,17 @@ public class MultipleValueSelectionWidget implements ISelectionChangedListener,
addElements(elements);
}
- /**
- * Adds the specified elements to the currently selected elements (For
- * "Add" and "Add all" actions)
- *
- * @param elements
- * The elements to be added
- */
- @Override
- public void addElements(Object[] elements) {
- if (elements != null) {
- allElements.addAll(Arrays.asList(elements));
- selectedElementsViewer.refresh();
- }
- }
-
- public List<Object> getSelection() {
- if (factory != null) {
- java.util.List<Object> objectsToValidate = new LinkedList<Object>();
- for (Object object : newObjects) {
- if (allElements.contains(object)) {
- objectsToValidate.add(object);
- }
- }
- factory.validateObjects(objectsToValidate);
- selector.clearTemporaryElements();
- }
- return new LinkedList<Object>(allElements);
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // Nothing (see #doubleClick())
- }
-
- /**
- * Indicates if the selected values should be unique (According to Object.equals())
- *
- * @param unique
- */
- public void setUnique(boolean unique) {
- this.unique = unique;
- updateControls();
- }
-
- /**
- * Indicates if the selected elements should be ordered
- *
- * @param ordered
- */
- public void setOrdered(boolean ordered) {
- this.ordered = ordered;
- updateControls();
- }
-
- public void updateControls() {
- updateControl(up, ordered && canMove(true));
- updateControl(down, ordered && canMove(false));
- updateControl(create, this.factory != null && this.factory.canCreateObject());
- updateControl(add, canAdd());
- updateControl(delete, canDelete());
- }
-
- /**
- * @return
- */
- protected boolean canDelete() {
- return true;
- }
-
- /**
- *
- * @param up
- * if <code>true</code> we try to move the element to the up, if <code>false</code> we try to move the element to the down
- * @return
- * <code>true</code> if the element can be moved
- */
- protected boolean canMove(boolean up) {
- return ordered;
- }
-
- /**
- *
- * @return
- * <code>true</code> if we can add elements
- */
- protected boolean canAdd() {
- /* Disable the bouton 'add' if the upperBound is reached */
- boolean canAdd = true;
- if (this.upperBound != ValueUtils.MANY) {
- if (allElements.size() >= this.upperBound) {
- canAdd = false;
- }
- }
- return canAdd;
- }
-
- protected void updateControl(Control control, boolean enabled) {
- if (control != null) {
- control.setEnabled(enabled);
- }
- }
-
- public void setSelector(IElementSelector selector) {
- if(null != this.selector) {
- this.selector.removeElementSelectionListener(this);
- }
- this.selector = selector;
- this.selector.addElementSelectionListener(this);
- }
-
- /**
- * Set the maximum number of values selected.
- *
- * @param upperBound
- */
- public void setUpperBound(int upperBound) {
- this.upperBound = upperBound;
- }
- /**
- * Sets the optional context of the element that is being edited, in which others will be added and removed.
- *
- * @param contextElement
- * the model element that is being edited
- */
- public void setContextElement(Object contextElement) {
- this.contextElement = contextElement;
- }
-
- /**
- * Queries the optional context of the element that is being edited, in which others will be added and removed.
- *
- * @return the model element that is being edited
- */
- public Object getContextElement() {
- return contextElement;
- }
/**
* {@inheritDoc}
- *
- * Handles double click event on the right-panel tree viewer {@link #selectedElementsViewer}
- *
- */
- @Override
- public void doubleClick(DoubleClickEvent event) {
- removeAction();
- }
-
- /**
*
- * @return
- * <code>true</code> if the selected elements can be removed (moved from right to left)
- */
- protected boolean canRemove() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * Handles selection change event on the right-panel tree viewer {@link #selectedElementsViewer}
- */
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- updateControls();
- }
-
- /**
- * @see org.eclipse.ui.services.IDisposable#dispose()
- *
+ * @see org.eclipse.papyrus.infra.widgets.widgets.MultipleValueWidget#updateControls()
*/
@Override
- public void dispose() {
- if(null != this.selector) {
- this.selector.removeElementSelectionListener(this);
- }
+ public void updateControls() {
+ updateControl(add, canAdd());
+ super.updateControls();
}
- /**
- *
- * @return
- * the initial selection
- */
- protected List<?> getInitialSelection() {
- return this.initialSelection;
- }
} \ No newline at end of file
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueWidget.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueWidget.java
new file mode 100644
index 00000000000..fc9faa3e308
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/widgets/MultipleValueWidget.java
@@ -0,0 +1,736 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.widgets.widgets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.infra.widgets.editors.IElementSelectionListener;
+import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider;
+import org.eclipse.papyrus.infra.widgets.util.ValueUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.services.IDisposable;
+
+/**
+ * The widget for the simple multi value (without selection widget).
+ *
+ * @since 3.3
+ */
+public class MultipleValueWidget implements ISelectionChangedListener, IDoubleClickListener, IElementSelectionListener, SelectionListener, IDisposable {
+
+ /**
+ * The object selector.
+ */
+ protected IElementSelector selector;
+
+ /**
+ * The up/down buttons section.
+ */
+ protected Composite rightButtonsSection;
+
+ /**
+ * The listViewer for chosen elements.
+ */
+ protected TreeViewer selectedElementsViewer;
+
+ /**
+ * The list for chosen elements.
+ */
+ protected Tree selectedElements;
+
+ /**
+ * The create action button.
+ */
+ protected Button create;
+
+ /**
+ * The delete action button.
+ */
+ protected Button delete;
+
+ /**
+ * the up action button.
+ */
+ protected Button up;
+
+ /**
+ * the down action button.
+ */
+ protected Button down;
+
+ /**
+ * The label provider for the listViewer of chosen elements.
+ */
+ protected ILabelProvider labelProvider;
+
+ /**
+ * The currently chosen elements.
+ */
+ protected final Collection<Object> allElements;
+
+ /**
+ * Indicates if the values should be unique (according to Object.equals()).
+ */
+ protected boolean unique;
+
+ /**
+ * Indicates if the list is ordered.
+ */
+ protected boolean ordered;
+
+ /**
+ * The factory for creating new elements.
+ */
+ protected ReferenceValueFactory factory;
+
+ /**
+ * The model element being edited (if any), to which elements are to be added or removed.
+ */
+ protected Object contextElement;
+
+ /**
+ * The list of newly created objects.
+ */
+ protected Set<Object> newObjects = new HashSet<Object>();
+
+
+ /**
+ * The maximum number of values selected.
+ */
+ protected int upperBound;
+
+ /**
+ * the initial selection.
+ */
+ protected List<?> initialSelection;
+
+ /**
+ * Constructor.
+ *
+ * @param selector
+ * The element selector used by this dialog
+ */
+ public MultipleValueWidget(IElementSelector selector) {
+ this(selector, false, false);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param selector
+ * The element selector used by this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ */
+ public MultipleValueWidget(IElementSelector selector, boolean unique) {
+ this(selector, unique, false);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param selector
+ * The element selector used by this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ */
+ public MultipleValueWidget(IElementSelector selector, boolean unique, boolean ordered) {
+ this(selector, unique, false, ValueUtils.MANY);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param selector
+ * The element selector used by this dialog
+ * @param unique
+ * True if the values returned by this dialog should be unique
+ * @param upperBound
+ * The maximum number of values selected.
+ */
+ public MultipleValueWidget(IElementSelector selector, boolean unique, boolean ordered, int upperBound) {
+ Assert.isNotNull(selector, "The element selector should be defined"); //$NON-NLS-1$
+ this.selector = selector;
+ allElements = unique ? new LinkedHashSet<Object>() : new LinkedList<Object>();
+ this.unique = unique;
+ this.ordered = ordered;
+ this.upperBound = upperBound;
+ selector.addElementSelectionListener(this);
+ init();
+ }
+
+ /**
+ * initialize the widget if required
+ */
+ protected void init() {
+ // nothing to do
+ }
+
+ /**
+ * Create the contents of the dialog
+ *
+ * @return
+ * the the composite which encapsulate all the sub composite
+ */
+ public final Composite create(Composite composite) {
+ Composite parent = createContents(composite);
+ updateControls();
+ return parent;
+ }
+
+ /**
+ * Create the contents of the dialog
+ *
+ * @return
+ * the the composite which encapsulate all the sub composite
+ */
+ protected Composite createContents(Composite parent) {
+ Object parentLayout = parent.getLayout();
+ GridLayout layout = null;
+ if (parentLayout instanceof GridLayout) {
+ layout = (GridLayout) parentLayout;
+ } else {
+ parent = new Composite(parent, SWT.NONE);
+ layout = new GridLayout();
+ parent.setLayout(layout);
+ }
+
+ createSections(parent);
+
+ allElements.clear();
+ allElements.addAll(getInitialElementSelections());
+ return parent;
+ }
+
+ /**
+ * This allows to create the sections of the dialog.
+ *
+ * @param parent
+ * The parent composite.
+ */
+ protected void createSections(final Composite parent) {
+ final Composite selectedPane = new Composite(parent, SWT.NONE);
+ selectedPane.setLayout(new GridLayout(2, false));
+ selectedPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ createListSection(selectedPane);
+ createRightButtonsSection(selectedPane);
+ }
+
+
+ public void setInitialSelections(List<?> selectedElements) {
+ this.initialSelection = selectedElements;
+ allElements.clear();
+ allElements.addAll(getInitialElementSelections());
+ }
+
+ /**
+ * @return
+ */
+ private Collection<? extends Object> getInitialElementSelections() {
+ if (this.initialSelection == null) {
+ return Collections.emptyList();
+ }
+ return this.initialSelection;
+ }
+
+ /**
+ * Creates the list displaying the currently selected elements
+ *
+ * @param parent
+ * The composite in which the section is created
+ */
+ protected void createListSection(Composite parent) {
+
+ selectedElements = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ // selectedElements.addSelectionListener(this);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ selectedElements.setLayoutData(data);
+ selectedElementsViewer = new TreeViewer(selectedElements);
+
+ selectedElementsViewer.addSelectionChangedListener(this);
+ selectedElementsViewer.addDoubleClickListener(this);
+
+ selectedElementsViewer.setContentProvider(createListSectionContentProvider());
+
+ if (labelProvider != null) {
+ selectedElementsViewer.setLabelProvider(labelProvider);
+ }
+
+ selectedElementsViewer.setInput(allElements);
+ selector.setSelectedElements(allElements.toArray());
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.wizard.pages.MultipleValueSelectionWizard#createListSectionContentProvider()
+ *
+ * @return
+ * the content provider to use in the list section (right part)
+ */
+ protected IContentProvider createListSectionContentProvider() {
+ return CollectionContentProvider.instance;
+ }
+
+ /**
+ * Creates the up/down controls section
+ *
+ * @param parent
+ * The composite in which the section is created
+ */
+ protected void createRightButtonsSection(Composite parent) {
+ rightButtonsSection = new Composite(parent, SWT.NONE);
+ rightButtonsSection.setLayout(new GridLayout(1, true));
+
+ up = new Button(rightButtonsSection, SWT.PUSH);
+ up.setImage(Activator.getDefault().getImage("/icons/Up_12x12.gif")); //$NON-NLS-1$
+ up.addSelectionListener(this);
+ up.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsUp);
+
+ down = new Button(rightButtonsSection, SWT.PUSH);
+ down.setImage(Activator.getDefault().getImage("/icons/Down_12x12.gif")); //$NON-NLS-1$
+ down.addSelectionListener(this);
+ down.setToolTipText(Messages.MultipleValueEditor_MoveSelectedElementsDown);
+
+ create = new Button(rightButtonsSection, SWT.PUSH);
+ create.setImage(Activator.getDefault().getImage("/icons/Add_12x12.gif")); //$NON-NLS-1$
+ create.addSelectionListener(this);
+ create.setToolTipText(Messages.MultipleValueSelectorDialog_CreateNewElement);
+
+ delete = new Button(rightButtonsSection, SWT.PUSH);
+ delete.setImage(Activator.getDefault().getImage("/icons/Delete_12x12.gif")); //$NON-NLS-1$
+ delete.addSelectionListener(this);
+ delete.setToolTipText(Messages.MultipleValueSelectorDialog_DeleteNewElement);
+ delete.setEnabled(false);
+ }
+
+ /**
+ * Sets the label provider used to display the selected elements
+ *
+ * @param labelProvider
+ */
+ public void setLabelProvider(ILabelProvider labelProvider) {
+ this.labelProvider = labelProvider;
+ }
+
+ /**
+ * {@inheritDoc} Handles the events on one of the control buttons
+ *
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ *
+ * @param e
+ * The event that occurred
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (e.widget == up) {
+ upAction();
+ } else if (e.widget == down) {
+ downAction();
+ } else if (e.widget == create) {
+ createAction();
+ } else if (e.widget == delete) {
+ deleteAction();
+ }
+
+ updateControls();
+ }
+
+ /**
+ * Sets the {@link ReferenceValueFactory} for this editor. The {@link ReferenceValueFactory} is used to create
+ * new instances and edit existing ones.
+ *
+ * @param factory
+ * The {@link ReferenceValueFactory} to be used by this editor
+ */
+ public void setFactory(ReferenceValueFactory factory) {
+ this.factory = factory;
+ updateControls();
+ }
+
+ /**
+ * Handles the "Up" action
+ */
+ protected void upAction() {
+ IStructuredSelection selection = (IStructuredSelection) selectedElementsViewer.getSelection();
+
+ // We need a list to move objects. LinkedHashSet can't do that
+ java.util.List<Object> list = new LinkedList<Object>(allElements);
+ for (Object o : selection.toArray()) {
+ int oldIndex = list.indexOf(o);
+ if (oldIndex > 0) {
+ move(list, oldIndex, oldIndex - 1);
+ }
+ }
+
+ allElements.clear();
+ allElements.addAll(list);
+
+ IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray());
+ selectedElementsViewer.setSelection(selectionCopy);
+ selectedElementsViewer.refresh();
+ }
+
+ /**
+ * Handles the "Down" action
+ */
+ protected void downAction() {
+ IStructuredSelection selection = (IStructuredSelection) selectedElementsViewer.getSelection();
+
+ // We need a list to move objects. LinkedHashSet can't do that
+ java.util.List<Object> list = new LinkedList<Object>(allElements);
+
+ int maxIndex = list.size() - 1;
+
+ Object[] selectionArray = selection.toArray();
+ for (int i = selectionArray.length - 1; i >= 0; i--) {
+ Object o = selectionArray[i];
+ int oldIndex = list.indexOf(o);
+ if (oldIndex < maxIndex) {
+ move(list, oldIndex, oldIndex + 1);
+ }
+ }
+
+ allElements.clear();
+ allElements.addAll(list);
+
+ IStructuredSelection selectionCopy = new StructuredSelection(selection.toArray());
+ selectedElementsViewer.setSelection(selectionCopy);
+ selectedElementsViewer.refresh();
+ }
+
+ /**
+ * Handles the "Create" action
+ */
+ protected void createAction() {
+ if (factory == null) {
+ return;
+ }
+
+ Object newObject;
+
+ try {
+ newObject = factory.createObject(this.create, this.contextElement);
+ } catch (OperationCanceledException e) {
+ // The user cancelled and we rolled back pending model changes
+ newObject = null;
+ }
+
+ if (newObject == null) {
+ return;
+ }
+
+ newObjects.add(newObject);
+ selector.newObjectCreated(newObject);
+
+ Object[] createdObjects = new Object[] { newObject };
+ addElements(createdObjects);
+
+ selector.setSelectedElements(allElements.toArray());
+ }
+
+
+ /**
+ * Moves an element from oldIndex to newIndex
+ *
+ * @param list
+ * The list in which to move the object
+ * @param oldIndex
+ * @param newIndex
+ */
+ private void move(java.util.List<Object> list, int oldIndex, int newIndex) {
+ int size = list.size();
+
+ if (oldIndex < 0 || oldIndex >= size) {
+ throw new IndexOutOfBoundsException("oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (newIndex < 0 || newIndex >= size) {
+ throw new IndexOutOfBoundsException("newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ Object element = list.remove(oldIndex);
+ list.add(newIndex, element);
+ }
+
+ /**
+ * Handles the "Remove" action
+ */
+ protected void removeAction() {
+ if (canRemove()) {
+ IStructuredSelection selection = (IStructuredSelection) selectedElementsViewer.getSelection();
+ if (selection.isEmpty()) {
+ return;
+ }
+
+ for (Object element : selection.toArray()) {
+ allElements.remove(element);
+ }
+
+ selector.setSelectedElements(allElements.toArray());
+ selectedElementsViewer.setSelection(null);
+ selectedElementsViewer.refresh();
+ }
+ }
+
+ /**
+ * Handles the "Delete" action
+ */
+ protected void deleteAction() {
+ // nothing to do here
+ ISelection selection = selectedElementsViewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ final Iterator<?> selectedObjects = ((IStructuredSelection) selection).iterator();
+ List<Object> removedObjects = new ArrayList<Object>();
+ while (selectedObjects.hasNext()) {
+ Object selectedObject = selectedObjects.next();
+ if (newObjects.contains(selectedObject)) {
+ newObjects.remove(selectedObject);
+ }
+ removedObjects.add(selectedObject);
+ }
+
+ removeElements(removedObjects.toArray());
+ selector.setSelectedElements(allElements.toArray());
+ }
+ }
+
+ /**
+ * Adds the specified elements to the currently selected elements (For
+ * "Add" and "Add all" actions)
+ *
+ * @param elements
+ * The elements to be added
+ */
+ @Override
+ public void addElements(final Object[] elements) {
+ if (null != elements && elements.length > 0) {
+ allElements.addAll(Arrays.asList(elements));
+ selectedElementsViewer.refresh();
+ }
+ }
+
+ /**
+ * Adds the specified elements to the currently selected elements (For
+ * "Remove" and "Remove all" actions)
+ *
+ * @param elements
+ * The elements to be added
+ */
+ public void removeElements(final Object[] elements) {
+ if (null != elements && elements.length > 0) {
+ allElements.removeAll(Arrays.asList(elements));
+ selectedElementsViewer.refresh();
+ }
+ }
+
+ public List<Object> getSelection() {
+ if (factory != null) {
+ java.util.List<Object> objectsToValidate = new LinkedList<Object>();
+ for (Object object : newObjects) {
+ if (allElements.contains(object)) {
+ objectsToValidate.add(object);
+ }
+ }
+ factory.validateObjects(objectsToValidate);
+ selector.clearTemporaryElements();
+ }
+ return new LinkedList<Object>(allElements);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing (see #doubleClick())
+ }
+
+ /**
+ * Indicates if the selected values should be unique (According to Object.equals())
+ *
+ * @param unique
+ */
+ public void setUnique(boolean unique) {
+ this.unique = unique;
+ updateControls();
+ }
+
+ /**
+ * Indicates if the selected elements should be ordered
+ *
+ * @param ordered
+ */
+ public void setOrdered(boolean ordered) {
+ this.ordered = ordered;
+ updateControls();
+ }
+
+ public void updateControls() {
+ updateControl(up, ordered && canMove(true));
+ updateControl(down, ordered && canMove(false));
+ updateControl(create, this.factory != null && this.factory.canCreateObject());
+ updateControl(delete, canDelete());
+ }
+
+ /**
+ * @return
+ */
+ protected boolean canDelete() {
+ return true;
+ }
+
+ /**
+ *
+ * @param up
+ * if <code>true</code> we try to move the element to the up, if <code>false</code> we try to move the element to the down
+ * @return
+ * <code>true</code> if the element can be moved
+ */
+ protected boolean canMove(boolean up) {
+ return null != selectedElementsViewer && null != selectedElementsViewer.getSelection() && !selectedElementsViewer.getSelection().isEmpty();
+ }
+
+ /**
+ *
+ * @return
+ * <code>true</code> if we can add elements
+ */
+ protected boolean canAdd() {
+ /* Disable the bouton 'add' if the upperBound is reached */
+ boolean canAdd = true;
+ if (this.upperBound != ValueUtils.MANY) {
+ if (allElements.size() >= this.upperBound) {
+ canAdd = false;
+ }
+ }
+ return canAdd;
+ }
+
+ protected void updateControl(Control control, boolean enabled) {
+ if (control != null) {
+ control.setEnabled(enabled);
+ }
+ }
+
+ public void setSelector(IElementSelector selector) {
+ this.selector = selector;
+ }
+
+ /**
+ * Set the maximum number of values selected.
+ *
+ * @param upperBound
+ */
+ public void setUpperBound(int upperBound) {
+ this.upperBound = upperBound;
+ }
+
+ /**
+ * Sets the optional context of the element that is being edited, in which others will be added and removed.
+ *
+ * @param contextElement
+ * the model element that is being edited
+ */
+ public void setContextElement(Object contextElement) {
+ this.contextElement = contextElement;
+ }
+
+ /**
+ * Queries the optional context of the element that is being edited, in which others will be added and removed.
+ *
+ * @return the model element that is being edited
+ */
+ public Object getContextElement() {
+ return contextElement;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Handles double click event on the right-panel tree viewer {@link #selectedElementsViewer}
+ *
+ */
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ removeAction();
+ }
+
+ /**
+ *
+ * @return
+ * <code>true</code> if the selected elements can be removed (moved from right to left)
+ */
+ protected boolean canRemove() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Handles selection change event on the right-panel tree viewer {@link #selectedElementsViewer}
+ */
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateControls();
+ }
+
+ /**
+ * @see org.eclipse.ui.services.IDisposable#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ selector.removeElementSelectionListener(this);
+ }
+
+ /**
+ *
+ * @return
+ * the initial selection
+ */
+ protected List<?> getInitialSelection() {
+ return this.initialSelection;
+ }
+}

Back to the top