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
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>
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml3
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/GeneratorProfileDataType.java350
-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
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath6
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF3
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml4
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java97
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java531
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java140
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java155
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/StereotypeModelElement.java30
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/GenericDataTypeLabelProvider.java266
23 files changed, 2653 insertions, 359 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml
index b7c28aa7e11..79fa9226086 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/plugin.xml
@@ -38,6 +38,9 @@
<generator
generator="org.eclipse.papyrus.customization.properties.generation.layout.ProfileWithDatatypes">
</generator>
+ <generator
+ generator="org.eclipse.papyrus.customization.properties.generation.layout.GeneratorProfileDataType">
+ </generator>
</extension>
<extension point="org.eclipse.m2m.qvt.oml.runtime.qvtTransformation">
<library
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/GeneratorProfileDataType.java b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/GeneratorProfileDataType.java
new file mode 100644
index 00000000000..bac11eb282b
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.generation/src/org/eclipse/papyrus/customization/properties/generation/layout/GeneratorProfileDataType.java
@@ -0,0 +1,350 @@
+/*****************************************************************************
+ * 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.customization.properties.generation.layout;
+
+import java.util.List;
+
+import org.eclipse.papyrus.customization.properties.generation.Activator;
+import org.eclipse.papyrus.customization.properties.generation.generators.IGenerator;
+import org.eclipse.papyrus.customization.properties.generation.generators.ProfileGenerator;
+import org.eclipse.papyrus.infra.properties.contexts.Context;
+import org.eclipse.papyrus.infra.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.infra.properties.contexts.DataContextPackage;
+import org.eclipse.papyrus.infra.properties.contexts.DataContextRoot;
+import org.eclipse.papyrus.infra.properties.contexts.Property;
+import org.eclipse.papyrus.infra.properties.contexts.View;
+import org.eclipse.papyrus.infra.properties.environment.CompositeWidgetType;
+import org.eclipse.papyrus.infra.properties.environment.Environment;
+import org.eclipse.papyrus.infra.properties.environment.LayoutType;
+import org.eclipse.papyrus.infra.properties.environment.PropertyEditorType;
+import org.eclipse.papyrus.infra.properties.environment.Type;
+import org.eclipse.papyrus.infra.properties.ui.CompositeWidget;
+import org.eclipse.papyrus.infra.properties.ui.Layout;
+import org.eclipse.papyrus.infra.properties.ui.PropertyEditor;
+import org.eclipse.papyrus.infra.properties.ui.UiFactory;
+import org.eclipse.papyrus.infra.properties.ui.ValueAttribute;
+import org.eclipse.papyrus.infra.properties.ui.runtime.PropertiesRuntime;
+import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ * Generator for Profile which contained DataTypes.
+ */
+public class GeneratorProfileDataType extends StandardLayoutGenerator {
+
+ /**
+ * The managed generator.
+ */
+ protected IGenerator generator;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator#sortEditors(java.util.List)
+ */
+ @Override
+ protected void sortEditors(final List<PropertyEditor> editors) {
+ for (PropertyEditor editor : editors) {
+ Category category = new TypeCategory(editor.getProperty());
+ getByCategory(category).add(editor);
+
+ if (editor.getWidgetType() == null) {
+ Activator.log.warn(String.format("Editor for property %s doesn't have a WidgetType", editor.getProperty().getName())); //$NON-NLS-1$
+ continue;
+ }
+
+ namespaces.add(editor.getWidgetType().getNamespace());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator#layoutCategorizedEditors(org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator.Category, java.util.List)
+ */
+ @Override
+ protected CompositeWidget layoutCategorizedEditors(final Category category, final List<PropertyEditor> editors) {
+ if (((TypeCategory) category).isDatatype) {
+ CompositeWidgetType compositeType = PropertiesRuntime.getConfigurationManager().getDefaultCompositeType();
+
+ CompositeWidget container = UiFactory.eINSTANCE.createCompositeWidget();
+ container.setWidgetType(compositeType);
+
+ Layout layout = createLayout(category.getNumColumns());
+ container.setLayout(layout);
+
+ for (PropertyEditor editor : editors) {
+ PropertyEditor viewEditor = UiFactory.eINSTANCE.createPropertyEditor();
+ viewEditor.setWidgetType(getViewEditor());
+ viewEditor.setProperty(editor.getProperty());
+
+ ValueAttribute view = UiFactory.eINSTANCE.createValueAttribute();
+ view.setName("view"); //$NON-NLS-1$
+ view.setValue(getViewName(editor.getProperty()));
+ viewEditor.getAttributes().add(view);
+
+ container.getWidgets().add(viewEditor);
+ }
+
+ return container;
+ }
+
+ return super.layoutCategorizedEditors(category, editors);
+ }
+
+ /**
+ * Get the view name.
+ *
+ * @param property
+ * The context property to manage.
+ * @return The string corresponding to the property.
+ */
+ protected String getViewName(final Property property) {
+ if (!(generator instanceof ProfileGenerator)) {
+ return ""; //$NON-NLS-1$
+ }
+
+ org.eclipse.uml2.uml.Property attribute = ((ProfileGenerator) generator).getAttribute(property);
+
+ Package nearestPackage = attribute.getType().getNearestPackage();
+ Package rootPackage = nearestPackage;
+ while (rootPackage.getNestingPackage() != null) {
+ rootPackage = rootPackage.getNestingPackage();
+ }
+
+ // TODO : We're assuming the rootPackage has the same name as the context...
+ // This layout generator is really only compatible with ProfileGenerator
+ return rootPackage.getName() + ":Single " + attribute.getType().getName(); //$NON-NLS-1$
+ }
+
+ /**
+ * This allows to find the context property.
+ *
+ * @param property
+ * The context property.
+ * @return the context.
+ */
+ protected Context findContext(final Property property) {
+ DataContextElement element = property.getContextElement();
+ if (element instanceof DataContextRoot) {
+ // TODO : Add a container reference to Context
+ return (Context) element.eContainer();
+ }
+
+ return findContext(element);
+ }
+
+ /**
+ * Find the context from the data context element.
+ *
+ * @param element
+ * The data context element.
+ * @return The needed context.
+ */
+ protected Context findContext(final DataContextElement element) {
+ DataContextPackage dataContextPackage = element.getPackage();
+ if (dataContextPackage instanceof DataContextRoot) {
+ return (Context) dataContextPackage.eContainer();
+ }
+ return findContext(dataContextPackage);
+ }
+
+ /**
+ * Get the qualified name of the view.
+ *
+ * @param view
+ * The view.
+ * @return The qualified name of the view.
+ */
+ protected String getQualifiedName(final View view) {
+ return view.getContext().getName() + ":" + view.getName(); //$NON-NLS-1$
+ }
+
+ /**
+ * This allows to create the correct layout.
+ *
+ * @param columns
+ * the number of columns needed.
+ * @return The created layout.
+ */
+ protected Layout createLayout(final Integer columns) {
+ LayoutType propertiesLayoutType = PropertiesRuntime.getConfigurationManager().getDefaultLayoutType();
+
+ Layout layout = UiFactory.eINSTANCE.createLayout();
+ ValueAttribute numColumns = UiFactory.eINSTANCE.createValueAttribute();
+ numColumns.setName("numColumns"); //$NON-NLS-1$
+ numColumns.setValue(columns.toString());
+
+ layout.getAttributes().add(numColumns);
+ layout.setLayoutType(propertiesLayoutType);
+
+ return layout;
+ }
+
+ /**
+ * Get the view editor.
+ *
+ * @return The view editor.
+ */
+ protected PropertyEditorType getViewEditor() {
+ for (Environment environment : ConfigurationManager.getInstance().getPropertiesRoot().getEnvironments()) {
+ for (PropertyEditorType widgetType : environment.getPropertyEditorTypes()) {
+ if (widgetType.getNamespace() != null && "ppe".equals(widgetType.getNamespace().getName()) && widgetType.getWidgetClass().equals("DataTypeEditor")) {
+ return widgetType;
+ }
+ }
+ }
+
+ return PropertiesRuntime.getConfigurationManager().getDefaultEditorType(Type.STRING, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator#setGenerator(org.eclipse.papyrus.customization.properties.generation.generators.IGenerator)
+ */
+ @Override
+ public void setGenerator(IGenerator generator) {
+ this.generator = generator;
+ }
+
+ /**
+ * The type category.
+ */
+ protected class TypeCategory extends Category {
+
+ /**
+ * Boolean to determinate if this is a data type.
+ */
+ protected boolean isDatatype;
+
+ /**
+ * Constructor.
+ *
+ * @param property
+ * The context property to manage.
+ */
+ public TypeCategory(final Property property) {
+ super(property);
+ org.eclipse.uml2.uml.Property attribute = resolveProperty(property);
+ if (attribute != null && attribute.getType() != null) {
+ isDatatype = attribute.getType().eClass() == UMLPackage.eINSTANCE.getDataType();
+ }
+ }
+
+ /**
+ * Resolve the context property to UML property.
+ *
+ * @param property
+ * The context property.
+ * @return The UML property corresponding.
+ */
+ protected org.eclipse.uml2.uml.Property resolveProperty(final Property property) {
+ // TODO : We should not have to rely on the IGenerator to retrieve the property...
+ if (generator instanceof ProfileGenerator) {
+ ProfileGenerator profileGenerator = (ProfileGenerator) generator;
+ return profileGenerator.getAttribute(property);
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator.Category#getNumColumns()
+ */
+ @Override
+ public Integer getNumColumns() {
+ if (isDatatype) {
+ return 1;
+ }
+ return super.getNumColumns();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator.Category#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + (isDatatype ? 1231 : 1237);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator.Category#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof TypeCategory)) {
+ return false;
+ }
+ TypeCategory other = (TypeCategory) obj;
+ if (!getOuterType().equals(other.getOuterType())) {
+ return false;
+ }
+ if (isDatatype != other.isDatatype) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator.Category#getTypeIndex()
+ */
+ @Override
+ public Integer getTypeIndex() {
+ if (isDatatype) {
+ return orderedTypes.length + 1;
+ }
+ return super.getTypeIndex();
+ }
+
+ /**
+ * Return the outer type.
+ *
+ * @return The outer type.
+ */
+ private GeneratorProfileDataType getOuterType() {
+ return GeneratorProfileDataType.this;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.customization.properties.generation.layout.StandardLayoutGenerator#getName()
+ */
+ @Override
+ public String getName() {
+ return "Generator for Profile with DataTypes"; //$NON-NLS-1$
+ }
+
+}
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);
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath
index d0eeb4a7de0..eca7bdba8f0 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="output" path="bin"/>
<classpathentry kind="src" path="src"/>
-</classpath> \ No newline at end of file
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs
index 94d61f00da6..b3aa6d60f94 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs
@@ -1,10 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF
index 8d9d57aee06..645352bee60 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF
@@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.papyrus.uml.tools;bundle-version="[3.0.0,4.0.0)";vis
org.eclipse.papyrus.infra.emf.nattable;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.papyrus.uml.tools.utils;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)"
+ org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.papyrus.infra.properties.ui;bundle-version="[2.0.0,3.0.0)"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
Bundle-Version: 3.0.0.qualifier
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml
index 0ffb58f6eca..bbaaf95c6e0 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml
@@ -135,6 +135,10 @@
class="org.eclipse.papyrus.uml.nattable.config.MultiStringCellEditorConfiguration"
order="1031">
</cellAxisConfiguration>
+ <cellAxisConfiguration
+ class="org.eclipse.papyrus.uml.nattable.config.UMLStereotypeSingleDataTypeCellEditorConfiguration"
+ order="2">
+ </cellAxisConfiguration>
</extension>
<extension
point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider">
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java
new file mode 100644
index 00000000000..b6ed8d7c7ef
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 502533
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.config;
+
+import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
+import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
+import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
+import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
+import org.eclipse.papyrus.uml.nattable.editor.DatatypeDialogCellEditor;
+import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * The cell editor for UML Datatype declared in the profile.
+ */
+public class UMLStereotypeSingleDataTypeCellEditorConfiguration implements ICellAxisConfiguration {
+
+ /**
+ * The identifier.
+ */
+ public static final String ID = "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleDataTypeCellEditorConfiguration.dialog"; // $NON-NLS-0$
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.configuration.IPapyrusNatTableConfiguration#getConfigurationId()
+ */
+ @Override
+ public String getConfigurationId() {
+ return ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.configuration.IPapyrusNatTableConfiguration#getConfigurationDescription()
+ */
+ public String getConfigurationDescription() {
+ return "This configuration provides a dialog to edit UML datatype"; //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration#handles(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object)
+ */
+ @Override
+ public boolean handles(final Table table, final Object axisElement) {
+ boolean result = false;
+ final String id = AxisUtils.getPropertyId(axisElement);
+ if (id != null && id.startsWith(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX)) {
+ final Property prop = UMLTableUtils.getRealStereotypeProperty(table.getContext(), id);
+ final Type type = prop.getType();
+ // TODO: Need to manage multi-valued datatype (it maybe must be the same cell editor)
+ if (null != prop && !prop.isMultivalued()) {
+ result = type instanceof DataType && !(type instanceof Enumeration) && !(type instanceof PrimitiveType);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration#configureCellEditor(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry, java.lang.Object, java.lang.String)
+ */
+ @Override
+ public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) {
+ configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.EDIT, configLabel);
+
+ final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
+ configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DatatypeDialogCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel);
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java
index a4208ba1f48..bfbd6cb553c 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java
@@ -1,260 +1,271 @@
-/*****************************************************************************
- * Copyright (c) 2013, 2014 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 402525
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.nattable.editor;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.nebula.widgets.nattable.NatTable;
-import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
-import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
-import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
-import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
-import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
-import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectionDialog;
-import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
-import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
-import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-
-/**
- *
- * Abstract Cell Editor for MultiValued properties
- *
- * @author Vincent Lorenzo
- *
- */
-public abstract class AbstractUMLMultiValueCellEditor extends AbstractDialogCellEditor {
-
- private Collection<Object> returnedValue;
-
- /**
- * the table axis element provider
- */
- protected ITableAxisElementProvider manager;
-
- /**
- * the axis element
- */
- private Object axisElement;
-
- /**
- *
- * Constructor.
- *
- * @param axisElement
- * the axis element
- * @param elementProvider
- * the table axis element provider
- */
- protected AbstractUMLMultiValueCellEditor(final Object axisElement, final ITableAxisElementProvider elementProvider) {
- this.manager = elementProvider;
- this.axisElement = axisElement;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#open()
- *
- * @return
- */
- @Override
- public int open() {
- int result = ((MultipleValueSelectionDialog) this.dialog).open();
- if (manager instanceof IAdaptable) {
- NatTable nattable = (NatTable) ((IAdaptable) manager).getAdapter(NatTable.class);
- if (nattable != null && !nattable.isDisposed()) {
- nattable.forceFocus();
- }
- }
- return result;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#createDialogInstance()
- *
- * @return
- */
- @Override
- public Object createDialogInstance() {
- int columnIndex = this.layerCell.getColumnIndex();
- int rowIndex = this.layerCell.getRowIndex();
- Object row = this.manager.getRowElement(rowIndex);
- Object column = this.manager.getColumnElement(columnIndex);
- row = AxisUtils.getRepresentedElement(row);
- column = AxisUtils.getRepresentedElement(column);
- Element editedElement = null;
- Object feature = null;
- if (row instanceof EObject && column == this.axisElement) {
- editedElement = (Element) row;
- feature = column;
- } else {
- editedElement = (Element) column;
- feature = row;
- }
-
- EStructuralFeature realFeature = null;
- EObject realEditedObject = null;
- Stereotype stereotype = null;
- List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null;
- if (feature instanceof EStructuralFeature) {
- realFeature = (EStructuralFeature) feature;
- realEditedObject = editedElement;
- } else {
- final String id = AxisUtils.getPropertyId(this.axisElement);
- stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id);
- stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0);
- realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0));
- Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id);
- realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName());
- }
- if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) {
- // TODO : not yet managed
- } else {
- this.dialog = createDialog(realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet());
- }
- return this.dialog;
- }
-
- /**
- *
- * @param realEditedObject
- * the real edited object : the stereotype application or the edited Element
- * @param realFeature
- * the real edited feature : the feature of the stereotype application or the the feature of the edited Element
- * @param stereotype
- * the stereotype if we are are editing a stereotype application
- * @param resourceSet
- * the resourceset
- * @return
- * the dialog to edit the property
- */
- protected Object createDialog(EObject realEditedObject, EStructuralFeature realFeature, Stereotype stereotype, ResourceSet resourceSet) {
- final UMLContentProvider p = new UMLContentProvider(realEditedObject, realFeature, stereotype, resourceSet);
- final String title = realFeature.getName();
- final boolean unique = realFeature.isUnique();
- final boolean ordered = realFeature.isOrdered();
- final int upperBound = realFeature.getUpperBound();
- final Object value = realEditedObject.eGet(realFeature);
- IElementSelector selector = getElementSelector(unique, new UMLLabelProvider(), p);
- final MultipleValueSelectionDialog dialog = new MultipleValueSelectionDialog(Display.getCurrent().getActiveShell(), selector, title, unique, ordered, upperBound) {
-
- @Override
- protected void okPressed() {
- super.okPressed();
- Collection<Object> newValue = new ArrayList<Object>();
- Object[] result = this.getResult();
- for (Object object : result) {
- newValue.add(object);
-
- }
- AbstractUMLMultiValueCellEditor.this.returnedValue = newValue;
- AbstractUMLMultiValueCellEditor.this.editHandler.commit(newValue, MoveDirectionEnum.NONE);
- }
-
- };
- dialog.setContextElement(realEditedObject);
- dialog.setLabelProvider(new UMLLabelProvider());
- if (value != null && value instanceof Collection) {
- Collection<?> coll = (Collection<?>) value;
- if (!coll.isEmpty()) {
- dialog.setInitialSelections(coll.toArray());
- }
- }
-
- ReferenceValueFactory factory = getFactory();
- if (factory != null) {
- dialog.setFactory(factory);
- }
-
- return dialog;
- }
-
- /**
- *
- * @return
- * the reference factory used to create to element
- */
- protected abstract ReferenceValueFactory getFactory();
-
- /**
- *
- * @param isUnique
- * @param labelProvider
- * @param contentProvider
- * @return
- * the element selector to use in the dialog
- */
- protected abstract IElementSelector getElementSelector(final boolean isUnique, final ILabelProvider labelProvider, final IStaticContentProvider contentProvider);
-
- @Override
- public Object getDialogInstance() {
- return this.dialog;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#getEditorValue()
- *
- * @return
- */
- @Override
- public Object getEditorValue() {
- return this.returnedValue;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#setEditorValue(java.lang.Object)
- *
- * @param value
- */
- @Override
- public void setEditorValue(Object value) {
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#close()
- *
- */
- @Override
- public void close() {
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#isClosed()
- *
- * @return
- */
- @Override
- public boolean isClosed() {
- return false;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2014 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.nattable.editor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
+import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
+import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
+import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectionDialog;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
+import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider;
+import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ *
+ * Abstract Cell Editor for MultiValued properties
+ *
+ * @author Vincent Lorenzo
+ *
+ */
+public abstract class AbstractUMLMultiValueCellEditor extends AbstractDialogCellEditor {
+
+ private Collection<Object> returnedValue;
+
+ /**
+ * the table axis element provider
+ */
+ protected ITableAxisElementProvider manager;
+
+ /**
+ * the axis element
+ */
+ private Object axisElement;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param axisElement
+ * the axis element
+ * @param elementProvider
+ * the table axis element provider
+ */
+ protected AbstractUMLMultiValueCellEditor(final Object axisElement, final ITableAxisElementProvider elementProvider) {
+ this.manager = elementProvider;
+ this.axisElement = axisElement;
+ }
+
+ /**
+ * Getter axisElement
+ *
+ * @return the axisElement
+ * @since 3.0
+ */
+ public Object getAxisElement() {
+ return axisElement;
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#open()
+ *
+ * @return
+ */
+ @Override
+ public int open() {
+ int result = ((Dialog) this.dialog).open();
+ if (manager instanceof IAdaptable) {
+ NatTable nattable = (NatTable) ((IAdaptable) manager).getAdapter(NatTable.class);
+ if (nattable != null && !nattable.isDisposed()) {
+ nattable.forceFocus();
+ }
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#createDialogInstance()
+ *
+ * @return
+ */
+ @Override
+ public Object createDialogInstance() {
+ int columnIndex = this.layerCell.getColumnIndex();
+ int rowIndex = this.layerCell.getRowIndex();
+ Object row = this.manager.getRowElement(rowIndex);
+ Object column = this.manager.getColumnElement(columnIndex);
+ row = AxisUtils.getRepresentedElement(row);
+ column = AxisUtils.getRepresentedElement(column);
+ Element editedElement = null;
+ Object feature = null;
+ if (row instanceof EObject && column == this.axisElement) {
+ editedElement = (Element) row;
+ feature = column;
+ } else {
+ editedElement = (Element) column;
+ feature = row;
+ }
+
+ EStructuralFeature realFeature = null;
+ EObject realEditedObject = null;
+ Stereotype stereotype = null;
+ List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null;
+ if (feature instanceof EStructuralFeature) {
+ realFeature = (EStructuralFeature) feature;
+ realEditedObject = editedElement;
+ } else {
+ final String id = AxisUtils.getPropertyId(this.axisElement);
+ stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id);
+ stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0);
+ realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0));
+ Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id);
+ realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName());
+ }
+ if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) {
+ // TODO : not yet managed
+ } else {
+ this.dialog = createDialog(realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet());
+ }
+ return this.dialog;
+ }
+
+ /**
+ *
+ * @param realEditedObject
+ * the real edited object : the stereotype application or the edited Element
+ * @param realFeature
+ * the real edited feature : the feature of the stereotype application or the the feature of the edited Element
+ * @param stereotype
+ * the stereotype if we are are editing a stereotype application
+ * @param resourceSet
+ * the resourceset
+ * @return
+ * the dialog to edit the property
+ */
+ protected Object createDialog(EObject realEditedObject, EStructuralFeature realFeature, Stereotype stereotype, ResourceSet resourceSet) {
+ final UMLContentProvider p = new UMLContentProvider(realEditedObject, realFeature, stereotype, resourceSet);
+ final String title = realFeature.getName();
+ final boolean unique = realFeature.isUnique();
+ final boolean ordered = realFeature.isOrdered();
+ final int upperBound = realFeature.getUpperBound();
+ final Object value = realEditedObject.eGet(realFeature);
+ IElementSelector selector = getElementSelector(unique, new UMLLabelProvider(), p);
+ final MultipleValueSelectionDialog dialog = new MultipleValueSelectionDialog(Display.getCurrent().getActiveShell(), selector, title, unique, ordered, upperBound) {
+
+ @Override
+ protected void okPressed() {
+ super.okPressed();
+ Collection<Object> newValue = new ArrayList<Object>();
+ Object[] result = this.getResult();
+ for (Object object : result) {
+ newValue.add(object);
+
+ }
+ AbstractUMLMultiValueCellEditor.this.returnedValue = newValue;
+ AbstractUMLMultiValueCellEditor.this.editHandler.commit(newValue, MoveDirectionEnum.NONE);
+ }
+
+ };
+ dialog.setContextElement(realEditedObject);
+ dialog.setLabelProvider(new UMLLabelProvider());
+ if (value != null && value instanceof Collection) {
+ Collection<?> coll = (Collection<?>) value;
+ if (!coll.isEmpty()) {
+ dialog.setInitialSelections(coll.toArray());
+ }
+ }
+
+ ReferenceValueFactory factory = getFactory();
+ if (factory != null) {
+ dialog.setFactory(factory);
+ }
+
+ return dialog;
+ }
+
+ /**
+ *
+ * @return
+ * the reference factory used to create to element
+ */
+ protected abstract ReferenceValueFactory getFactory();
+
+ /**
+ *
+ * @param isUnique
+ * @param labelProvider
+ * @param contentProvider
+ * @return
+ * the element selector to use in the dialog
+ */
+ protected abstract IElementSelector getElementSelector(final boolean isUnique, final ILabelProvider labelProvider, final IStaticContentProvider contentProvider);
+
+ @Override
+ public Object getDialogInstance() {
+ return this.dialog;
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#getEditorValue()
+ *
+ * @return
+ */
+ @Override
+ public Object getEditorValue() {
+ return this.returnedValue;
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#setEditorValue(java.lang.Object)
+ *
+ * @param value
+ */
+ @Override
+ public void setEditorValue(Object value) {
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#close()
+ *
+ */
+ @Override
+ public void close() {
+ }
+
+ /**
+ *
+ * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#isClosed()
+ *
+ * @return
+ */
+ @Override
+ public boolean isClosed() {
+ return false;
+ }
+
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java
new file mode 100644
index 00000000000..ab11c3726cf
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java
@@ -0,0 +1,140 @@
+/*****************************************************************************
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.nattable.editor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
+import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The cell editor for the DataType with a dialog.
+ */
+public class DatatypeDialogCellEditor extends AbstractUMLMultiValueCellEditor {
+
+ /**
+ * Constructor.
+ *
+ * @param axisElement
+ * The axis element.
+ * @param provider
+ * The table axis element provider.
+ */
+ public DatatypeDialogCellEditor(final Object axisElement, final ITableAxisElementProvider provider) {
+ super(axisElement, provider);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#createDialogInstance()
+ */
+ @Override
+ public Object createDialogInstance() {
+ int columnIndex = this.layerCell.getColumnIndex();
+ int rowIndex = this.layerCell.getRowIndex();
+ Object row = this.manager.getRowElement(rowIndex);
+ Object column = this.manager.getColumnElement(columnIndex);
+ row = AxisUtils.getRepresentedElement(row);
+ column = AxisUtils.getRepresentedElement(column);
+ Element editedElement = null;
+ Object feature = null;
+ if (row instanceof EObject && column == getAxisElement()) {
+ editedElement = (Element) row;
+ feature = column;
+ } else {
+ editedElement = (Element) column;
+ feature = row;
+ }
+
+ EStructuralFeature realFeature = null;
+ EObject realEditedObject = null;
+ Stereotype stereotype = null;
+ List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null;
+ if (feature instanceof EStructuralFeature) {
+ realFeature = (EStructuralFeature) feature;
+ realEditedObject = editedElement;
+ } else {
+ final String id = AxisUtils.getPropertyId(getAxisElement());
+ stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id);
+ stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0);
+ realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0));
+ Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id);
+ realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName());
+ }
+ if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) {
+ // TODO : not yet managed
+ } else {
+ this.dialog = createDialog(realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet());
+ }
+ return this.dialog;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#getFactory()
+ */
+ @Override
+ protected ReferenceValueFactory getFactory() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#getElementSelector(boolean, org.eclipse.jface.viewers.ILabelProvider, org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider)
+ */
+ @Override
+ protected IElementSelector getElementSelector(final boolean isUnique, final ILabelProvider labelProvider, final IStaticContentProvider contentProvider) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#createDialog(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, org.eclipse.uml2.uml.Stereotype, org.eclipse.emf.ecore.resource.ResourceSet)
+ */
+ @Override
+ protected Object createDialog(final EObject realEditedObject, final EStructuralFeature realFeature, final Stereotype stereotype, final ResourceSet resourceSet) {
+ return new EObjectTreeDialog(Display.getDefault().getActiveShell(), realEditedObject, realFeature, "DataType Edition") { // $NON-NLS-1$
+ @Override
+ protected void okPressed() {
+ super.okPressed();
+ Collection<Object> newValue = new ArrayList<Object>();
+ Object[] result = this.getResult();
+ for (Object object : result) {
+ newValue.add(object);
+
+ }
+ DatatypeDialogCellEditor.this.editHandler.commit(newValue, MoveDirectionEnum.NONE);
+ }
+ };
+ }
+}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java
new file mode 100644
index 00000000000..ae4b9f2e7fc
--- /dev/null
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java
@@ -0,0 +1,155 @@
+/*****************************************************************************
+ * 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.uml.nattable.editor;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.properties.ui.modelelement.EObjectStructuredValueFactory;
+import org.eclipse.papyrus.infra.services.edit.ui.databinding.PapyrusObservableValue;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
+import org.eclipse.papyrus.infra.tools.databinding.DelegatingObservable;
+import org.eclipse.papyrus.infra.ui.emf.dialog.EObjectTreeReferenceValueEditor;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+/**
+ * Dialog to display a EObjectTreeReferenceValueEditor
+ */
+public class EObjectTreeDialog extends SelectionDialog {
+
+ /**
+ * EObject to edit.
+ */
+ protected EObject editedObject;
+
+ /**
+ * Feature of the EObject to edit.
+ */
+ protected EStructuralFeature feature;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * The parent shell.
+ * @param editedObject
+ * The object to edit.
+ * @param feature
+ * The structural feature.
+ */
+ public EObjectTreeDialog(Shell parentShell, EObject editedObject, EStructuralFeature feature, String title) {
+ super(parentShell);
+ setTitle(title);
+ setHelpAvailable(false);
+ this.editedObject = editedObject;
+ this.feature = feature;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+ EObjectTreeReferenceValueEditor treeReferenceValueEditor = new EObjectTreeReferenceValueEditor(container, SWT.NONE);
+
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(editedObject);
+
+ PapyrusObservableValue papyrusObservableValue = new PapyrusObservableValue(editedObject, feature, editingDomain, GMFtoEMFCommandWrapper::wrap);
+
+ IObservableValue wrap = (IObservableValue) DelegatingObservable.wrap(papyrusObservableValue);
+
+ treeReferenceValueEditor.setModelObservable(wrap);
+ treeReferenceValueEditor.setLabelProvider(getLabelProviderForEObject(editedObject));
+ treeReferenceValueEditor.setProvidersTreeViewer();
+
+ if (feature instanceof EReference) {
+ treeReferenceValueEditor.setValueFactory(new EObjectStructuredValueFactory((EReference) feature));
+ }
+
+ treeReferenceValueEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ return container;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ui.dialogs.SelectionDialog#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ @Override
+ protected void configureShell(final Shell shell) {
+ super.configureShell(shell);
+ shell.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(800, 600);
+ }
+
+ /**
+ * Returns the ILabelProvider for an EObject.
+ *
+ * @param eObject
+ * The object which one search the label provider.
+ * @return The ILabelProvider for an EObject.
+ */
+ private ILabelProvider getLabelProviderForEObject(final EObject eObject) {
+ LabelProviderService labelProviderService = new LabelProviderServiceImpl();
+ try {
+ labelProviderService.startService();
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+
+ return labelProviderService.getLabelProvider(eObject);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ui.dialogs.SelectionDialog#getResult()
+ */
+ @Override
+ public Object[] getResult() {
+ // Return the editedObject for the result
+ Object[] objects = new Object[1];
+ objects[0] = editedObject;
+ return objects;
+ }
+}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/StereotypeModelElement.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/StereotypeModelElement.java
index 5deb71a4c50..56489cfa25c 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/StereotypeModelElement.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/StereotypeModelElement.java
@@ -9,8 +9,10 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - bug 453445
- *
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 502533
+ *
*****************************************************************************/
+
package org.eclipse.papyrus.uml.properties.modelelement;
import org.eclipse.core.databinding.observable.IObservable;
@@ -25,6 +27,8 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement;
+import org.eclipse.papyrus.infra.properties.ui.modelelement.EObjectStructuredValueFactory;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.uml.properties.Activator;
import org.eclipse.papyrus.uml.properties.datatype.DataTypeProvider;
@@ -32,6 +36,7 @@ import org.eclipse.papyrus.uml.properties.datatype.StructuredDataTypeObservableV
import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList;
import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue;
import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider;
+import org.eclipse.papyrus.uml.tools.utils.DataTypeUtil;
import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Stereotype;
@@ -141,4 +146,27 @@ public class StereotypeModelElement extends EMFModelElement {
return new UMLContentProvider(source, feature, stereotype);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement#getValueFactory(java.lang.String)
+ */
+ @Override
+ public ReferenceValueFactory getValueFactory(final String propertyPath) {
+ EStructuralFeature feature = getFeature(propertyPath);
+ if (feature != null) {
+ if (feature instanceof EReference) {
+ EReference reference = (EReference) feature;
+ if (reference.isContainment()) {
+ EClassifier featureType = feature.getEType();
+ if (featureType instanceof EClass && DataTypeUtil.isDataTypeDefinition((EClass) featureType, getSource())) {
+ return new EObjectStructuredValueFactory(reference);
+ }
+ }
+ }
+ }
+
+ return super.getValueFactory(propertyPath);
+ }
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/GenericDataTypeLabelProvider.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/GenericDataTypeLabelProvider.java
index 47614472d00..b431cdcf1b2 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/GenericDataTypeLabelProvider.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/GenericDataTypeLabelProvider.java
@@ -1,90 +1,176 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.providers;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
-import org.eclipse.papyrus.infra.ui.emf.providers.EMFLabelProvider;
-import org.eclipse.papyrus.uml.tools.utils.DataTypeUtil;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * A generic Label Provider for EObjects which are instances of UML DataTypes (Defined as EClasses)
- *
- * @author Camille Letavernier
- *
- * @see {@link DataTypeUtil#isDataTypeDefinition(EClass)}
- */
-public class GenericDataTypeLabelProvider extends EMFLabelProvider implements IFilteredLabelProvider {
-
- /**
- * {@inheritDoc}
- */
- public boolean accept(Object element) {
- if (element instanceof Collection<?>) {
- for (Object item : ((Collection<?>) element)) {
- if (!accept(item)) {
- return false;
- }
- }
- return !((Collection<?>) element).isEmpty();
- }
-
- EObject eObject = EMFHelper.getEObject(element);
- if (eObject == null) {
- return false;
- }
-
- return DataTypeUtil.isDataTypeInstance(eObject);
- }
-
- @Override
- public String getText(Object element) {
- // Initial implementation. TODO: Improve the label
- if (element instanceof Collection<?> && !(((Collection<?>) element).isEmpty())) {
- Set<EClass> allEClasses = new HashSet<EClass>();
- for (Object item : (Collection<?>) element) {
- EObject eObject = EMFHelper.getEObject(item);
- if (eObject != null) {
- allEClasses.add(eObject.eClass());
- }
- }
-
- if (allEClasses.size() == 1) {
- return "Multiple " + allEClasses.iterator().next().getName() + ": " + ((Collection<?>) element).size();
- }
- return "Multiple DataTypeInstances: " + ((Collection<?>) element).size();
- } else {
- EObject dataTypeInstance = EMFHelper.getEObject(element);
- if (dataTypeInstance != null) {
- EClass dataTypeDefinition = dataTypeInstance.eClass();
- if (dataTypeDefinition != null) {
- return dataTypeDefinition.getName();
- }
- }
- }
- return "Generic DataTypeInstance";
- }
-
- @Override
- public Image getImage(Object element) {
- return null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - bug 405442
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.providers;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.tools.Activator;
+import org.eclipse.papyrus.infra.ui.emf.providers.EMFLabelProvider;
+import org.eclipse.papyrus.uml.tools.utils.DataTypeUtil;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * A generic Label Provider for EObjects which are instances of UML DataTypes (Defined as EClasses)
+ *
+ * @author Camille Letavernier
+ *
+ * @see {@link DataTypeUtil#isDataTypeDefinition(EClass)}
+ */
+public class GenericDataTypeLabelProvider extends EMFLabelProvider implements IFilteredLabelProvider {
+
+ public static final String SEPARATOR = ","; //$NON-NLS-1$
+ public static final String DATATYPE_START = "("; //$NON-NLS-1$
+ public static final String DATATYPE_END = ")"; //$NON-NLS-1$
+ public static final String COLLECTION_START = "{"; //$NON-NLS-1$
+ public static final String COLLECTION_END = "}"; //$NON-NLS-1$
+ public static final String EQUALS = "="; //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean accept(Object element) {
+ if (element instanceof Collection<?>) {
+ for (Object item : ((Collection<?>) element)) {
+ if (!accept(item)) {
+ return false;
+ }
+ }
+ return !((Collection<?>) element).isEmpty();
+ }
+
+ EObject eObject = EMFHelper.getEObject(element);
+ if (eObject == null) {
+ return false;
+ }
+
+ return DataTypeUtil.isDataTypeInstance(eObject);
+ }
+
+ @Override
+ public String getText(Object element) {
+ // now we use the Marte VSL syntax : (propertyName=propertyValue, an otherProperty=value, (propertyFromAReferencedDataType=value) )
+ LabelProviderService serv = null;
+ if (element instanceof Collection<?> && !((Collection<?>) element).isEmpty()) {
+ final Object first = ((Collection<?>) element).iterator().next();
+ if (first instanceof EObject) {// always true due to the accept method
+ serv = getLabelProviderService((EObject) first);
+ }
+ } else {
+ // always true due to the accept method
+ serv = getLabelProviderService((EObject) element);
+ }
+ if (null == serv) {
+ Activator.log.error("LabelProviderService not found for " + element, null); //$NON-NLS-1$
+ }
+
+ // Initial implementation. TODO: Improve the label
+ final StringBuilder builder = new StringBuilder(DATATYPE_START);
+ if (element instanceof Collection<?> && !(((Collection<?>) element).isEmpty())) {
+ builder.append(getLabel(serv, element)); // collection management is delegated to this method
+ } else {
+ final EObject dataTypeInstance = EMFHelper.getEObject(element);
+ if (dataTypeInstance != null) {
+ final EClass dataTypeDefinition = dataTypeInstance.eClass();
+ final Iterator<EStructuralFeature> iter = dataTypeDefinition.getEAllStructuralFeatures().iterator();
+ while (iter.hasNext()) {
+ final EStructuralFeature feature = iter.next();
+ builder.append(feature.getName());
+ builder.append(EQUALS);
+ final Object value = dataTypeInstance.eGet(feature);
+ builder.append(getLabel(serv, value));
+ if (iter.hasNext()) {
+ builder.append(SEPARATOR);
+ builder.append(" ");//$NON-NLS-1$
+ }
+ }
+
+ }
+ }
+ builder.append(DATATYPE_END);
+ return builder.toString();
+ }
+
+ /**
+ *
+ * @param service
+ * the label provider service
+ * @param current
+ * the object for which we want the label
+ * @return
+ * the label for the given value
+ */
+ protected String getLabel(final LabelProviderService service, final Object object) {
+ final StringBuilder builder = new StringBuilder();
+ if (object instanceof Collection<?>) {
+ builder.append(COLLECTION_START);
+ final Collection<?> coll = (Collection<?>) object;
+ final Iterator<?> iter = coll.iterator();
+ while (iter.hasNext()) {
+ final Object current = iter.next();
+ final String value = getLabel(service, current);
+ if (value != null) {
+ builder.append(value);
+ } else {
+ builder.append(" "); //$NON-NLS-1$
+ }
+ if (iter.hasNext()) {
+ builder.append(SEPARATOR);
+ builder.append(" "); //$NON-NLS-1$
+ }
+ }
+ builder.append(COLLECTION_END);
+ } else {
+ final String label = service.getLabelProvider(object).getText(object);
+ if (label != null) {
+ builder.append(label);
+ }
+ }
+ return builder.toString();
+
+ }
+
+ /**
+ *
+ * @param dataTypeInstance
+ * a datatype instance
+ * @return
+ * the label provider service found or <code>null</code> otherwise
+ */
+ protected LabelProviderService getLabelProviderService(final EObject dataTypeInstance) {
+ ServicesRegistry registry = null;
+ LabelProviderService service = null;
+ try {
+ registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(dataTypeInstance);
+ service = registry.getService(LabelProviderService.class);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return service;
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return null;
+ }
+}

Back to the top