Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2017-09-21 11:40:02 +0000
committervincent lorenzo2017-09-25 08:15:18 +0000
commit24eb73bed0d0c0a6c7d5d0745b99c547a88f846f (patch)
tree833d6683affd9617fae5474122fb8b09b2ec34ea /plugins/uml
parentb16c9d2ea83029aee2c6031db266f54542f0485d (diff)
downloadorg.eclipse.papyrus-24eb73bed0d0c0a6c7d5d0745b99c547a88f846f.tar.gz
org.eclipse.papyrus-24eb73bed0d0c0a6c7d5d0745b99c547a88f846f.tar.xz
org.eclipse.papyrus-24eb73bed0d0c0a6c7d5d0745b99c547a88f846f.zip
Bug 521861: [Property View][Profile] Too many exceptions when editing datatype values
Change-Id: Iff9cd3ea861eac14c4d42e6b3cc050f0891b53d7 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/EObjectContentsEditor.java42
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/GenericUMLDatatypeEditor.java40
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/providers/GenericDataTypeLabelProvider.java20
3 files changed, 82 insertions, 20 deletions
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/EObjectContentsEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/EObjectContentsEditor.java
index 3e4816e3024..480d7519b6b 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/EObjectContentsEditor.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/EObjectContentsEditor.java
@@ -10,7 +10,7 @@
* Contributors:
* Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
* Pierre GAUTIER (CEA LIST) - bug 521865
- *
+ * Vincent LORENZO (CEA LIST) - bug 521861
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.widgets;
@@ -23,6 +23,8 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.papyrus.infra.emf.utils.HistoryUtil;
@@ -192,7 +194,13 @@ public class EObjectContentsEditor extends Composite {
ILabelProvider labelProvider;
try {
- labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, dataTypeInstance).getLabelProvider();
+ if (null == dataTypeInstance.eResource() && null != dataTypeDefinition.eResource()) {
+ // the datatype is not always in a resource (when it just comes to be created, nevertheless, its EClass is always in a resource loaded in the ResourceSet
+ labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, dataTypeDefinition).getLabelProvider();
+ } else {
+ // I continue to use this branch for all other cases, to get exception and example to reproduce them
+ labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, dataTypeInstance).getLabelProvider();
+ }
} catch (Exception ex) {
Activator.log.error(ex);
labelProvider = new UMLLabelProvider();
@@ -201,7 +209,12 @@ public class EObjectContentsEditor extends Composite {
for (EStructuralFeature feature : dataTypeDefinition.getEAllStructuralFeatures()) {
EStructuralFeatureEditor propertyEditor = new EStructuralFeatureEditor(contents, SWT.NONE);
- propertyEditor.setProviders(new UMLContentProvider(dataTypeInstance, feature), labelProvider);
+ if (null == dataTypeInstance.eResource() && null != dataTypeDefinition.eResource()) {
+ propertyEditor.setProviders(new UMLContentProvider(dataTypeInstance, feature, null, dataTypeDefinition.eResource().getResourceSet()), labelProvider);
+ } else {
+ propertyEditor.setProviders(new UMLContentProvider(dataTypeInstance, feature), labelProvider);
+ }
+
if (feature instanceof EReference) {
propertyEditor.setValueFactory(getUMLPropertyEditorFactory(dataTypeInstance, (EReference) feature));
}
@@ -259,7 +272,7 @@ public class EObjectContentsEditor extends Composite {
protected void createAddButton() {
addButton = new Button(buttonsBar, SWT.PUSH);
addButton.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("icons/Add_12x12.gif")); //$NON-NLS-1$
- addButton.setToolTipText(Messages.EObjectContentsEditor_CreateElement);
+ addButton.setToolTipText(Messages.EObjectContentsEditor_CreateElement);
addButton.addSelectionListener(new SelectionListener() {
@@ -291,7 +304,7 @@ public class EObjectContentsEditor extends Composite {
protected void createDeleteButton() {
deleteButton = new Button(buttonsBar, SWT.PUSH);
deleteButton.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("icons/Delete_12x12.gif")); //$NON-NLS-1$
- deleteButton.setToolTipText(Messages.EObjectContentsEditor_UnsetValue);
+ deleteButton.setToolTipText(Messages.EObjectContentsEditor_UnsetValue);
deleteButton.addSelectionListener(new SelectionListener() {
@@ -320,9 +333,22 @@ public class EObjectContentsEditor extends Composite {
factory.setContainerLabelProvider(new UMLFilteredLabelProvider());
factory.setReferenceLabelProvider(new EMFLabelProvider());
- ITreeContentProvider contentProvider = new UMLContainerContentProvider(dataTypeInstance, reference);
-
- EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, dataTypeInstance.eResource().getResourceSet(), HistoryUtil.getHistoryID(dataTypeInstance, reference, "container")); //$NON-NLS-1$
+ final Resource res = null != dataTypeInstance.eResource() ? dataTypeInstance.eResource() : null;
+ ResourceSet resourceSet = null != res ? res.getResourceSet() : null;
+
+ // the datatype is not always in a resource (when it just comes to be created, nevertheless, its EClass is always in a resource loaded in the ResourceSet
+ if (null == resourceSet && null!=dataTypeInstance.eClass().eResource()) {
+ resourceSet = dataTypeInstance.eClass().eResource().getResourceSet();
+ }
+
+ final ITreeContentProvider contentProvider;
+ if (null != dataTypeInstance.eResource()) {
+ contentProvider = new UMLContainerContentProvider(dataTypeInstance, reference);
+ } else {
+ contentProvider = new UMLContainerContentProvider(dataTypeInstance, reference, resourceSet);
+ }
+
+ EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, resourceSet, HistoryUtil.getHistoryID(dataTypeInstance, reference, "container")); //$NON-NLS-1$
factory.setContainerContentProvider(provider);
factory.setReferenceContentProvider(new FeatureContentProvider(type));
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/GenericUMLDatatypeEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/GenericUMLDatatypeEditor.java
index 6a2c59d2df0..dfae516a0c9 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/GenericUMLDatatypeEditor.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/GenericUMLDatatypeEditor.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2017 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,7 +9,7 @@
*
* Contributors:
* Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
- *
+ * Vincent Lorenzo (CEA LIST) - bug 521861
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.widgets;
@@ -17,6 +17,8 @@ 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.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -98,7 +100,13 @@ public class GenericUMLDatatypeEditor extends AbstractPropertyEditor {
ILabelProvider labelProvider;
try {
- labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, dataTypeInstance).getLabelProvider();
+ if (null == dataTypeInstance.eResource() && null != dataTypeDefinition.eResource()) {
+ // the datatype is not always in a resource (when it just comes to be created, nevertheless, its EClass is always in a resource loaded in the ResourceSet
+ labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, dataTypeDefinition).getLabelProvider();
+ } else {
+ // I continue to use this branch for all other cases, to get exception and example to reproduce them
+ labelProvider = ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, dataTypeInstance).getLabelProvider();
+ }
} catch (Exception ex) {
Activator.log.error(ex);
labelProvider = new UMLLabelProvider();
@@ -107,7 +115,14 @@ public class GenericUMLDatatypeEditor extends AbstractPropertyEditor {
for (EStructuralFeature feature : dataTypeDefinition.getEAllStructuralFeatures()) {
EStructuralFeatureEditor propertyEditor = new EStructuralFeatureEditor(self, SWT.NONE);
- propertyEditor.setProviders(new UMLContentProvider(dataTypeInstance, feature), labelProvider);
+
+ if (null == dataTypeInstance.eResource() && null != dataTypeDefinition.eResource()) {
+ propertyEditor.setProviders(new UMLContentProvider(dataTypeInstance, feature, null, dataTypeDefinition.eResource().getResourceSet()), labelProvider);
+ } else {
+ propertyEditor.setProviders(new UMLContentProvider(dataTypeInstance, feature), labelProvider);
+ }
+
+
if (feature instanceof EReference) {
propertyEditor.setValueFactory(getUMLPropertyEditorFactory(dataTypeInstance, (EReference) feature));
}
@@ -124,9 +139,22 @@ public class GenericUMLDatatypeEditor extends AbstractPropertyEditor {
factory.setContainerLabelProvider(new UMLFilteredLabelProvider());
factory.setReferenceLabelProvider(new EMFLabelProvider());
- ITreeContentProvider contentProvider = new UMLContainerContentProvider(dataTypeInstance, reference);
+ final Resource res = null != dataTypeInstance.eResource() ? dataTypeInstance.eResource() : null;
+ ResourceSet resourceSet = null != res ? res.getResourceSet() : null;
+
+ // the datatype is not always in a resource (when it just comes to be created, nevertheless, its EClass is always in a resource loaded in the ResourceSet
+ if (null == resourceSet && null!=dataTypeInstance.eClass().eResource()) {
+ resourceSet = dataTypeInstance.eClass().eResource().getResourceSet();
+ }
+
+ final ITreeContentProvider contentProvider;
+ if (null != dataTypeInstance.eResource()) {
+ contentProvider = new UMLContainerContentProvider(dataTypeInstance, reference);
+ } else {
+ contentProvider = new UMLContainerContentProvider(dataTypeInstance, reference, resourceSet);
+ }
- EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, dataTypeInstance.eResource().getResourceSet(), HistoryUtil.getHistoryID(dataTypeInstance, reference, "container"));
+ EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, resourceSet, HistoryUtil.getHistoryID(dataTypeInstance, reference, "container"));
factory.setContainerContentProvider(provider);
factory.setReferenceContentProvider(new FeatureContentProvider(type));
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 12b21b088c3..6bfeca44528 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,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2017 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,7 +9,7 @@
*
* Contributors:
* Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation
- * Vincent Lorenzo (vincent.lorenzo@cea.fr) - bug 405442
+ * Vincent Lorenzo (vincent.lorenzo@cea.fr) - bug 405442, bug 521861
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.providers;
@@ -165,9 +165,11 @@ public class GenericDataTypeLabelProvider extends EMFLabelProvider implements IF
}
builder.append(COLLECTION_END);
} else {
- final String label = service.getLabelProvider(object).getText(object);
- if (label != null) {
- builder.append(label);
+ if (null != service) {
+ final String label = service.getLabelProvider(object).getText(object);
+ if (label != null) {
+ builder.append(label);
+ }
}
}
return builder.toString();
@@ -186,7 +188,13 @@ public class GenericDataTypeLabelProvider extends EMFLabelProvider implements IF
ServicesRegistry registry = null;
LabelProviderService service = null;
try {
- registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(dataTypeInstance);
+ final EClass dataTypeDefinition = dataTypeInstance.eClass();
+ if (null == dataTypeInstance.eResource() && null!=dataTypeDefinition.eResource()) {
+ // the datatype is not always in a resource (when it just comes to be created, nevertheless, its EClass is always in a resource loaded in the ResourceSet
+ registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(dataTypeDefinition);
+ } else {
+ registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(dataTypeInstance);
+ }
service = registry.getService(LabelProviderService.class);
} catch (ServiceException e) {
Activator.log.error(e);

Back to the top