Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-12-16 15:16:06 +0000
committerGerrit Code Review @ Eclipse.org2016-12-16 17:20:59 +0000
commit5b79cfb1b41f2089508ebda7c82675513fd3620c (patch)
tree6fdbcfeb9d424ff6dbe05fbd8461be10a0d38b50 /plugins/infra
parentcc5807c3961121773e939142c9f7bd1717dc12f3 (diff)
downloadorg.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.tar.gz
org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.tar.xz
org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.zip
Bug 502533: [Property View] Property pages generated for DataType
shall be improved - Modification of the compliance of the uml.nattable plugin to use PapyrusObservableValue not deprecated. Developed by Fanch Bonnabesse. Change-Id: Ib2c5436de26a256ac136715a58de716bd816da2c Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java270
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java115
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java104
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java107
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java87
-rw-r--r--plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi8
-rw-r--r--plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectDirectEditingValueFactory.java67
-rw-r--r--plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectStructuredValueFactory.java156
-rw-r--r--plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/DataTypeEditor.java98
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeReferenceValueEditor.java407
11 files changed, 1420 insertions, 1 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
new file mode 100644
index 00000000000..457f0f68d92
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
@@ -0,0 +1,270 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.databinding;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.ui.provider.PropertyDescriptor.EDataTypeCellEditor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.swt.SWT;
+
+/**
+ *
+ * Editing Support used to edit EObservableValue on a TreeViewer.
+ *
+ */
+public class EObjectObservableValueEditingSupport extends EditingSupport {
+
+ /** proposals for boolean */
+ protected final String[] booleanProposals = new String[] { "true", "false" }; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Constructor.
+ *
+ * @param viewer
+ * Viewer in which editors will open.
+ * @param factory
+ * The reference value factory.
+ */
+ public EObjectObservableValueEditingSupport(final ColumnViewer viewer, final ReferenceValueFactory factory) {
+ super(viewer);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang.Object)
+ */
+ @Override
+ protected boolean canEdit(final Object element) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
+ */
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ if (element instanceof EObjectObservableValue) {
+ Object valueType = ((EObjectObservableValue) element).getValueType();
+ if (valueType instanceof EStructuralFeature) {
+ EStructuralFeature feature = (EStructuralFeature) valueType;
+
+ if (feature instanceof EReference) {
+ return null;
+ }
+
+ EClassifier eType = feature.getEType();
+ if (eType instanceof EEnum) {
+ return createEnumerationEditor(feature);
+ } else {
+ String instanceTypeName = eType.getInstanceClassName();
+ if (instanceTypeName.equals("boolean")) { //$NON-NLS-1$
+ return createBooleanEditor();
+ }
+ }
+
+ if (eType instanceof EDataType) {
+ return new EDataTypeCellEditor((EDataType) eType, ((TreeViewer) getViewer()).getTree());
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object)
+ */
+ @Override
+ protected Object getValue(final Object element) {
+ if (element instanceof EObjectObservableValue) {
+ EStructuralFeature feature = (EStructuralFeature) ((EObjectObservableValue) element).getValueType();
+ if (feature instanceof EReference) {
+ return null;
+ // return getReferenceValue((EReference) feature);
+ }
+ EClassifier eType = feature.getEType();
+ Object object = ((EObjectObservableValue) element).getValue();
+ if (eType instanceof EEnum) {
+ return getEnumerationValue((EEnum) eType, object);
+ } else {
+ String instanceTypeName = eType.getInstanceClassName();
+ if (instanceTypeName.equals("boolean")) { //$NON-NLS-1$
+ return getBooleanValue(object);
+ }
+
+ return object;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the value from the feature.
+ *
+ * @param feature
+ * The feature to edit.
+ * @param object
+ * The object to search.
+ * @return the boolean value
+ */
+ protected Object getEnumerationValue(final EEnum eType, final Object object) {
+ List<EEnumLiteral> literals = eType.getELiterals();
+ if (object == null) {
+ return 0;
+ } else {
+ return literals.indexOf(object);
+ }
+ }
+
+ /**
+ * Returns the value from the feature.
+ *
+ * @return the boolean value.
+ */
+ protected Object getBooleanValue(final Object object) {
+ List<String> booleans = Arrays.asList(booleanProposals);
+ if (object == null || object.equals("")) {
+ return 0;
+ }
+ return booleans.indexOf(object.toString());
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object, java.lang.Object)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void setValue(final Object element, final Object value) {
+ if (element instanceof EObjectObservableValue) {
+ EStructuralFeature feature = (EStructuralFeature) ((EObjectObservableValue) element).getValueType();
+ if (feature instanceof EReference) {
+ // setReferenceValue(element, value);
+ } else {
+ EClassifier eType = feature.getEType();
+ if (eType instanceof EEnum) {
+ setEnumerationValue((EObjectObservableValue) element, value);
+ } else {
+ String instanceTypeName = eType.getInstanceClassName();
+ if (instanceTypeName.equals("boolean")) { //$NON-NLS-1$
+ setBooleanValue((EObjectObservableValue) element, value);
+ } else {
+ ((EObjectObservableValue) element).setValue(value);
+ }
+ }
+ }
+
+ getViewer().update(element, null);
+ }
+ }
+
+ /**
+ * This allows to set the enumeration value.
+ *
+ * @param element
+ * The element to manage.
+ * @param value
+ * The value to set.
+ */
+ @SuppressWarnings("unchecked")
+ protected void setEnumerationValue(final EObjectObservableValue element, final Object value) {
+ EStructuralFeature feature = (EStructuralFeature) element.getValueType();
+ EEnum eType = (EEnum) feature.getEType();
+ List<EEnumLiteral> literals = eType.getELiterals();
+ List<String> proposals = new ArrayList<>();
+ for (int i = 0; i < literals.size(); i++) {
+ // i+1 because there is already the "" string
+ proposals.add(i, literals.get(i).getLiteral());
+ }
+ if (null == value) {
+ element.setValue(null);
+ } else {
+ // retrieve the index of the current value in the list
+ int index = (Integer) value;
+ if (index >= 0 && index < literals.size()) {
+ element.setValue(literals.get(index));
+ }
+ }
+ }
+
+ /**
+ * Sets the new boolean value on the given element.
+ *
+ * @param element
+ * The model element.
+ * @param value
+ * The new value.
+ */
+ @SuppressWarnings("unchecked")
+ protected void setBooleanValue(final EObjectObservableValue element, final Object value) {
+ if (null == value) {
+ // propertiesToUpdate.remove(featureName);
+ } else if (value.equals(0)) {
+ element.setValue(Boolean.valueOf(booleanProposals[0]));
+ } else if (value.equals(1)) {
+ element.setValue(Boolean.valueOf(booleanProposals[1]));
+ } else {
+ Activator.log.error("impossible to set boolean value " + value, null); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates and return a combobox cell editor for a boolean type
+ *
+ * @return the newly created combo box cell editor
+ */
+ protected CellEditor createBooleanEditor() {
+ return new ComboBoxCellEditor(((TreeViewer) getViewer()).getTree(), booleanProposals, SWT.READ_ONLY);
+ }
+
+ /**
+ * Creates and return a combobox cell editor for an enumeration type
+ *
+ * @param feature
+ * the feature to edit
+ * @return the newly created combo box cell editor
+ */
+ protected CellEditor createEnumerationEditor(final EStructuralFeature feature) {
+ EEnum eType = (EEnum) feature.getEType();
+ List<EEnumLiteral> literals = eType.getELiterals();
+ String[] proposals = new String[literals.size()];
+ for (int i = 0; i < literals.size(); i++) {
+ proposals[i] = literals.get(i).getLiteral();
+ }
+ return new ComboBoxCellEditor(((TreeViewer) getViewer()).getTree(), proposals, SWT.READ_ONLY);
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java
new file mode 100644
index 00000000000..fd6ee4c4fd3
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.databinding;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+
+/**
+ * Structured ObservableValue.
+ */
+public class EObjectStructuredObservableValue extends EMFObservableValue {
+
+ /**
+ * List of child of the ObservableValue.
+ */
+ protected List<EObjectObservableValue> observables = new ArrayList<>();
+
+ /**
+ * Constructor.
+ *
+ * @param eObject
+ * The EObject to edit.
+ * @param eStructuralFeature
+ * The structural feature.
+ * @param domain
+ * The current editing domain.
+ * @param browseFeatures
+ * The features for the browse.
+ */
+ public EObjectStructuredObservableValue(EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain, boolean browseFeatures) {
+ super(eObject, eStructuralFeature, domain);
+ if (null != eObject) {
+ if (browseFeatures) {
+ browseFeatures(eObject);
+ }
+ }
+ }
+
+ /**
+ * Get the child.
+ *
+ * @return The observables.
+ */
+ public List<EObjectObservableValue> getObservables() {
+ return observables;
+ }
+
+ /**
+ * Crete the child.
+ *
+ * @param eObject
+ * The parent.
+ */
+ private void browseFeatures(final EObject eObject) {
+ EList<EStructuralFeature> eStructuralFeatures = eObject.eClass().getEStructuralFeatures();
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(eObject);
+ for (EStructuralFeature eStructuralFeature : eStructuralFeatures) {
+ EObjectObservableValue eObjectObservableValue;
+ Object eGet = eObject.eGet(eStructuralFeature);
+ if (eStructuralFeature instanceof EReference && eGet instanceof EObject) {
+ eObjectObservableValue = new EObjectStructuredObservableValue((EObject) eGet, eStructuralFeature, editingDomain, true);
+ } else {
+ eObjectObservableValue = new EObjectStructuredObservableValue(eObject, eStructuralFeature, editingDomain, false);
+ }
+ observables.add(eObjectObservableValue);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.databinding.EObjectObservableValue#getValueType()
+ */
+ @Override
+ public Object getValueType() {
+ Object valueType = super.getValueType();
+ if (null == valueType && null != eObject) {
+ valueType = eObject.eClass();
+ }
+ return valueType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.databinding.EObjectObservableValue#dispose()
+ */
+ @Override
+ public synchronized void dispose() {
+ for (EObjectObservableValue eObjectObservableValue : observables) {
+ eObjectObservableValue.dispose();
+ }
+ super.dispose();
+ }
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java
new file mode 100644
index 00000000000..046174a3478
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.dialog;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EObjectObservableValueEditingSupport;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EObjectStructuredObservableValue;
+import org.eclipse.papyrus.infra.ui.emf.providers.EObjectObservableValueContentProvider;
+import org.eclipse.papyrus.infra.ui.emf.providers.EObjectObservableValueLabelProvider;
+import org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor;
+import org.eclipse.papyrus.infra.widgets.providers.DelegatingStyledLabelProvider;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * This class extends TreeReferenceDialog and allow the display of EObjectObservableValue.
+ */
+public class EObjectTreeReferenceValueEditor extends TreeReferenceValueEditor {
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * the parent composite.
+ * @param style
+ * The style of the composite to create.
+ */
+ public EObjectTreeReferenceValueEditor(final Composite parent, final int style) {
+ super(parent, style);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#setValueRootContentProvider()
+ */
+ @Override
+ public void setValueRootContentProvider() {
+ if (null != treeViewer) {
+ if (treeViewer.getContentProvider() instanceof EObjectObservableValueContentProvider) {
+ ((EObjectObservableValueContentProvider) treeViewer.getContentProvider()).setValueRoot(widgetObservable);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#setProvidersTreeViewer()
+ */
+ @Override
+ public void setProvidersTreeViewer() {
+ treeViewer.setContentProvider(new EObjectObservableValueContentProvider(widgetObservable));
+ if (labelProvider instanceof IStyledLabelProvider) {
+ treeViewer.setLabelProvider(new EObjectObservableValueLabelProvider((IStyledLabelProvider) labelProvider));
+ } else {
+ treeViewer.setLabelProvider(new EObjectObservableValueLabelProvider(new DelegatingStyledLabelProvider(labelProvider)));
+ }
+
+ treeViewer.setInput(""); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#createWidgetObservable(org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ public IObservableValue createWidgetObservable(final IObservableValue modelProperty) {
+ EObjectStructuredObservableValue eObjectObser = null;
+ if (modelProperty.getValue() instanceof EObject) {
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain((EObject) modelProperty.getValue());
+ eObjectObser = new EObjectStructuredObservableValue((EObject) modelProperty.getValue(), null, editingDomain, true);
+ }
+ return eObjectObser;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#createEditingSupport()
+ */
+ @Override
+ public EditingSupport createEditingSupport() {
+ return new EObjectObservableValueEditingSupport(treeViewer, valueFactory);
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java
new file mode 100644
index 00000000000..f0a9caeb39d
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.providers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EObjectStructuredObservableValue;
+
+/**
+ * ContentProvider of the EObjectObservaleValue.
+ */
+public class EObjectObservableValueContentProvider implements ITreeContentProvider {
+
+ /**
+ * Value root of the tree.
+ */
+ private Object valueRoot = null;
+
+ /**
+ * Constructor.
+ *
+ * @param value
+ * The value to manage.
+ */
+ public EObjectObservableValueContentProvider(final Object value) {
+ super();
+ valueRoot = value;
+ }
+
+ /**
+ * This allows to set the root value.
+ *
+ * @param value
+ * the root value
+ */
+ public void setValueRoot(final Object value) {
+ this.valueRoot = value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements(final Object inputElement) {
+ ArrayList<Object> arrayList = new ArrayList<>();
+ if (null != valueRoot) {
+ arrayList.add(valueRoot);
+ }
+
+
+ return arrayList.toArray();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(final Object parentElement) {
+ final List<EObjectObservableValue> children = new ArrayList<>();
+
+ if (parentElement instanceof EObjectStructuredObservableValue) {
+ List<EObjectObservableValue> observables = ((EObjectStructuredObservableValue) parentElement).getObservables();
+ children.addAll(observables);
+ }
+
+ return children.toArray();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(final Object element) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(final Object element) {
+ return 0 < getChildren(element).length;
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
new file mode 100644
index 00000000000..6df791cfd22
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.providers;
+
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider;
+
+/**
+ * LabelProvider used to show feature name and EObject of an EObjectObservaleValue.
+ *
+ */
+public class EObjectObservableValueLabelProvider extends DelegatingStyledCellLabelProvider {
+
+ /**
+ * Index of the EStructuralFeature.
+ */
+ private static final int ESTRUCTURAL_FEATURE = 0;
+
+ /**
+ * Index of the EObject.
+ */
+ private static final int EOBJECT = 1;
+
+ /**
+ * Constructor.
+ *
+ * @param styledLabelProvider
+ * The {@link IStyledLabelProvider}.
+ */
+ public EObjectObservableValueLabelProvider(final IStyledLabelProvider styledLabelProvider) {
+ super(styledLabelProvider);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ @Override
+ public String getColumnText(final Object element, final int columnIndex) {
+ if (element instanceof EObjectObservableValue) {
+ String columnText = ""; //$NON-NLS-1$
+ EObjectObservableValue elementObservableValue = (EObjectObservableValue) element;
+ Object valueType = elementObservableValue.getValueType();
+ if (valueType instanceof EAttribute) {
+ switch (columnIndex) {
+ case ESTRUCTURAL_FEATURE:
+ if (valueType instanceof EStructuralFeature) {
+ columnText = ((EStructuralFeature) valueType).getName();
+ }
+ break;
+ case EOBJECT:
+ if (null != elementObservableValue.getValue()) {
+ columnText = elementObservableValue.getValue().toString();
+ }
+ break;
+ default:
+ columnText = super.getColumnText(element, columnIndex);
+ break;
+ }
+ } else {
+ if (ESTRUCTURAL_FEATURE == columnIndex) {
+ if (valueType instanceof ENamedElement) {
+ columnText = ((ENamedElement) valueType).getName();
+ }
+ }
+ }
+
+ return columnText;
+ }
+ return super.getColumnText(element, columnIndex);
+ }
+}
diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/META-INF/MANIFEST.MF b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/META-INF/MANIFEST.MF
index 3441b89268d..7b533edbce7 100644
--- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/META-INF/MANIFEST.MF
+++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/META-INF/MANIFEST.MF
@@ -22,7 +22,7 @@ Require-Bundle: org.eclipse.papyrus.infra.properties;bundle-version="[1.2.0,2.0.
org.eclipse.papyrus.infra.widgets;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="[1.2.0,2.0.0)",
- org.eclipse.xwt;bundle-version="[1.1.0,2.0.0)",
+ org.eclipse.xwt;bundle-version="[1.2.0,2.0.0)",
org.eclipse.papyrus.infra.ui.emf;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 2.0.0.qualifier
diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi
index 9c1059070ff..cee209ee374 100644
--- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi
+++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/model/Environment.xmi
@@ -27,6 +27,9 @@
<modelElementFactories
name="Basic preferences Factory"
factoryClass="org.eclipse.papyrus.infra.properties.ui.modelelement.PreferencesModelElementFactory"/>
+ <modelElementFactories
+ name="DynamicEObject Factory"
+ factoryClass="org.eclipse.papyrus.infra.properties.ui.modelelement.DynamicEObjectModelElementFactory"/>
<widgetTypes
label="Label"
widgetClass="Label"/>
@@ -184,6 +187,11 @@
label="Icon property editor with browser"
widgetClass="IconPropertyEditor"
namespace="//@namespaces.3"/>
+ <propertyEditorTypes
+ label="DataTypeEditor"
+ widgetClass="DataTypeEditor"
+ namespace="//@namespaces.3"
+ type="Reference"/>
<compositeWidgetTypes
label="Composite"
widgetClass="Composite"/>
diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectDirectEditingValueFactory.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectDirectEditingValueFactory.java
new file mode 100644
index 00000000000..d163bbe2d37
--- /dev/null
+++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectDirectEditingValueFactory.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.properties.ui.modelelement;
+
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.constraints.runtime.ConstraintEngine;
+import org.eclipse.papyrus.infra.properties.contexts.View;
+import org.eclipse.papyrus.infra.properties.ui.creation.CreationContext;
+import org.eclipse.papyrus.infra.properties.ui.creation.EcorePropertyEditorFactory;
+import org.eclipse.papyrus.infra.properties.ui.runtime.PropertiesRuntime;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A ReferenceFactory used to instantiate EObjects.
+ */
+public class EObjectDirectEditingValueFactory extends EcorePropertyEditorFactory {
+
+ /**
+ * Constructor.
+ *
+ * @param referenceIn
+ * The {@link EReference}.
+ */
+ public EObjectDirectEditingValueFactory(final EReference referenceIn) {
+ super(referenceIn);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.creation.PropertyEditorFactory#createObject(org.eclipse.swt.widgets.Control, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ protected Object createObject(final Control widget, final Object context, final Object source) {
+ if (source == null) {
+ return null;
+ }
+
+ IStructuredSelection selection = new StructuredSelection(source);
+
+ ConstraintEngine<View> constraintEngine = PropertiesRuntime.getConstraintEngine();
+ Set<View> views = constraintEngine.getDisplayUnits(selection);
+ if (!views.isEmpty()) {
+ CreationContext creationContext = getCreationContext(context);
+ creationContext.pushCreatedElement(source);
+ creationContext.popCreatedElement(source);
+ }
+
+ return source;
+ }
+
+}
diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectStructuredValueFactory.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectStructuredValueFactory.java
new file mode 100644
index 00000000000..39d9c59b3e9
--- /dev/null
+++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/EObjectStructuredValueFactory.java
@@ -0,0 +1,156 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.properties.ui.modelelement;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.DeleteCommand;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A ReferenceFactory used to instantiate new DataType.
+ * DataType may contain other DataType
+ */
+public class EObjectStructuredValueFactory extends EObjectDirectEditingValueFactory {
+
+ /**
+ * Constructor.
+ *
+ * @param referenceIn
+ */
+ public EObjectStructuredValueFactory(final EReference referenceIn) {
+ super(referenceIn);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.creation.EcorePropertyEditorFactory#doCreateObject(org.eclipse.swt.widgets.Control, java.lang.Object)
+ */
+ @Override
+ protected Object doCreateObject(final Control widget, final Object context) {
+ Object instance;
+
+ if (referenceIn.isContainment()) {
+ instance = createStructuredObject(widget);
+ } else {
+ instance = createObjectInDifferentContainer(widget);
+ }
+
+ return createObject(widget, context, instance);
+ }
+
+ /**
+ * Create an object an its child.
+ *
+ * @param widget
+ * The widget.
+ * @return The created object.
+ */
+ protected EObject createStructuredObject(final Control widget) {
+ EClass eClass = chooseEClass(widget);
+ if (eClass == null) {
+ return null;
+ }
+
+ EObject instance = eClass.getEPackage().getEFactoryInstance().create(eClass);
+
+ createStructure(instance);
+
+ return instance;
+ }
+
+ /**
+ * Creation of the instance of the DataType referenced by the container.
+ *
+ * @param eObject
+ * The container.
+ */
+ private void createStructure(final EObject eObject) {
+ if (null != eObject) {
+ EList<EStructuralFeature> eStructuralFeatures = eObject.eClass().getEStructuralFeatures();
+ for (EStructuralFeature eStructuralFeature : eStructuralFeatures) {
+ if (eStructuralFeature instanceof EReference) {
+ Object eGet = eObject.eGet(eStructuralFeature);
+ if (eGet == null) {
+ if (eStructuralFeature.getEType() instanceof EClass) {
+ EClass new_name = (EClass) eStructuralFeature.getEType();
+ EObject create = new_name.getEPackage().getEFactoryInstance().create(new_name);
+ setValue(eObject, create, eGet, eStructuralFeature);
+ eGet = eObject.eGet(eStructuralFeature);
+ }
+ }
+
+ createStructure((EObject) eGet);
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the edit value by command.
+ *
+ * @param eObject
+ * The parent object to edit.
+ * @param value
+ * The new value
+ * @param oldValue
+ * The old value
+ * @param eStructuralFeature
+ * The feature.
+ */
+ protected void setValue(final EObject eObject, final Object value, final Object oldValue, final EStructuralFeature eStructuralFeature) {
+ final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(eObject);
+
+ final Command command = getSetCommand(eObject, value, oldValue, eStructuralFeature, editingDomain);
+ command.execute();
+ }
+
+ /**
+ * Returns the command used to edit the value.
+ *
+ * @param eObject
+ * The parent object to edit.
+ * @param value
+ * The new value
+ * @param oldValue
+ * The old value
+ * @param eStructuralFeature
+ * The feature.
+ * @param domain
+ * the current editing domain.
+ * @return The Set command used to edit the value
+ */
+ protected Command getSetCommand(final EObject eObject, final Object value, final Object oldValue, final EStructuralFeature eStructuralFeature, final EditingDomain domain) {
+ CompoundCommand cc = new CompoundCommand("Edit value"); //$NON-NLS-1$
+
+ if (oldValue instanceof EObject && eStructuralFeature instanceof EReference && ((EReference) eStructuralFeature).isContainment()) {
+ cc.append(DeleteCommand.create(domain, oldValue));
+ }
+
+ cc.append(new SetCommand(domain, eObject, eStructuralFeature, value));
+
+ return cc;
+ }
+
+}
diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/DataTypeEditor.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/DataTypeEditor.java
new file mode 100644
index 00000000000..38709caac46
--- /dev/null
+++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/DataTypeEditor.java
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.properties.ui.widgets;
+
+import org.eclipse.papyrus.infra.ui.emf.dialog.EObjectTreeReferenceValueEditor;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * This class is used to create a Property Editor based on the DataType.
+ */
+public class DataTypeEditor extends AbstractPropertyEditor {
+
+ /**
+ * The TreeReferenceDialog widget
+ */
+ protected TreeReferenceValueEditor editor;
+
+ /**
+ * The ValueFactory used to create or edit Objects directly from this editor.
+ */
+ protected ReferenceValueFactory factory;
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * The composite in which the widget will be displayed
+ * @param style
+ * The style for the widget
+ */
+ public DataTypeEditor(final Composite parent, final int style) {
+ editor = createTreeReferenceDialog(parent, style);
+ setEditor(editor);
+ }
+
+ /**
+ * Creates the tree reference dialog.
+ *
+ * @param parent
+ * The composite in which the widget will be displayed
+ * @param style
+ * The style for the widget
+ * @return the tree reference dialog.
+ */
+ protected TreeReferenceValueEditor createTreeReferenceDialog(final Composite parent, final int style) {
+ return new EObjectTreeReferenceValueEditor(parent, style);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.widgets.AbstractPropertyEditor#doBinding()
+ */
+ @Override
+ protected void doBinding() {
+ super.doBinding();
+
+ editor.setLabelProvider(input.getLabelProvider(propertyPath));
+ editor.setProvidersTreeViewer();
+ if (factory == null) { // Use the default factory from the DataSource
+ factory = input.getValueFactory(propertyPath);
+ }
+ editor.setValueFactory(factory);
+ }
+
+ /**
+ * Sets the ValueFactory used to create or edit Objects directly from this editor.
+ *
+ * @param factory
+ * The {@link ReferenceValueFactory}.
+ */
+ public void setFactory(final ReferenceValueFactory factory) {
+ this.factory = factory;
+ editor.setValueFactory(factory);
+ }
+
+ /**
+ * Get the ValueFactory used to create or edit Objects directly from this editor.
+ *
+ * @return The ValueFactory used to create or edit Objects directly from this editor.
+ */
+ public ReferenceValueFactory getFactory() {
+ return factory;
+ }
+}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeReferenceValueEditor.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeReferenceValueEditor.java
new file mode 100644
index 00000000000..49050bbceb9
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeReferenceValueEditor.java
@@ -0,0 +1,407 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.widgets.editors;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.layout.TreeColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.infra.widgets.messages.Messages;
+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.Tree;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * This class allow to define a Tree Reference Value Editor.
+ */
+public abstract class TreeReferenceValueEditor extends AbstractValueEditor implements SelectionListener {
+
+ /**
+ * The Button used to create a new instance
+ */
+ protected Button createInstanceButton;
+
+ /**
+ * The Button used to unset the current value
+ */
+ protected Button unsetButton;
+
+ /**
+ * The label provider used to display the values in both the label and the
+ * selection dialog
+ */
+ protected ILabelProvider labelProvider;
+
+ /**
+ * The current value for this editor
+ */
+ protected Object value;
+
+ /**
+ * The factory used to create or edit objects directly from this editor
+ */
+ protected ReferenceValueFactory valueFactory;
+
+ /**
+ * TreeViewer to show
+ */
+ protected TreeViewer treeViewer;
+
+ /**
+ * The tree of the TreeViewer.
+ */
+ protected Tree tree;
+
+ /**
+ * The parent composite of the tree viewer.
+ */
+ protected Composite compositeTree;
+
+ /**
+ * The adapter used to refresh the TreeViewer.
+ */
+ protected Adapter adapterNotifyChanged = new AdapterImpl() {
+ @Override
+ public void notifyChanged(Notification msg) {
+ if (null != treeViewer) {
+ treeViewer.refresh();
+ }
+ };
+ };
+
+ /**
+ *
+ * Constructs a new ReferenceDialog in the given parent Composite. The style
+ * will be applied to the CLabel displaying the current value.
+ *
+ * @param parent
+ * The parent composite.
+ * @param style
+ * The style for the created widget.
+ */
+ public TreeReferenceValueEditor(final Composite parent, final int style) {
+ super(parent, style);
+
+ ((GridLayout) getLayout()).numColumns += 1;
+
+ // Create a parent composite to set the margin
+ final Composite gridComposite = factory.createComposite(this);
+ gridComposite.setLayout(new GridLayout());
+ gridComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ compositeTree = factory.createComposite(gridComposite);
+ final TreeColumnLayout treeColumnLayout = new TreeColumnLayout();
+ compositeTree.setLayout(treeColumnLayout);
+ final GridData compositeTreeGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ compositeTreeGridData.minimumHeight = 150;
+ compositeTree.setLayoutData(compositeTreeGridData);
+
+ treeViewer = new TreeViewer(compositeTree, SWT.MULTI | SWT.NO_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
+ tree = treeViewer.getTree();
+ tree.setLinesVisible(true);
+ tree.setHeaderVisible(true);
+
+ final TreeViewerColumn columnProperty = new TreeViewerColumn(treeViewer, SWT.LEFT);
+ columnProperty.getColumn().setAlignment(SWT.LEFT);
+ columnProperty.getColumn().setText("Property"); //$NON-NLS-1$
+ treeColumnLayout.setColumnData(columnProperty.getColumn(), new ColumnWeightData(100));
+ final TreeViewerColumn columnValue = new TreeViewerColumn(treeViewer, SWT.RIGHT);
+ columnValue.getColumn().setAlignment(SWT.LEFT);
+ columnValue.getColumn().setText("Value"); //$NON-NLS-1$
+ treeColumnLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(200));
+
+ columnValue.setEditingSupport(createEditingSupport());
+
+ treeViewer.setAutoExpandLevel(10);
+
+ createButtons();
+ }
+
+ /**
+ * Create the buttons.
+ */
+ protected void createButtons() {
+ ((GridLayout) getLayout()).numColumns += 2;
+
+ createInstanceButton = factory.createButton(this, null, SWT.PUSH);
+ createInstanceButton.setImage(Activator.getDefault().getImage("/icons/Add_12x12.gif")); //$NON-NLS-1$
+ createInstanceButton.setToolTipText(Messages.ReferenceDialog_CreateANewObject);
+ createInstanceButton.addSelectionListener(this);
+
+ unsetButton = factory.createButton(this, null, SWT.PUSH);
+ unsetButton.setImage(Activator.getDefault().getImage("/icons/Delete_12x12.gif")); //$NON-NLS-1$
+ unsetButton.setToolTipText(Messages.ReferenceDialog_UnsetValue);
+ unsetButton.addSelectionListener(this);
+ }
+
+ /**
+ * The action executed when the "create" button is selected Create a new
+ * instance and assign it to this reference.
+ */
+ protected void createAction() {
+ if (valueFactory != null && valueFactory.canCreateObject()) {
+ final Object context = getContextElement();
+ getOperationExecutor(context).execute(new Runnable() {
+
+ @Override
+ public void run() {
+ Object value = valueFactory.createObject(createInstanceButton, context);
+ if (null == value) {
+ // Cancel the operation
+ throw new OperationCanceledException();
+ }
+
+ Collection<Object> validatedObjects = valueFactory.validateObjects(Collections.singleton(value));
+ if (!validatedObjects.isEmpty()) {
+ setValue(validatedObjects.iterator().next());
+ }
+ }
+ }, NLS.bind(Messages.ReferenceDialog_setOperation, labelText));
+ }
+ }
+
+ /**
+ * The action executed when the "unset" button is selected Sets the current
+ * reference to null.
+ */
+ protected void unsetAction() {
+ setValue(null);
+ }
+
+ /**
+ * Sets the Label provider for this editor If the label provider is null, a
+ * default one will be used. The same label provider is used for both the
+ * editor's label and the selection dialog.
+ *
+ * @param provider
+ * The label provider
+ */
+ public void setLabelProvider(final ILabelProvider provider) {
+ if (null == provider) {
+ setLabelProvider(new LabelProvider());
+ return;
+ }
+ this.labelProvider = provider;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor#getValue()
+ */
+ @Override
+ public Object getValue() {
+ if (null != modelProperty) {
+ return modelProperty.getValue();
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#getEditableType()
+ */
+ @Override
+ public Object getEditableType() {
+ return Object.class;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor#setModelObservable(org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ public void setModelObservable(final IObservableValue modelProperty) {
+ if (null != modelProperty) {
+ this.value = modelProperty.getValue();
+ }
+ super.setModelObservable(modelProperty);
+ addEAdapters();
+ setWidgetObservable(createWidgetObservable(modelProperty));
+ }
+
+ /**
+ * This allows to set the Reference value factory.
+ *
+ * @param factory
+ * The reference value factory.
+ */
+ public void setValueFactory(final ReferenceValueFactory factory) {
+ this.valueFactory = factory;
+ }
+
+ /**
+ * Get the Reference value factory.
+ *
+ * @return The Reference value factory.
+ */
+ public ReferenceValueFactory getValueFactory() {
+ return valueFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ Widget widget = e.widget;
+ if (widget == createInstanceButton) {
+ createAction();
+ } else if (widget == unsetButton) {
+ unsetAction();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetDefaultSelected(final SelectionEvent e) {
+ // Do nothing
+ }
+
+
+ /**
+ * Set value of the modelProperty and create the widget observable.
+ *
+ * @param value
+ * The new value.
+ */
+ @SuppressWarnings("unchecked")
+ public void setValue(final Object value) {
+ removeEAdapters();
+ this.value = value;
+ if (null != modelProperty) {
+ modelProperty.setValue(value);
+ setWidgetObservable(createWidgetObservable(modelProperty));
+ addEAdapters();
+ }
+
+ if (null != treeViewer) {
+ IContentProvider treeViewerContentProvider = treeViewer.getContentProvider();
+ if (null != treeViewerContentProvider) {
+ setValueRootContentProvider();
+ treeViewer.setInput(""); // $NON-NLS-1$
+ }
+ }
+
+ commit();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#isReadOnly()
+ */
+ @Override
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#setReadOnly(boolean)
+ */
+ @Override
+ public void setReadOnly(final boolean readOnly) {
+ // Do Nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.swt.widgets.Widget#dispose()
+ */
+ @Override
+ public void dispose() {
+ removeEAdapters();
+ super.dispose();
+ }
+
+ /**
+ * Add the eAdapters to the current value.
+ */
+ private void addEAdapters() {
+ if (value instanceof EObject) {
+ ((EObject) value).eAdapters().add(adapterNotifyChanged);
+ }
+ }
+
+ /**
+ * Remove the eAdapters to the current value.
+ */
+ private void removeEAdapters() {
+ if (value instanceof EObject) {
+ ((EObject) value).eAdapters().remove(adapterNotifyChanged);
+ }
+ }
+
+ /**
+ * Set the value root to the content provider of the tree viewer.
+ */
+ public abstract void setValueRootContentProvider();
+
+ /**
+ * Set the providers of the TreeViewer.
+ */
+ public abstract void setProvidersTreeViewer();
+
+ /**
+ * Create the Editing Support.
+ *
+ * @return The EditingSupport created.
+ */
+ public abstract EditingSupport createEditingSupport();
+
+ /**
+ * This allow to create the widget observable value.
+ *
+ * @param modelProperty
+ * The current observable value.
+ * @return The created IObservableValue.
+ */
+ @SuppressWarnings("rawtypes")
+ public abstract IObservableValue createWidgetObservable(final IObservableValue modelProperty);
+
+}

Back to the top