Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-12-16 15:16:06 +0000
committerGerrit Code Review @ Eclipse.org2016-12-16 17:20:59 +0000
commit5b79cfb1b41f2089508ebda7c82675513fd3620c (patch)
tree6fdbcfeb9d424ff6dbe05fbd8461be10a0d38b50 /plugins/infra/emf
parentcc5807c3961121773e939142c9f7bd1717dc12f3 (diff)
downloadorg.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.tar.gz
org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.tar.xz
org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.zip
Bug 502533: [Property View] Property pages generated for DataType
shall be improved - Modification of the compliance of the uml.nattable plugin to use PapyrusObservableValue not deprecated. Developed by Fanch Bonnabesse. Change-Id: Ib2c5436de26a256ac136715a58de716bd816da2c Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/infra/emf')
-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
5 files changed, 683 insertions, 0 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
new file mode 100644
index 00000000000..457f0f68d92
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
@@ -0,0 +1,270 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.databinding;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.ui.provider.PropertyDescriptor.EDataTypeCellEditor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
+import org.eclipse.swt.SWT;
+
+/**
+ *
+ * Editing Support used to edit EObservableValue on a TreeViewer.
+ *
+ */
+public class EObjectObservableValueEditingSupport extends EditingSupport {
+
+ /** proposals for boolean */
+ protected final String[] booleanProposals = new String[] { "true", "false" }; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Constructor.
+ *
+ * @param viewer
+ * Viewer in which editors will open.
+ * @param factory
+ * The reference value factory.
+ */
+ public EObjectObservableValueEditingSupport(final ColumnViewer viewer, final ReferenceValueFactory factory) {
+ super(viewer);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang.Object)
+ */
+ @Override
+ protected boolean canEdit(final Object element) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
+ */
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ if (element instanceof EObjectObservableValue) {
+ Object valueType = ((EObjectObservableValue) element).getValueType();
+ if (valueType instanceof EStructuralFeature) {
+ EStructuralFeature feature = (EStructuralFeature) valueType;
+
+ if (feature instanceof EReference) {
+ return null;
+ }
+
+ EClassifier eType = feature.getEType();
+ if (eType instanceof EEnum) {
+ return createEnumerationEditor(feature);
+ } else {
+ String instanceTypeName = eType.getInstanceClassName();
+ if (instanceTypeName.equals("boolean")) { //$NON-NLS-1$
+ return createBooleanEditor();
+ }
+ }
+
+ if (eType instanceof EDataType) {
+ return new EDataTypeCellEditor((EDataType) eType, ((TreeViewer) getViewer()).getTree());
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object)
+ */
+ @Override
+ protected Object getValue(final Object element) {
+ if (element instanceof EObjectObservableValue) {
+ EStructuralFeature feature = (EStructuralFeature) ((EObjectObservableValue) element).getValueType();
+ if (feature instanceof EReference) {
+ return null;
+ // return getReferenceValue((EReference) feature);
+ }
+ EClassifier eType = feature.getEType();
+ Object object = ((EObjectObservableValue) element).getValue();
+ if (eType instanceof EEnum) {
+ return getEnumerationValue((EEnum) eType, object);
+ } else {
+ String instanceTypeName = eType.getInstanceClassName();
+ if (instanceTypeName.equals("boolean")) { //$NON-NLS-1$
+ return getBooleanValue(object);
+ }
+
+ return object;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the value from the feature.
+ *
+ * @param feature
+ * The feature to edit.
+ * @param object
+ * The object to search.
+ * @return the boolean value
+ */
+ protected Object getEnumerationValue(final EEnum eType, final Object object) {
+ List<EEnumLiteral> literals = eType.getELiterals();
+ if (object == null) {
+ return 0;
+ } else {
+ return literals.indexOf(object);
+ }
+ }
+
+ /**
+ * Returns the value from the feature.
+ *
+ * @return the boolean value.
+ */
+ protected Object getBooleanValue(final Object object) {
+ List<String> booleans = Arrays.asList(booleanProposals);
+ if (object == null || object.equals("")) {
+ return 0;
+ }
+ return booleans.indexOf(object.toString());
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object, java.lang.Object)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void setValue(final Object element, final Object value) {
+ if (element instanceof EObjectObservableValue) {
+ EStructuralFeature feature = (EStructuralFeature) ((EObjectObservableValue) element).getValueType();
+ if (feature instanceof EReference) {
+ // setReferenceValue(element, value);
+ } else {
+ EClassifier eType = feature.getEType();
+ if (eType instanceof EEnum) {
+ setEnumerationValue((EObjectObservableValue) element, value);
+ } else {
+ String instanceTypeName = eType.getInstanceClassName();
+ if (instanceTypeName.equals("boolean")) { //$NON-NLS-1$
+ setBooleanValue((EObjectObservableValue) element, value);
+ } else {
+ ((EObjectObservableValue) element).setValue(value);
+ }
+ }
+ }
+
+ getViewer().update(element, null);
+ }
+ }
+
+ /**
+ * This allows to set the enumeration value.
+ *
+ * @param element
+ * The element to manage.
+ * @param value
+ * The value to set.
+ */
+ @SuppressWarnings("unchecked")
+ protected void setEnumerationValue(final EObjectObservableValue element, final Object value) {
+ EStructuralFeature feature = (EStructuralFeature) element.getValueType();
+ EEnum eType = (EEnum) feature.getEType();
+ List<EEnumLiteral> literals = eType.getELiterals();
+ List<String> proposals = new ArrayList<>();
+ for (int i = 0; i < literals.size(); i++) {
+ // i+1 because there is already the "" string
+ proposals.add(i, literals.get(i).getLiteral());
+ }
+ if (null == value) {
+ element.setValue(null);
+ } else {
+ // retrieve the index of the current value in the list
+ int index = (Integer) value;
+ if (index >= 0 && index < literals.size()) {
+ element.setValue(literals.get(index));
+ }
+ }
+ }
+
+ /**
+ * Sets the new boolean value on the given element.
+ *
+ * @param element
+ * The model element.
+ * @param value
+ * The new value.
+ */
+ @SuppressWarnings("unchecked")
+ protected void setBooleanValue(final EObjectObservableValue element, final Object value) {
+ if (null == value) {
+ // propertiesToUpdate.remove(featureName);
+ } else if (value.equals(0)) {
+ element.setValue(Boolean.valueOf(booleanProposals[0]));
+ } else if (value.equals(1)) {
+ element.setValue(Boolean.valueOf(booleanProposals[1]));
+ } else {
+ Activator.log.error("impossible to set boolean value " + value, null); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates and return a combobox cell editor for a boolean type
+ *
+ * @return the newly created combo box cell editor
+ */
+ protected CellEditor createBooleanEditor() {
+ return new ComboBoxCellEditor(((TreeViewer) getViewer()).getTree(), booleanProposals, SWT.READ_ONLY);
+ }
+
+ /**
+ * Creates and return a combobox cell editor for an enumeration type
+ *
+ * @param feature
+ * the feature to edit
+ * @return the newly created combo box cell editor
+ */
+ protected CellEditor createEnumerationEditor(final EStructuralFeature feature) {
+ EEnum eType = (EEnum) feature.getEType();
+ List<EEnumLiteral> literals = eType.getELiterals();
+ String[] proposals = new String[literals.size()];
+ for (int i = 0; i < literals.size(); i++) {
+ proposals[i] = literals.get(i).getLiteral();
+ }
+ return new ComboBoxCellEditor(((TreeViewer) getViewer()).getTree(), proposals, SWT.READ_ONLY);
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java
new file mode 100644
index 00000000000..fd6ee4c4fd3
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectStructuredObservableValue.java
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.databinding;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+
+/**
+ * Structured ObservableValue.
+ */
+public class EObjectStructuredObservableValue extends EMFObservableValue {
+
+ /**
+ * List of child of the ObservableValue.
+ */
+ protected List<EObjectObservableValue> observables = new ArrayList<>();
+
+ /**
+ * Constructor.
+ *
+ * @param eObject
+ * The EObject to edit.
+ * @param eStructuralFeature
+ * The structural feature.
+ * @param domain
+ * The current editing domain.
+ * @param browseFeatures
+ * The features for the browse.
+ */
+ public EObjectStructuredObservableValue(EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain, boolean browseFeatures) {
+ super(eObject, eStructuralFeature, domain);
+ if (null != eObject) {
+ if (browseFeatures) {
+ browseFeatures(eObject);
+ }
+ }
+ }
+
+ /**
+ * Get the child.
+ *
+ * @return The observables.
+ */
+ public List<EObjectObservableValue> getObservables() {
+ return observables;
+ }
+
+ /**
+ * Crete the child.
+ *
+ * @param eObject
+ * The parent.
+ */
+ private void browseFeatures(final EObject eObject) {
+ EList<EStructuralFeature> eStructuralFeatures = eObject.eClass().getEStructuralFeatures();
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(eObject);
+ for (EStructuralFeature eStructuralFeature : eStructuralFeatures) {
+ EObjectObservableValue eObjectObservableValue;
+ Object eGet = eObject.eGet(eStructuralFeature);
+ if (eStructuralFeature instanceof EReference && eGet instanceof EObject) {
+ eObjectObservableValue = new EObjectStructuredObservableValue((EObject) eGet, eStructuralFeature, editingDomain, true);
+ } else {
+ eObjectObservableValue = new EObjectStructuredObservableValue(eObject, eStructuralFeature, editingDomain, false);
+ }
+ observables.add(eObjectObservableValue);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.databinding.EObjectObservableValue#getValueType()
+ */
+ @Override
+ public Object getValueType() {
+ Object valueType = super.getValueType();
+ if (null == valueType && null != eObject) {
+ valueType = eObject.eClass();
+ }
+ return valueType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.databinding.EObjectObservableValue#dispose()
+ */
+ @Override
+ public synchronized void dispose() {
+ for (EObjectObservableValue eObjectObservableValue : observables) {
+ eObjectObservableValue.dispose();
+ }
+ super.dispose();
+ }
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java
new file mode 100644
index 00000000000..046174a3478
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/dialog/EObjectTreeReferenceValueEditor.java
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.dialog;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EObjectObservableValueEditingSupport;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EObjectStructuredObservableValue;
+import org.eclipse.papyrus.infra.ui.emf.providers.EObjectObservableValueContentProvider;
+import org.eclipse.papyrus.infra.ui.emf.providers.EObjectObservableValueLabelProvider;
+import org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor;
+import org.eclipse.papyrus.infra.widgets.providers.DelegatingStyledLabelProvider;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * This class extends TreeReferenceDialog and allow the display of EObjectObservableValue.
+ */
+public class EObjectTreeReferenceValueEditor extends TreeReferenceValueEditor {
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * the parent composite.
+ * @param style
+ * The style of the composite to create.
+ */
+ public EObjectTreeReferenceValueEditor(final Composite parent, final int style) {
+ super(parent, style);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#setValueRootContentProvider()
+ */
+ @Override
+ public void setValueRootContentProvider() {
+ if (null != treeViewer) {
+ if (treeViewer.getContentProvider() instanceof EObjectObservableValueContentProvider) {
+ ((EObjectObservableValueContentProvider) treeViewer.getContentProvider()).setValueRoot(widgetObservable);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#setProvidersTreeViewer()
+ */
+ @Override
+ public void setProvidersTreeViewer() {
+ treeViewer.setContentProvider(new EObjectObservableValueContentProvider(widgetObservable));
+ if (labelProvider instanceof IStyledLabelProvider) {
+ treeViewer.setLabelProvider(new EObjectObservableValueLabelProvider((IStyledLabelProvider) labelProvider));
+ } else {
+ treeViewer.setLabelProvider(new EObjectObservableValueLabelProvider(new DelegatingStyledLabelProvider(labelProvider)));
+ }
+
+ treeViewer.setInput(""); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#createWidgetObservable(org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ public IObservableValue createWidgetObservable(final IObservableValue modelProperty) {
+ EObjectStructuredObservableValue eObjectObser = null;
+ if (modelProperty.getValue() instanceof EObject) {
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain((EObject) modelProperty.getValue());
+ eObjectObser = new EObjectStructuredObservableValue((EObject) modelProperty.getValue(), null, editingDomain, true);
+ }
+ return eObjectObser;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.widgets.editors.TreeReferenceValueEditor#createEditingSupport()
+ */
+ @Override
+ public EditingSupport createEditingSupport() {
+ return new EObjectObservableValueEditingSupport(treeViewer, valueFactory);
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java
new file mode 100644
index 00000000000..f0a9caeb39d
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueContentProvider.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.providers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EObjectStructuredObservableValue;
+
+/**
+ * ContentProvider of the EObjectObservaleValue.
+ */
+public class EObjectObservableValueContentProvider implements ITreeContentProvider {
+
+ /**
+ * Value root of the tree.
+ */
+ private Object valueRoot = null;
+
+ /**
+ * Constructor.
+ *
+ * @param value
+ * The value to manage.
+ */
+ public EObjectObservableValueContentProvider(final Object value) {
+ super();
+ valueRoot = value;
+ }
+
+ /**
+ * This allows to set the root value.
+ *
+ * @param value
+ * the root value
+ */
+ public void setValueRoot(final Object value) {
+ this.valueRoot = value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements(final Object inputElement) {
+ ArrayList<Object> arrayList = new ArrayList<>();
+ if (null != valueRoot) {
+ arrayList.add(valueRoot);
+ }
+
+
+ return arrayList.toArray();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(final Object parentElement) {
+ final List<EObjectObservableValue> children = new ArrayList<>();
+
+ if (parentElement instanceof EObjectStructuredObservableValue) {
+ List<EObjectObservableValue> observables = ((EObjectStructuredObservableValue) parentElement).getObservables();
+ children.addAll(observables);
+ }
+
+ return children.toArray();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(final Object element) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(final Object element) {
+ return 0 < getChildren(element).length;
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
new file mode 100644
index 00000000000..6df791cfd22
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.providers;
+
+import org.eclipse.emf.databinding.EObjectObservableValue;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider;
+
+/**
+ * LabelProvider used to show feature name and EObject of an EObjectObservaleValue.
+ *
+ */
+public class EObjectObservableValueLabelProvider extends DelegatingStyledCellLabelProvider {
+
+ /**
+ * Index of the EStructuralFeature.
+ */
+ private static final int ESTRUCTURAL_FEATURE = 0;
+
+ /**
+ * Index of the EObject.
+ */
+ private static final int EOBJECT = 1;
+
+ /**
+ * Constructor.
+ *
+ * @param styledLabelProvider
+ * The {@link IStyledLabelProvider}.
+ */
+ public EObjectObservableValueLabelProvider(final IStyledLabelProvider styledLabelProvider) {
+ super(styledLabelProvider);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ @Override
+ public String getColumnText(final Object element, final int columnIndex) {
+ if (element instanceof EObjectObservableValue) {
+ String columnText = ""; //$NON-NLS-1$
+ EObjectObservableValue elementObservableValue = (EObjectObservableValue) element;
+ Object valueType = elementObservableValue.getValueType();
+ if (valueType instanceof EAttribute) {
+ switch (columnIndex) {
+ case ESTRUCTURAL_FEATURE:
+ if (valueType instanceof EStructuralFeature) {
+ columnText = ((EStructuralFeature) valueType).getName();
+ }
+ break;
+ case EOBJECT:
+ if (null != elementObservableValue.getValue()) {
+ columnText = elementObservableValue.getValue().toString();
+ }
+ break;
+ default:
+ columnText = super.getColumnText(element, columnIndex);
+ break;
+ }
+ } else {
+ if (ESTRUCTURAL_FEATURE == columnIndex) {
+ if (valueType instanceof ENamedElement) {
+ columnText = ((ENamedElement) valueType).getName();
+ }
+ }
+ }
+
+ return columnText;
+ }
+ return super.getColumnText(element, columnIndex);
+ }
+}

Back to the top