Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-02-04 23:21:45 +0000
committerChristian W. Damus2014-02-07 23:55:45 +0000
commit09f0c73e06c20481ec3b8b58c3e83798ac7c85b9 (patch)
tree1f508bcd2954bd05b6ccb447a186212a8faf85e6 /plugins/views
parentd909f5a652495c22b61933b969eebdf72c513b24 (diff)
downloadorg.eclipse.papyrus-09f0c73e06c20481ec3b8b58c3e83798ac7c85b9.tar.gz
org.eclipse.papyrus-09f0c73e06c20481ec3b8b58c3e83798ac7c85b9.tar.xz
org.eclipse.papyrus-09f0c73e06c20481ec3b8b58c3e83798ac7c85b9.zip
402525: [Widgets / Transactions] Papyrus dialogs should be transactional
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402525 Introduce an IAtomicOperationExecutor adapter for the object being edited by the widgets to to execute complex operations on the EMF command-stack (for EObjects being edited). This command stack is understood to support nested command execution. Add the element being edited as context for the ReferenceValueFactory's creation of a new referenced object. This provides resource-set context for nested editors that need to create further new elements wherever in the model. This resource-set also can be used to look up the LabelProviderService for presentation of objects in the dialogs.
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EcorePropertyEditorFactory.java73
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/PropertyEditorFactory.java79
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/modelelement/EMFModelElement.java11
3 files changed, 136 insertions, 27 deletions
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EcorePropertyEditorFactory.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EcorePropertyEditorFactory.java
index f9da5ab4928..e17e7831e6b 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EcorePropertyEditorFactory.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EcorePropertyEditorFactory.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 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
@@ -8,6 +8,8 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.properties.creation;
@@ -16,17 +18,23 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.emf.dialog.NestedEditingDialogContext;
import org.eclipse.papyrus.infra.emf.utils.EClassNameComparator;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.views.properties.Activator;
+import org.eclipse.papyrus.views.properties.contexts.View;
import org.eclipse.papyrus.views.properties.messages.Messages;
import org.eclipse.papyrus.views.properties.providers.CreateInFeatureContentProvider;
import org.eclipse.swt.SWT;
@@ -185,17 +193,67 @@ public class EcorePropertyEditorFactory extends PropertyEditorFactory {
* {@inheritDoc}
*/
@Override
- public Object createObject(Control widget) {
+ public final Object createObject(Control widget, Object context) {
+ Object result;
+
+ final ResourceSet previous = NestedEditingDialogContext.getInstance().push(context);
+
+ try {
+ result = doCreateObject(widget, context);
+ } finally {
+ NestedEditingDialogContext.getInstance().pop(previous);
+ }
+
+ return result;
+ }
+
+ protected Object doCreateObject(Control widget, Object context) {
Object instance;
+
if(referenceIn.isContainment()) {
instance = simpleCreateObject(widget);
} else {
instance = createObjectInDifferentContainer(widget);
}
- return super.createObject(widget, instance);
+ return createObject(widget, context, instance);
}
+ @Override
+ protected Object doEdit(final Control widget, final Object source, final Set<View> views, final String dialogTitle) {
+ Object result;
+
+ try {
+ NestedEditingDialogContext.getInstance().enter();
+ try {
+ result = getOperationExecutor(source).execute(new Callable<Object>() {
+ public Object call() throws Exception {
+ return basicDoEdit(widget, source, views, dialogTitle);
+ }
+ }, dialogTitle);
+ } finally {
+ NestedEditingDialogContext.getInstance().exit();
+ }
+ } catch (OperationCanceledException e) {
+ if(!NestedEditingDialogContext.getInstance().isNested()) {
+ // Propagate to the caller if not in a nested edit dialog
+ throw e;
+ }
+ result = null;
+ }
+
+ return result;
+ }
+
+ protected final Object basicDoEdit(Control widget, Object source, Set<View> views, String dialogTitle) {
+ return super.doEdit(widget, source, views, dialogTitle);
+ }
+
+ @Override
+ protected void handleEditCancelled(Control widget, Object source) {
+ throw new OperationCanceledException();
+ }
+
protected EObject simpleCreateObject(Control widget) {
EClass eClass = chooseEClass(widget);
if(eClass == null) {
@@ -212,7 +270,14 @@ public class EcorePropertyEditorFactory extends PropertyEditorFactory {
return null;
}
- containerContentProvider.inputChanged(null, null, instance);
+ // Try to get the current resource set for a wide scope of places to put a new element
+ Object containerInput = NestedEditingDialogContext.getInstance().getResourceSet();
+ if (containerInput == null) {
+ // Only have the object that we've created for context
+ containerInput = instance;
+ }
+
+ containerContentProvider.inputChanged(null, null, containerInput);
referenceContentProvider.setType(instance.eClass());
CreateInDialog dialog = new CreateInDialog(widget.getShell(), instance);
dialog.setProviders(containerContentProvider, referenceContentProvider, containerLabelProvider, referenceLabelProvider);
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/PropertyEditorFactory.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/PropertyEditorFactory.java
index 4e86109ca2b..93eb38b7ef1 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/PropertyEditorFactory.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/PropertyEditorFactory.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 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
@@ -8,15 +8,20 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.properties.creation;
import java.util.Collection;
import java.util.Set;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.widgets.creation.IAtomicOperationExecutor;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.views.properties.contexts.View;
import org.eclipse.papyrus.views.properties.messages.Messages;
@@ -51,15 +56,18 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
* Return a null value. Implementors should override when object creation
* needs to be supported. Implementors may rely on {@link #createObject(Control, Object)}
*
- * @see org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory#createObject(org.eclipse.swt.widgets.Control)
- * @see #createObject(org.eclipse.swt.widgets.Control, Object)
- *
* @param widget
* The widget from which this method is called. May be used to retrieve the current shell
+ * @param context
+ * The object being edited, in which context the new object is to be created and which will as a result have a reference to the new object.
+ * If there is no context object (creation of a free-floating object) or it cannot be determined, this may be {@code null}
* @return
* The newly created object
+ *
+ * @see ReferenceValueFactory#createObject(Control, Object)
+ * @see #createObject(Control, Object, Object)
*/
- public Object createObject(Control widget) {
+ public Object createObject(Control widget, Object context) {
return null;
}
@@ -72,12 +80,15 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
*
* @param widget
* The widget used to open the dialog
+ * @param context
+ * The object being edited, in which context the new object is to be created and which will as a result have a reference to the new object.
+ * If there is no context object (creation of a free-floating object) or it cannot be determined, this may be {@code null}
* @param source
* The created EObject. If null, nothing will happen
* @return
* The source EObject, which potential in-place modifications
*/
- protected Object createObject(Control widget, Object source) {
+ protected Object createObject(Control widget, Object context, Object source) {
if(source == null) {
return null;
}
@@ -87,15 +98,7 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
ViewConstraintEngine constraintEngine = ConfigurationManager.getInstance().getConstraintEngine();
Set<View> views = constraintEngine.getViews(selection);
if(!views.isEmpty()) {
- EditionDialog dialog = new EditionDialog(widget.getShell(), true);
- dialog.setViews(views);
- dialog.setInput(source);
- dialog.setTitle(getCreationDialogTitle());
-
- int result = dialog.open();
- if(result != Window.OK) {
- return null;
- }
+ return doEdit(widget, source, views, getCreationDialogTitle());
}
return source;
@@ -134,17 +137,30 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
Set<View> views = constraintEngine.getViews(selection);
if(!views.isEmpty()) {
- EditionDialog dialog = new EditionDialog(widget.getShell());
- dialog.setTitle(getEditionDialogTitle(source));
- dialog.setViews(views);
- dialog.setInput(source);
-
- dialog.open();
+ return doEdit(widget, source, views, getEditionDialogTitle(source));
}
return source;
}
+ protected Object doEdit(Control widget, Object source, Set<View> views, String dialogTitle) {
+ EditionDialog dialog = new EditionDialog(widget.getShell(), true);
+ dialog.setTitle(dialogTitle);
+ dialog.setViews(views);
+ dialog.setInput(source);
+
+ if (dialog.open() != Window.OK) {
+ handleEditCancelled(widget, source);
+ return null;
+ }
+
+ return source;
+ }
+
+ protected void handleEditCancelled(Control widget, Object source) {
+ // Pass
+ }
+
/**
* The standard Property Editor Factory cannot instantiate new objects.
* However, subclasses may override this method to return true if they
@@ -173,4 +189,25 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
public String getEditionDialogTitle(Object objectToEdit) {
return "Edit an element";
}
+
+ /**
+ * Obtains the most appropriate operation executor for the object being edited.
+ *
+ * @param context the object being edited
+ * @return the executor to use to run operations (never {@code null})
+ */
+ public IAtomicOperationExecutor getOperationExecutor(Object context) {
+ IAtomicOperationExecutor result;
+ if(context instanceof IAdaptable) {
+ result = (IAtomicOperationExecutor)((IAdaptable)context).getAdapter(IAtomicOperationExecutor.class);
+ } else {
+ result = (IAtomicOperationExecutor)Platform.getAdapterManager().getAdapter(context, IAtomicOperationExecutor.class);
+ }
+
+ if (result == null) {
+ result = IAtomicOperationExecutor.DEFAULT;
+ }
+
+ return result;
+ }
}
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/modelelement/EMFModelElement.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/modelelement/EMFModelElement.java
index cf40594c4ef..ed4cfe5f47c 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/modelelement/EMFModelElement.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/modelelement/EMFModelElement.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 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
@@ -8,6 +8,8 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.properties.modelelement;
@@ -27,10 +29,12 @@ import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.databinding.EMFObservableList;
import org.eclipse.papyrus.infra.emf.databinding.EMFObservableValue;
+import org.eclipse.papyrus.infra.emf.dialog.NestedEditingDialogContext;
import org.eclipse.papyrus.infra.emf.providers.EMFContentProvider;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
@@ -199,7 +203,10 @@ public class EMFModelElement extends AbstractModelElement {
@Override
public ILabelProvider getLabelProvider(String propertyPath) {
try {
- return ServiceUtilsForEObject.getInstance().getServiceRegistry(source).getService(LabelProviderService.class).getLabelProvider();
+ LabelProviderService lpSvc = (source.eResource() != null) //
+ ? ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, source) //
+ : ServiceUtilsForResourceSet.getInstance().getService(LabelProviderService.class, NestedEditingDialogContext.getInstance().getResourceSet());
+ return lpSvc.getLabelProvider();
} catch (ServiceException ex) {
Activator.log.error(ex);
return new EMFLabelProvider();

Back to the top