Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AbstractNaryEditingDialog.java139
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AssignableValuesContentProvider.java82
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/EditingUtils.java84
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/FeatureValuesInput.java33
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/ModelCellsEditingSupport.java130
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryAttributeEditingDialog.java373
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryReferenceEditingDialog.java489
7 files changed, 1330 insertions, 0 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AbstractNaryEditingDialog.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AbstractNaryEditingDialog.java
new file mode 100644
index 00000000000..59d3d611876
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AbstractNaryEditingDialog.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditHandler;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Shell;
+
+public abstract class AbstractNaryEditingDialog<T extends Object> extends Dialog {
+
+ public static final int AVAILABLE_VALUES_TREE_WIDTH = 200;
+ public static final int AVAILABLE_VALUES_TREE_HEIGHT = 250;
+
+ private final List<T> values;
+ private final IModelCellEditHandler editHandler;
+ private final EObject eObject;
+ private final EStructuralFeature feature;
+
+ protected AbstractNaryEditingDialog(final Shell shell, final List<T> values,
+ final IModelCellEditHandler editHandler, final EObject eObject,
+ final EStructuralFeature feature) {
+ super(shell);
+ this.values = new ArrayList<T>(values);
+ this.feature = feature;
+ this.editHandler = editHandler;
+ this.eObject = eObject;
+ }
+
+ public class AssignedValuesContentProvider implements IStructuredContentProvider {
+ public Object[] getElements(final Object inputElement) {
+ if (inputElement instanceof FeatureValuesInput) {
+ FeatureValuesInput valuesInput = (FeatureValuesInput) inputElement;
+ EObject source = valuesInput.getSource();
+ List<?> list = (List<?>) source.eGet(valuesInput.getFeature());
+ if (list == null) {
+ return new Object[0];
+ }
+ return list.toArray();
+ } else if (inputElement instanceof List<?>) {
+ return ((List<?>) inputElement).toArray();
+ }
+ throw new IllegalArgumentException(FeatureValuesInput.class.getSimpleName()
+ + " expected"); //$NON-NLS-1$
+ }
+
+ public void dispose() {
+ //
+ }
+
+ public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
+ //
+ }
+ }
+
+ public List<T> getValue() {
+ return this.values;
+ }
+
+ @SuppressWarnings("unchecked") // type erasure on generic
+ public void upButtonClicked() {
+ final IStructuredSelection selection = (IStructuredSelection) getSelection();
+
+ int minIndex = 0;
+ for (Object element : selection.toList()) {
+ final int index = this.values.indexOf(element);
+ T object = this.values.set(Math.max(index - 1, minIndex++), (T) element);
+ this.values.set(index, object);
+ }
+ refresh();
+ }
+
+ @SuppressWarnings("unchecked") // type erasure on generic
+ public void downButtonClicked() {
+ final IStructuredSelection selection = (StructuredSelection) getSelection();
+
+ List<?> selectionList = selection.toList();
+ boolean canMove = !selectionList.contains(this.values.get(this.values.size() - 1));
+ for (int i = this.values.size() - 2; i >= 0; i--) {
+ final Object selectedObject = this.values.get(i);
+ if (selectionList.contains(selectedObject)) {
+ if (canMove) {
+ T object = this.values.set(i + 1, (T) selectedObject);
+ this.values.set(i, object);
+ }
+ } else {
+ canMove = true;
+ }
+
+ }
+
+ refresh();
+ }
+
+ public abstract ISelection getSelection();
+
+ public abstract void refresh();
+
+ @Override
+ protected void okPressed() {
+ super.okPressed();
+ this.editHandler.commit();
+ }
+
+ protected List<T> getValues() {
+ return this.values;
+ }
+
+ protected IModelCellEditHandler getEditHandler() {
+ return this.editHandler;
+ }
+
+ protected EObject geteObject() {
+ return this.eObject;
+ }
+
+ protected EStructuralFeature getFeature() {
+ return this.feature;
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AssignableValuesContentProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AssignableValuesContentProvider.java
new file mode 100644
index 00000000000..4800e135885
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/AssignableValuesContentProvider.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class AssignableValuesContentProvider implements ITreeContentProvider {
+ public Object[] getElements(final Object inputElement) {
+ if (inputElement instanceof FeatureValuesInput) {
+ FeatureValuesInput assignableValuesInput = (FeatureValuesInput) inputElement;
+ EStructuralFeature feature = assignableValuesInput.getFeature();
+ EClassifier eType = feature.getEType();
+ EObject source = assignableValuesInput.getSource();
+ List<?> featureValues = (List<?>) source.eGet(feature);
+
+ // build a list of EObjects assignable to the EReference
+ List<EObject> list = new ArrayList<EObject>();
+ Resource eResource = source.eResource();
+ if (eResource == null) {
+ return new Object[0];
+ }
+ ResourceSet resourceSet = eResource.getResourceSet();
+ TreeIterator<Notifier> allContents = resourceSet.getAllContents();
+ while (allContents.hasNext()) {
+ Notifier notifier = allContents.next();
+ if (notifier instanceof EObject) {
+ EObject eObject = (EObject) notifier;
+ if (eType.isInstance(eObject)
+ && (!feature.isUnique() || !(featureValues != null && featureValues
+ .contains(eObject)))) {
+ list.add(eObject);
+ }
+ }
+ }
+ return list.toArray();
+ } else if (inputElement instanceof List<?>) {
+ return ((List<?>) inputElement).toArray();
+ }
+ throw new IllegalArgumentException(FeatureValuesInput.class.getSimpleName() + " expected"); //$NON-NLS-1$
+ }
+
+ public void dispose() {
+ //
+ }
+
+ public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
+ //
+ }
+
+ public Object[] getChildren(final Object parentElement) {
+ return null;
+ }
+
+ public Object getParent(final Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(final Object element) {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/EditingUtils.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/EditingUtils.java
new file mode 100644
index 00000000000..c8080828af1
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/EditingUtils.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
+
+public final class EditingUtils {
+ private EditingUtils() {
+ //
+ }
+
+ public static void moveElementsUp(final EObject eObject, final EStructuralFeature feature,
+ final Collection<Object> elements, final ICommandFactory commandFactory,
+ final EditingDomain editingDomain) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+
+ List<?> list = (List<?>) eObject.eGet(feature);
+
+ int minIndex = 0;
+ for (Object element : elements) {
+ final int index = list.indexOf(element);
+
+ Command moveCommand = commandFactory.createMoveCommand(editingDomain, eObject, feature,
+ element, Math.max(index - 1, minIndex++));
+ compoundCommand.append(moveCommand);
+ }
+ editingDomain.getCommandStack().execute(compoundCommand);
+ // int[] selectionIndices;
+ // Arrays.sort(selectionIndices);
+ // CompoundCommand compoundCommand = new CompoundCommand();
+ // int minIndex = 0;
+ // for(int index : selectionIndices) {
+ // Command moveCommand = MoveCommand.create(editingDomain,
+ // eObject,feature, index, Math.max(index - 1,
+ // minIndex++));
+ // compoundCommand.append(moveCommand);
+ // }
+ // editingDomain.getCommandStack().execute(compoundCommand);
+ }
+
+ public static void moveElementsDown(final EObject eObject, final EStructuralFeature feature,
+ final Collection<Object> elements, final ICommandFactory commandFactory,
+ final EditingDomain editingDomain) {
+ Object value = eObject.eGet(feature);
+ List<?> list = (List<?>) value;
+
+ CompoundCommand compoundCommand = new CompoundCommand();
+
+ // prevent the last two elements from swapping
+ boolean canMove = !elements.contains(list.get(list.size() - 1));
+ for (int i = list.size() - 2; i >= 0; i--) {
+ final Object selectedObject = list.get(i);
+ if (elements.contains(selectedObject)) {
+ if (canMove) {
+ Command moveCommand = commandFactory.createMoveCommand(editingDomain, eObject,
+ feature, selectedObject, i + 1);
+ compoundCommand.append(moveCommand);
+ }
+ } else {
+ canMove = true;
+ }
+
+ }
+ editingDomain.getCommandStack().execute(compoundCommand);
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/FeatureValuesInput.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/FeatureValuesInput.java
new file mode 100644
index 00000000000..a5cafceae55
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/FeatureValuesInput.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+public class FeatureValuesInput {
+ private final EStructuralFeature feature;
+ private final EObject source;
+
+ public FeatureValuesInput(final EStructuralFeature feature, final EObject source) {
+ this.feature = feature;
+ this.source = source;
+ }
+
+ public EStructuralFeature getFeature() {
+ return this.feature;
+ }
+
+ public EObject getSource() {
+ return this.source;
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/ModelCellsEditingSupport.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/ModelCellsEditingSupport.java
new file mode 100644
index 00000000000..96e787a1852
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/ModelCellsEditingSupport.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Guyomar (Mia-Software) - Bug 339554 - org.eclipse.emf.facet.widgets.celleditors API cleaning
+ * Nicolas Bros (Mia-Software) - Bug 339855 - ModelCellEditor class should not be exposed
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.facet.widgets.celleditors.ICellEditorsRegistry;
+import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditHandler;
+import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public class ModelCellsEditingSupport<T> extends EditingSupport {
+
+ private final EStructuralFeature feature;
+ private final IModelCellEditor cellEditor;
+ private final EObject eObject;
+ private final ColumnViewer columnViewer;
+ private final Object newValuePlaceholder;
+ private List<T> values;
+
+ public ModelCellsEditingSupport(final ColumnViewer columnViewer,
+ final EStructuralFeature feature, final EObject eObject,
+ final Object newValuePlaceholder, final List<T> values) {
+ super(columnViewer);
+ this.columnViewer = columnViewer;
+ this.feature = feature;
+ this.eObject = eObject;
+ this.values = values;
+ this.newValuePlaceholder = newValuePlaceholder;
+ this.cellEditor = ICellEditorsRegistry.INSTANCE.getCellEditorFor(this.feature.getEType());
+ if (this.cellEditor == null) {
+ throw new IllegalStateException(
+ "no cell editor found for " + this.feature.getEType().getName()); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ return new CellEditor((Composite) this.columnViewer.getControl()) {
+
+ private Control control;
+
+ @Override
+ protected void doSetValue(final Object value) {
+ //
+ }
+
+ @Override
+ protected void doSetFocus() {
+ this.control.setFocus();
+ }
+
+ @Override
+ protected Object doGetValue() {
+ return null;
+ }
+
+ @Override
+ protected Control createControl(final Composite parent) {
+ IModelCellEditHandler editHandler = new IModelCellEditHandler() {
+ public void commit() {
+ @SuppressWarnings("unchecked")
+ //unchecked: The cellEditor.getValue() type cannot be checked.
+ T value = (T) ModelCellsEditingSupport.this.cellEditor.getValue();
+ int index = ModelCellsEditingSupport.this.values.indexOf(element);
+ if (index != -1
+ || element == ModelCellsEditingSupport.this.newValuePlaceholder) {
+ ModelCellsEditingSupport.this.values.set(index, value);
+ }
+ close();
+ ModelCellsEditingSupport.this.columnViewer.refresh();
+ }
+
+ };
+
+ Object originalValue = null;
+ if (element != ModelCellsEditingSupport.this.newValuePlaceholder) {
+ originalValue = element;
+ }
+
+ this.control = ModelCellsEditingSupport.this.cellEditor.activateCell(parent,
+ originalValue, editHandler, ModelCellsEditingSupport.this.feature,
+ ModelCellsEditingSupport.this.eObject);
+ return this.control;
+ }
+
+ public void close() {
+ deactivate();
+ Control parentControl = ModelCellsEditingSupport.this.columnViewer.getControl();
+ if (parentControl != null && !parentControl.isDisposed()) {
+ parentControl.forceFocus();
+ }
+ dispose();
+ }
+ };
+ }
+
+ @Override
+ protected boolean canEdit(final Object element) {
+ return true;
+ }
+
+ @Override
+ protected Object getValue(final Object element) {
+ return element;
+ }
+
+ @Override
+ protected void setValue(final Object element, final Object value) {
+ // TODO Auto-generated method stub
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryAttributeEditingDialog.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryAttributeEditingDialog.java
new file mode 100644
index 00000000000..61e2a0d0cb8
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryAttributeEditingDialog.java
@@ -0,0 +1,373 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Guyomar (Mia-Software) - Bug 339554 - org.eclipse.emf.facet.widgets.celleditors API cleaning
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditHandler;
+import org.eclipse.emf.facet.widgets.celleditors.internal.Messages;
+import org.eclipse.emf.facet.widgets.internal.CustomizableLabelProvider;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+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.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+/** A dialog to edit a multiplicity-many {@link EAttribute} */
+public class NaryAttributeEditingDialog<T extends Object> extends AbstractNaryEditingDialog<T> {
+
+ private static final int NUM_COLUMNS = 2;
+ private TableViewer featureValuesTableViewer;
+
+ private final Object newValuePlaceholder = new Object();
+
+ private Button addButton;
+ private Button removeButton;
+ private Button upButton;
+ private Button downButton;
+
+ private final ColumnLabelProvider labelProvider = new ColumnLabelProvider() {
+ private final LabelProvider delegateLabelProvider = new CustomizableLabelProvider();
+
+ @Override
+ public Image getImage(final Object element) {
+ return this.delegateLabelProvider.getImage(element);
+ }
+
+ @Override
+ public String getText(final Object element) {
+ if (element == NaryAttributeEditingDialog.this.newValuePlaceholder) {
+ return Messages.NaryAttributeEditingDialog_enterNewValuePlaceholder;
+ }
+ return this.delegateLabelProvider.getText(element);
+ }
+
+ @Override
+ public Color getForeground(final Object element) {
+ if (element == NaryAttributeEditingDialog.this.newValuePlaceholder) {
+ return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
+ }
+ return null;
+ }
+ };
+
+ /**
+ * @param parent
+ * the parent {@link Shell}
+ * @param values
+ * the current values
+ * @param editHandler
+ * the edit handler to perform the commit.
+ * @param feature
+ * the feature to edit
+ * @param eObject
+ * the eObject being currently edited. Should not be modified in this dialog.
+ */
+ public NaryAttributeEditingDialog(final Shell shell, final List<T> values,
+ final IModelCellEditHandler editHandler, final EObject eObject, final EStructuralFeature feature) {
+ super(shell, values, editHandler, eObject, feature);
+ }
+
+
+ @Override
+ protected void configureShell(final Shell shell) {
+ super.configureShell(shell);
+ shell.setText(NLS.bind(Messages.NaryReferenceEditingDialog_shellTitle,
+ getFeature().getName(), geteObject().eClass().getName()));
+ // prevent Escape or Enter from closing the dialog
+ // when a cell editor is active
+ shell.addListener(SWT.Traverse, new Listener() {
+ public void handleEvent(final Event e) {
+ if ((e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN)
+ && NaryAttributeEditingDialog.this.featureValuesTableViewer
+ .isCellEditorActive()) {
+ e.doit = false;
+ NaryAttributeEditingDialog.this.featureValuesTableViewer.cancelEditing();
+ }
+ }
+ });
+ }
+
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ final Composite contents = (Composite) super.createDialogArea(parent);
+
+ final GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
+ contentsGridLayout.numColumns = NaryAttributeEditingDialog.NUM_COLUMNS;
+
+ final GridData contentsGridData = (GridData) contents.getLayoutData();
+ contentsGridData.horizontalAlignment = SWT.FILL;
+ contentsGridData.verticalAlignment = SWT.FILL;
+
+ createValuesPane(contents);
+ createButtonsPane(contents);
+
+ this.featureValuesTableViewer.addOpenListener(new IOpenListener() {
+ public void open(final OpenEvent event) {
+ editSelectedElement();
+ }
+ });
+
+ this.upButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ upButtonClicked();
+ }
+ });
+
+ this.downButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ downButtonClicked();
+ }
+ });
+
+ this.addButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ addButtonClicked();
+ }
+ });
+
+ this.removeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ removeButtonClicked();
+ }
+ });
+
+ return contents;
+ }
+
+ @SuppressWarnings("unchecked") // type erasure on generic
+ private void addButtonClicked() {
+ getValues().add(0, (T) NaryAttributeEditingDialog.this.newValuePlaceholder);
+ refresh();
+ this.featureValuesTableViewer.editElement(this.newValuePlaceholder, 0);
+ }
+
+ @SuppressWarnings("unchecked") // type erasure on generic
+ private void removeButtonClicked() {
+ final IStructuredSelection selection = (IStructuredSelection) this.featureValuesTableViewer
+ .getSelection();
+
+ for (final Iterator<T> it = selection.iterator(); it.hasNext();) {
+ final Object element = it.next();
+
+ if (getValues().contains(element)) {
+ getValues().remove(element);
+ }
+ }
+ refresh();
+ }
+
+ private void spacer(final Composite parent) {
+ @SuppressWarnings("unused")
+ Label label = new Label(parent, SWT.NONE);
+ }
+
+ private void createButtonsPane(final Composite contents) {
+ final Composite buttonsComposite = new Composite(contents, SWT.NONE);
+ final GridData buttonsCompositeGridData = new GridData();
+ buttonsCompositeGridData.verticalAlignment = SWT.FILL;
+ buttonsCompositeGridData.horizontalAlignment = SWT.FILL;
+ buttonsComposite.setLayoutData(buttonsCompositeGridData);
+ buttonsComposite.setLayout(new GridLayout());
+
+ // spacer
+ spacer(buttonsComposite);
+
+ this.addButton = new Button(buttonsComposite, SWT.PUSH);
+ this.addButton.setText(Messages.NaryAttributeEditingDialog_add);
+ final GridData addButtonGridData = new GridData();
+ addButtonGridData.verticalAlignment = SWT.FILL;
+ addButtonGridData.horizontalAlignment = SWT.FILL;
+ this.addButton.setLayoutData(addButtonGridData);
+
+ this.removeButton = new Button(buttonsComposite, SWT.PUSH);
+ this.removeButton.setText(Messages.NaryAttributeEditingDialog_delete);
+ final GridData removeButtonGridData = new GridData();
+ removeButtonGridData.verticalAlignment = SWT.FILL;
+ removeButtonGridData.horizontalAlignment = SWT.FILL;
+ this.removeButton.setLayoutData(removeButtonGridData);
+
+ spacer(buttonsComposite);
+
+ this.upButton = new Button(buttonsComposite, SWT.PUSH);
+ this.upButton.setText(Messages.NaryReferenceEditingDialog_up);
+ final GridData upButtonGridData = new GridData();
+ upButtonGridData.verticalAlignment = SWT.FILL;
+ upButtonGridData.horizontalAlignment = SWT.FILL;
+ this.upButton.setLayoutData(upButtonGridData);
+
+ this.downButton = new Button(buttonsComposite, SWT.PUSH);
+ this.downButton.setText(Messages.NaryReferenceEditingDialog_down);
+ final GridData downButtonGridData = new GridData();
+ downButtonGridData.verticalAlignment = SWT.FILL;
+ downButtonGridData.horizontalAlignment = SWT.FILL;
+ this.downButton.setLayoutData(downButtonGridData);
+ }
+
+ private void createValuesPane(final Composite contents) {
+ final Composite featureComposite = new Composite(contents, SWT.NONE);
+ final GridData featureCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ featureCompositeData.horizontalAlignment = SWT.END;
+ featureComposite.setLayoutData(featureCompositeData);
+
+ final GridLayout featureCompositeLayout = new GridLayout();
+ featureCompositeData.horizontalAlignment = SWT.FILL;
+ featureCompositeLayout.marginHeight = 0;
+ featureCompositeLayout.marginWidth = 0;
+ featureCompositeLayout.numColumns = 1;
+ featureComposite.setLayout(featureCompositeLayout);
+
+ final Label featureLabel = new Label(featureComposite, SWT.NONE);
+ featureLabel.setText(Messages.NaryReferenceEditingDialog_values);
+ final GridData valuesLabelGridData = new GridData();
+ valuesLabelGridData.horizontalSpan = 2;
+ valuesLabelGridData.horizontalAlignment = SWT.FILL;
+ valuesLabelGridData.verticalAlignment = SWT.FILL;
+ featureLabel.setLayoutData(valuesLabelGridData);
+
+ final Table table = new Table(featureComposite, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
+ final GridData tableGridData = new GridData();
+ tableGridData.widthHint = AbstractNaryEditingDialog.AVAILABLE_VALUES_TREE_WIDTH;
+ tableGridData.heightHint = AbstractNaryEditingDialog.AVAILABLE_VALUES_TREE_HEIGHT;
+ tableGridData.verticalAlignment = SWT.FILL;
+ tableGridData.horizontalAlignment = SWT.FILL;
+ tableGridData.grabExcessHorizontalSpace = true;
+ tableGridData.grabExcessVerticalSpace = true;
+ table.setLayoutData(tableGridData);
+ final TableColumn tableColumn = new TableColumn(table, SWT.CENTER);
+
+ // full-width column
+ table.addControlListener(new ControlListener() {
+ public void controlResized(final ControlEvent e) {
+ tableColumn.setWidth(table.getClientArea().width);
+ }
+
+ public void controlMoved(final ControlEvent e) {
+ //
+ }
+ });
+
+ this.featureValuesTableViewer = new TableViewer(table);
+ this.featureValuesTableViewer.setContentProvider(new AssignedValuesContentProvider());
+ // this.fFeatureValuesTableViewer.setLabelProvider(this.labelProvider);
+ this.featureValuesTableViewer
+ .setInput(getValues());
+
+ final TableViewerColumn tableViewerColumn = new TableViewerColumn(
+ this.featureValuesTableViewer, tableColumn);
+ tableViewerColumn.setLabelProvider(this.labelProvider);
+
+ tableViewerColumn.setEditingSupport(new ModelCellsEditingSupport<T>(
+ this.featureValuesTableViewer, getFeature(), geteObject(),
+ this.newValuePlaceholder, getValues()));
+
+ // keyboard accessibility
+ table.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(final KeyEvent e) {
+ if (e.keyCode == SWT.F2) {
+ editSelectedElement();
+ }
+ if (e.keyCode == SWT.DEL) {
+ if (NaryAttributeEditingDialog.this.removeButton.isEnabled()) {
+ NaryAttributeEditingDialog.this.removeButton.notifyListeners(
+ SWT.Selection, null);
+ }
+ }
+ if (e.keyCode == SWT.ARROW_UP
+ && ((e.stateMask & SWT.COMMAND) != 0 || (e.stateMask & SWT.CONTROL) != 0)) {
+ if (NaryAttributeEditingDialog.this.upButton.isEnabled()) {
+ NaryAttributeEditingDialog.this.upButton.notifyListeners(SWT.Selection,
+ null);
+ }
+ }
+ if (e.keyCode == SWT.ARROW_DOWN
+ && ((e.stateMask & SWT.COMMAND) != 0 || (e.stateMask & SWT.CONTROL) != 0)) {
+ if (NaryAttributeEditingDialog.this.downButton.isEnabled()) {
+ NaryAttributeEditingDialog.this.downButton.notifyListeners(SWT.Selection,
+ null);
+ }
+ }
+ }
+ });
+
+ }
+
+ private void editSelectedElement() {
+ ISelection selection = NaryAttributeEditingDialog.this.featureValuesTableViewer
+ .getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ if (structuredSelection.getFirstElement() != null) {
+ NaryAttributeEditingDialog.this.featureValuesTableViewer.editElement(
+ structuredSelection.getFirstElement(), 0);
+ }
+ }
+ }
+
+ @Override
+ public void refresh() {
+ this.featureValuesTableViewer.refresh();
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(final Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+
+
+ @Override
+ public ISelection getSelection() {
+ return this.featureValuesTableViewer.getSelection();
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryReferenceEditingDialog.java b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryReferenceEditingDialog.java
new file mode 100644
index 00000000000..cef3a0120d7
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.widgets.celleditors/src/org/eclipse/emf/facet/widgets/celleditors/internal/ui/NaryReferenceEditingDialog.java
@@ -0,0 +1,489 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Guyomar (Mia-Software) - Bug 339554 - org.eclipse.emf.facet.widgets.celleditors API cleaning
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ * Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
+ *******************************************************************************/
+package org.eclipse.emf.facet.widgets.celleditors.internal.ui;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetReference;
+import org.eclipse.emf.facet.util.emf.ui.internal.dialogs.CreateInstanceDialog;
+import org.eclipse.emf.facet.widgets.celleditors.IModelCellEditHandler;
+import org.eclipse.emf.facet.widgets.celleditors.internal.Messages;
+import org.eclipse.emf.facet.widgets.internal.CustomizableLabelProvider;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.dialogs.PatternFilter;
+
+/** A dialog to edit a multiplicity-many {@link EReference} */
+public class NaryReferenceEditingDialog<T extends EObject> extends AbstractNaryEditingDialog<T> {
+
+
+ private Button addButton;
+ private Button removeButton;
+ private Button addAllButton;
+ private Button removeAllButton;
+ private Button upButton;
+ private Button downButton;
+
+ private static final int NUM_COLUMNS = 4;
+ // this is a *tree* viewer because PatternFilter only supports Trees
+ private TreeViewer availableValuesTreeViewer;
+ private ListViewer featureValuesListViewer;
+ private Button createInstanceButton;
+
+ private AssignableValuesContentProvider assignableValuesContentProvider;
+ private final List<T> availableValues;
+
+
+ /**
+ *
+ * @param parent
+ * the parent {@link Shell}
+ * @param values
+ * the list of current values.
+ * @param feature
+ * the feature to edit
+ * @param eObject
+ * the eObject being currently edited. Should not be modified in this dialog.
+ * @param editHandler
+ * The editHandler which has to be called when the edition is completed
+ */
+ public NaryReferenceEditingDialog(final Shell shell, final List<T> values,
+ final List<T> availableValues, final IModelCellEditHandler editHandler,
+ final EObject eObject, final EStructuralFeature feature) {
+ super(shell, values, editHandler, eObject, feature);
+ this.availableValues = new ArrayList<T>(availableValues);
+ }
+
+ @Override
+ protected void configureShell(final Shell shell) {
+ super.configureShell(shell);
+ shell.setText(NLS.bind(Messages.NaryReferenceEditingDialog_shellTitle,
+ getFeature().getName(), geteObject().eClass().getName()));
+ }
+
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ final Composite contents = (Composite) super.createDialogArea(parent);
+
+ final GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
+ contentsGridLayout.numColumns = NaryReferenceEditingDialog.NUM_COLUMNS;
+
+ final GridData contentsGridData = (GridData) contents.getLayoutData();
+ contentsGridData.horizontalAlignment = SWT.FILL;
+ contentsGridData.verticalAlignment = SWT.FILL;
+
+ createLeftPane(contents);
+ createMiddleButtonsPane(contents);
+ createRightPane(contents);
+ createRightButtonsPane(contents);
+
+ this.availableValuesTreeViewer.addOpenListener(new IOpenListener() {
+ public void open(final OpenEvent event) {
+ if (NaryReferenceEditingDialog.this.addButton.isEnabled()) {
+ NaryReferenceEditingDialog.this.addButton.notifyListeners(SWT.Selection, null);
+ }
+ }
+ });
+
+ this.featureValuesListViewer.addOpenListener(new IOpenListener() {
+ public void open(final OpenEvent event) {
+ if (NaryReferenceEditingDialog.this.removeButton.isEnabled()) {
+ NaryReferenceEditingDialog.this.removeButton.notifyListeners(SWT.Selection,
+ null);
+ }
+ }
+ });
+
+ this.upButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ upButtonClicked();
+ }
+ });
+
+ this.downButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ downButtonClicked();
+ }
+ });
+
+ this.addButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ addButtonClicked();
+ }
+ });
+
+ this.addAllButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ addAllButtonClicked();
+ }
+ });
+
+ this.removeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ removeButtonClicked();
+ }
+ });
+
+ this.removeAllButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ removeAllButtonClicked();
+ }
+ });
+
+ if (this.createInstanceButton != null) {
+ this.createInstanceButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent event) {
+ createInstanceButtonClicked();
+ }
+ });
+ }
+
+ return contents;
+ }
+
+ private void addButtonClicked() {
+ final IStructuredSelection selection = (IStructuredSelection) this.availableValuesTreeViewer
+ .getSelection();
+ if (selection.isEmpty() || !confirmMove()) {
+ return;
+ }
+ Iterator<T> it = getTCastedStructuredSelectionIterator(selection);
+ while (it.hasNext()) {
+ T element = it.next();
+ if (!(getValues() != null && getValues().contains(element))) {
+ getValues().add(element);
+ this.availableValues.remove(element);
+ }
+ }
+ refresh();
+ this.featureValuesListViewer.setSelection(selection);
+ }
+
+ @SuppressWarnings({ "unchecked", "static-method" })
+ //unchecked: the selection in not type parameterized, then we cannot get a cleaned cast iterator
+ //static-method: this method cannot be static to be able to use the T type.
+ private Iterator<T> getTCastedStructuredSelectionIterator(final IStructuredSelection selection) {
+ return selection.iterator();
+ }
+
+ private void addAllButtonClicked() {
+ if (this.availableValues.isEmpty() || !confirmMove()) {
+ return;
+ }
+ getValues().addAll(this.availableValues);
+ this.availableValues.removeAll(getValues());
+ refresh();
+ }
+
+ private void removeButtonClicked() {
+ final IStructuredSelection selection = (IStructuredSelection) this.featureValuesListViewer
+ .getSelection();
+ if (selection.isEmpty() || !confirmRemove()) {
+ return;
+ }
+
+ Iterator<T> it = this.getTCastedStructuredSelectionIterator(selection);
+ while (it.hasNext()) {
+ T element = it.next();
+ if (getValues().contains(element)) {
+ this.availableValues.add(element);
+ getValues().remove(element);
+ }
+ }
+ refresh();
+ }
+
+ private void removeAllButtonClicked() {
+ if (getValues().isEmpty() || !confirmRemove()) {
+ return;
+ }
+ this.availableValues.addAll(getValues());
+ getValues().removeAll(getValues());
+ refresh();
+ }
+
+ private boolean confirmRemove() {
+ if (getFeature() instanceof EReference) {
+ EReference eReference = (EReference) getFeature();
+ if (eReference.isContainment()) {
+ return MessageDialog.openConfirm(getShell(),
+ Messages.NaryReferenceEditingDialog_deleteElements,
+ Messages.NaryReferenceEditingDialog_deleteElementsLong);
+ }
+ }
+ return true;
+ }
+
+ private boolean confirmMove() {
+ if (getFeature() instanceof EReference || getFeature() instanceof FacetReference) {
+ EReference reference = (EReference) getFeature();
+ if (reference.isContainment()) {
+ String fullMessage = Messages.NaryReferenceEditingDialog_moveWarning;
+ return MessageDialog.openConfirm(getShell(),
+ Messages.NaryReferenceEditingDialog_moveElement, fullMessage);
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked") // type erasure on generic
+ private void createInstanceButtonClicked() {
+ EClassifier eType = getFeature().getEType();
+ if (eType instanceof EClass) {
+ EClass eClass = (EClass) eType;
+ EObject newInstance = CreateInstanceDialog.open(getShell(), eClass,
+ new CustomizableLabelProvider());
+ if (newInstance != null) {
+ getValues().add((T) newInstance);
+ refresh();
+ }
+ }
+ }
+
+ private void createLeftPane(final Composite contents) {
+ final Composite choiceComposite = new Composite(contents, SWT.NONE);
+ final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ data.horizontalAlignment = SWT.END;
+ choiceComposite.setLayoutData(data);
+
+ final GridLayout layout = new GridLayout();
+ data.horizontalAlignment = SWT.FILL;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 1;
+ choiceComposite.setLayout(layout);
+
+ final Label choiceLabel = new Label(choiceComposite, SWT.NONE);
+ choiceLabel.setText(Messages.NaryReferenceEditingDialog_availableValues);
+
+ final GridData choiceLabelGridData = new GridData();
+ choiceLabelGridData.verticalAlignment = SWT.FILL;
+ choiceLabelGridData.horizontalAlignment = SWT.FILL;
+ choiceLabel.setLayoutData(choiceLabelGridData);
+
+ final Text patternText = createFilterText(choiceComposite);
+
+ final Tree availableValuesTree = new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
+ final GridData availableValuesGridData = new GridData();
+ availableValuesGridData.widthHint = AbstractNaryEditingDialog.AVAILABLE_VALUES_TREE_WIDTH;
+ availableValuesGridData.heightHint = AbstractNaryEditingDialog.AVAILABLE_VALUES_TREE_HEIGHT;
+ availableValuesGridData.horizontalAlignment = SWT.FILL;
+ availableValuesGridData.verticalAlignment = SWT.FILL;
+ availableValuesGridData.grabExcessHorizontalSpace = true;
+ availableValuesGridData.grabExcessVerticalSpace = true;
+ availableValuesTree.setLayoutData(availableValuesGridData);
+
+ this.availableValuesTreeViewer = new TreeViewer(availableValuesTree);
+ this.assignableValuesContentProvider = new AssignableValuesContentProvider();
+ this.availableValuesTreeViewer.setContentProvider(this.assignableValuesContentProvider);
+ this.availableValuesTreeViewer.setLabelProvider(new CustomizableLabelProvider());
+ final PatternFilter filter = new PatternFilter();
+ this.availableValuesTreeViewer.addFilter(filter);
+
+ this.availableValuesTreeViewer.setInput(this.availableValues);
+
+ patternText.addModifyListener(new ModifyListener() {
+ public void modifyText(final ModifyEvent e) {
+ filter.setPattern(patternText.getText());
+ NaryReferenceEditingDialog.this.availableValuesTreeViewer.refresh();
+ }
+ });
+ }
+
+ private void createMiddleButtonsPane(final Composite contents) {
+ final Composite buttonsComposite = new Composite(contents, SWT.NONE);
+ final GridData buttonsCompositeGridData = new GridData();
+ buttonsCompositeGridData.verticalAlignment = SWT.CENTER;
+ buttonsCompositeGridData.horizontalAlignment = SWT.FILL;
+ buttonsComposite.setLayoutData(buttonsCompositeGridData);
+ buttonsComposite.setLayout(new GridLayout());
+
+ // new Label(buttonsComposite, SWT.NONE);
+
+ this.addButton = new Button(buttonsComposite, SWT.PUSH);
+ this.addButton.setText(Messages.NaryReferenceEditingDialog_add);
+ this.addButton.setToolTipText(Messages.NaryReferenceEditingDialog_addTooltip);
+ final GridData addButtonGridData = new GridData();
+ addButtonGridData.verticalAlignment = SWT.FILL;
+ addButtonGridData.horizontalAlignment = SWT.FILL;
+ this.addButton.setLayoutData(addButtonGridData);
+
+ this.removeButton = new Button(buttonsComposite, SWT.PUSH);
+ this.removeButton.setText(Messages.NaryReferenceEditingDialog_remove);
+ this.removeButton.setToolTipText(Messages.NaryReferenceEditingDialog_removeTooltip);
+ final GridData removeButtonGridData = new GridData();
+ removeButtonGridData.verticalAlignment = SWT.FILL;
+ removeButtonGridData.horizontalAlignment = SWT.FILL;
+ this.removeButton.setLayoutData(removeButtonGridData);
+
+ spacer(buttonsComposite);
+
+ this.addAllButton = new Button(buttonsComposite, SWT.PUSH);
+ this.addAllButton.setText(Messages.NaryReferenceEditingDialog_addAll);
+ this.addAllButton.setToolTipText(Messages.NaryReferenceEditingDialog_addAllTooltip);
+
+ this.removeAllButton = new Button(buttonsComposite, SWT.PUSH);
+ this.removeAllButton.setText(Messages.NaryReferenceEditingDialog_removeAll);
+ this.removeAllButton.setToolTipText(Messages.NaryReferenceEditingDialog_removeAllTooltip);
+ }
+
+ private void spacer(final Composite parent) {
+ @SuppressWarnings("unused")
+ Label label = new Label(parent, SWT.NONE);
+ }
+
+ private void createRightButtonsPane(final Composite contents) {
+ final Composite buttonsComposite = new Composite(contents, SWT.NONE);
+ final GridData buttonsCompositeGridData = new GridData();
+ buttonsCompositeGridData.verticalAlignment = SWT.FILL;
+ buttonsCompositeGridData.horizontalAlignment = SWT.FILL;
+ buttonsComposite.setLayoutData(buttonsCompositeGridData);
+ buttonsComposite.setLayout(new GridLayout());
+
+ // spacer
+ spacer(buttonsComposite);
+
+ if (getFeature() instanceof EReference) {
+ EReference eReference = (EReference) getFeature();
+ if (eReference.isContainment()) {
+ this.createInstanceButton = new Button(buttonsComposite, SWT.PUSH);
+ this.createInstanceButton.setText(Messages.NaryReferenceEditingDialog_newInstance);
+ final GridData createButtonGridData = new GridData();
+ createButtonGridData.verticalAlignment = SWT.FILL;
+ createButtonGridData.horizontalAlignment = SWT.FILL;
+ this.createInstanceButton.setLayoutData(createButtonGridData);
+ spacer(buttonsComposite);
+ }
+
+ }
+
+ this.upButton = new Button(buttonsComposite, SWT.PUSH);
+ this.upButton.setText(Messages.NaryReferenceEditingDialog_up);
+ final GridData upButtonGridData = new GridData();
+ upButtonGridData.verticalAlignment = SWT.FILL;
+ upButtonGridData.horizontalAlignment = SWT.FILL;
+ this.upButton.setLayoutData(upButtonGridData);
+
+ this.downButton = new Button(buttonsComposite, SWT.PUSH);
+ this.downButton.setText(Messages.NaryReferenceEditingDialog_down);
+ final GridData downButtonGridData = new GridData();
+ downButtonGridData.verticalAlignment = SWT.FILL;
+ downButtonGridData.horizontalAlignment = SWT.FILL;
+ this.downButton.setLayoutData(downButtonGridData);
+ }
+
+ private void createRightPane(final Composite contents) {
+ final Composite featureComposite = new Composite(contents, SWT.NONE);
+ final GridData featureCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ featureCompositeData.horizontalAlignment = SWT.END;
+ featureComposite.setLayoutData(featureCompositeData);
+
+ final GridLayout featureCompositeLayout = new GridLayout();
+ featureCompositeData.horizontalAlignment = SWT.FILL;
+ featureCompositeLayout.marginHeight = 0;
+ featureCompositeLayout.marginWidth = 0;
+ featureCompositeLayout.numColumns = 1;
+ featureComposite.setLayout(featureCompositeLayout);
+
+ final Label featureLabel = new Label(featureComposite, SWT.NONE);
+ featureLabel.setText(Messages.NaryReferenceEditingDialog_values);
+ final GridData valuesLabelGridData = new GridData();
+ valuesLabelGridData.horizontalSpan = 2;
+ valuesLabelGridData.horizontalAlignment = SWT.FILL;
+ valuesLabelGridData.verticalAlignment = SWT.FILL;
+ featureLabel.setLayoutData(valuesLabelGridData);
+
+ final org.eclipse.swt.widgets.List availableValuesList = new org.eclipse.swt.widgets.List(
+ featureComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
+ final GridData availableValuesGridData = new GridData();
+ availableValuesGridData.widthHint = AbstractNaryEditingDialog.AVAILABLE_VALUES_TREE_WIDTH;
+ availableValuesGridData.heightHint = AbstractNaryEditingDialog.AVAILABLE_VALUES_TREE_HEIGHT;
+ availableValuesGridData.verticalAlignment = SWT.FILL;
+ availableValuesGridData.horizontalAlignment = SWT.FILL;
+ availableValuesGridData.grabExcessHorizontalSpace = true;
+ availableValuesGridData.grabExcessVerticalSpace = true;
+ availableValuesList.setLayoutData(availableValuesGridData);
+
+ this.featureValuesListViewer = new ListViewer(availableValuesList);
+ this.featureValuesListViewer.setContentProvider(new AssignedValuesContentProvider());
+ this.featureValuesListViewer.setLabelProvider(new CustomizableLabelProvider());
+ this.featureValuesListViewer
+ .setInput(getValues());
+ }
+
+ private Text createFilterText(final Composite contents) {
+ Text patternText = new Text(contents, SWT.BORDER | SWT.SEARCH);
+ patternText.setMessage(Messages.NaryReferenceEditingDialog_typeFilterText);
+ patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ return patternText;
+ }
+
+ @Override
+ public void refresh() {
+ this.availableValuesTreeViewer.refresh();
+ this.featureValuesListViewer.refresh();
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(final Composite parent) {
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+
+ @Override
+ public ISelection getSelection() {
+ return this.featureValuesListViewer.getSelection();
+ }
+}

Back to the top