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/infra
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/infra')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/plugin.xml10
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/adapters/EObjectAdapterFactory.java85
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/databinding/EMFObservableList.java11
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/dialog/NestedEditingDialogContext.java132
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/BooleanEditionFactory.java14
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IAtomicOperationExecutor.java91
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IntegerEditionFactory.java15
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/ReferenceValueFactory.java9
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/StringEditionFactory.java6
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java15
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java27
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java54
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java6
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java47
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/Messages.java12
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties20
17 files changed, 479 insertions, 76 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
index b2fdcac9a08..b4c9fd570ce 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
@@ -30,6 +30,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.7.0",
com.google.guava;bundle-version="11.0.0"
Export-Package: org.eclipse.papyrus.infra.emf,
+ org.eclipse.papyrus.infra.emf.adapters,
org.eclipse.papyrus.infra.emf.commands,
org.eclipse.papyrus.infra.emf.databinding,
org.eclipse.papyrus.infra.emf.dialog,
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/plugin.xml b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/plugin.xml
index a5a77a29959..d9b6cb0f5d1 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/plugin.xml
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/plugin.xml
@@ -57,5 +57,15 @@
</elementType>
</binding>
</extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.emf.ecore.EObject"
+ class="org.eclipse.papyrus.infra.emf.adapters.EObjectAdapterFactory">
+ <adapter
+ type="org.eclipse.papyrus.infra.widgets.creation.IAtomicOperationExecutor">
+ </adapter>
+ </factory>
+ </extension>
</plugin>
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/adapters/EObjectAdapterFactory.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/adapters/EObjectAdapterFactory.java
new file mode 100644
index 00000000000..e16b485fc3b
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/adapters/EObjectAdapterFactory.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.infra.emf.adapters;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.papyrus.infra.emf.dialog.NestedEditingDialogContext;
+import org.eclipse.papyrus.infra.widgets.creation.IAtomicOperationExecutor;
+
+
+/**
+ * This is the EObjectAdapterFactory type. Enjoy.
+ */
+public class EObjectAdapterFactory implements IAdapterFactory {
+
+ private final Class<?>[] adapterTypes = { IAtomicOperationExecutor.class };
+
+ public EObjectAdapterFactory() {
+ super();
+ }
+
+ public Object getAdapter(Object adaptable, @SuppressWarnings("rawtypes") Class adapterType) {
+ Object result = null;
+
+ if(adaptable instanceof EObject) {
+ if(adapterType == IAtomicOperationExecutor.class) {
+ TransactionalEditingDomain domain = TransactionUtil.getEditingDomain((EObject)adaptable);
+ if(domain == null) {
+ ResourceSet rset = NestedEditingDialogContext.getInstance().getResourceSet();
+ if(rset != null) {
+ domain = TransactionUtil.getEditingDomain(rset);
+ }
+ }
+ if(domain != null) {
+ result = new EMFAtomicOperationExecutor(domain);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public Class[] getAdapterList() {
+ return adapterTypes;
+ }
+
+ //
+ // Nested types
+ //
+
+ private static final class EMFAtomicOperationExecutor extends IAtomicOperationExecutor.Default {
+
+ private final TransactionalEditingDomain domain;
+
+ EMFAtomicOperationExecutor(TransactionalEditingDomain domain) {
+ this.domain = domain;
+ }
+
+ @Override
+ public void execute(final Runnable operation, String label) {
+ domain.getCommandStack().execute(new RecordingCommand(domain, label) {
+
+ @Override
+ protected void doExecute() {
+ operation.run();
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/databinding/EMFObservableList.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/databinding/EMFObservableList.java
index 6af566f79ad..beb832a0015 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/databinding/EMFObservableList.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/databinding/EMFObservableList.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.infra.emf.databinding;
@@ -17,6 +19,7 @@ import java.util.List;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObserving;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.list.ObservableList;
import org.eclipse.emf.common.command.Command;
@@ -41,7 +44,7 @@ import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
* @author Camille Letavernier
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
-public class EMFObservableList extends ObservableList implements ICommitListener, IChangeListener {
+public class EMFObservableList extends ObservableList implements ICommitListener, IChangeListener, IObserving {
/**
* The list of commands that haven't been executed yet
@@ -106,6 +109,10 @@ public class EMFObservableList extends ObservableList implements ICommitListener
}
}
+ public Object getObserved() {
+ return source;
+ }
+
@Override
public synchronized void dispose() {
if(concreteList instanceof IObservableList) {
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/dialog/NestedEditingDialogContext.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/dialog/NestedEditingDialogContext.java
new file mode 100644
index 00000000000..813e5524574
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/dialog/NestedEditingDialogContext.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.infra.emf.dialog;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * A tracker of nested editing-dialog context information required by various components that have no direct access to the context.
+ */
+public class NestedEditingDialogContext {
+
+ private static final NestedEditingDialogContext INSTANCE = new NestedEditingDialogContext();
+
+ private final ThreadLocal<Integer> nesting = new ThreadLocal<Integer>();
+
+ private final ThreadLocal<ResourceSet> resourceSet = new ThreadLocal<ResourceSet>();
+
+ public static NestedEditingDialogContext getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Queries whether the current editing dialog is nested in (created by) a higher-level dialog editing some other object.
+ *
+ * @return whether the current thread is presenting a nested editing dialog
+ */
+ public boolean isNested() {
+ Integer depth = nesting.get();
+ return (depth != null) && (depth.intValue() > 0);
+ }
+
+ /**
+ * Signals entry of an editing dialog context (the current thread is now presenting a dialog). Must be matched by a subsequent
+ * call to {@linkplain #exit() exit} the context.
+ *
+ * @see #exit()
+ */
+ public void enter() {
+ Integer depth = nesting.get();
+ if((depth == null) || (depth.intValue() < 1)) {
+ depth = 1;
+ } else {
+ depth = depth.intValue() + 1;
+ }
+ nesting.set(depth);
+ }
+
+ /**
+ * Signals the end of an editing dialog context (the current thread is no longer presenting a dialog). Must match an earlier
+ * call to {@linkplain #enter() enter} the context.
+ *
+ * @see #enter()
+ */
+ public void exit() {
+ Integer depth = nesting.get();
+ if(depth != null) {
+ if(depth.intValue() <= 1) {
+ depth = null;
+ } else {
+ depth = depth.intValue() - 1;
+ }
+ nesting.set(depth);
+ }
+ }
+
+ /**
+ * Obtains the resource set in the editing-dialog context of the current thread.
+ *
+ * @return the current contextual resource set
+ */
+ public ResourceSet getResourceSet() {
+ return resourceSet.get();
+ }
+
+ /**
+ * Determines, if possible, the resource set containing the given {@code context} object being edited and pushes it onto the
+ * current thread's context stack.
+ *
+ * @param context
+ * the object currently being edited in a dialog
+ *
+ * @return the resource set that was previously the context (which may be the same as the new one being pushed). This
+ * must be {@linkplain #pop(ResourceSet) popped} from the context subsequently
+ *
+ * @see #pop(ResourceSet)
+ */
+ public ResourceSet push(Object context) {
+ final ResourceSet previous = resourceSet.get();
+
+ if(context instanceof EObject) {
+ Resource res = ((EObject)context).eResource();
+ if(res != null) {
+ ResourceSet current = res.getResourceSet();
+ if(current != null) {
+ // put it in context
+ resourceSet.set(current);
+ }
+ }
+ }
+
+ return previous;
+ }
+
+ /**
+ * Pops the current resource set from the context, restoring the given resource set that was returned by a previous {@linkplain #push(Object)
+ * push}, even if it was {@code null}.
+ *
+ * @param previous
+ * a resource set returned by an earlier push (may be {@code null})
+ *
+ * @see #push(Object)
+ */
+ public void pop(ResourceSet previous) {
+ if(previous == null) {
+ resourceSet.remove();
+ } else {
+ resourceSet.set(previous);
+ }
+ }
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/BooleanEditionFactory.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/BooleanEditionFactory.java
index 8f326b0d196..28e586aa906 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/BooleanEditionFactory.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/BooleanEditionFactory.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2014 CEA LIST and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
*
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.creation;
@@ -71,16 +72,9 @@ public class BooleanEditionFactory extends StringEditionFactory {
super(title, label, new BooleanInputValidator());
}
- /**
- *
- * @see org.eclipse.papyrus.infra.widgets.creation.StringEditionFactory#createObject(org.eclipse.swt.widgets.Control)
- *
- * @param widget
- * @return
- */
@Override
- public Object createObject(Control widget) {
- String txt = super.createObject(widget).toString();
+ public Object createObject(Control widget, Object context) {
+ String txt = super.createObject(widget, context).toString();
if(txt != null) {
return Boolean.parseBoolean(txt);
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IAtomicOperationExecutor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IAtomicOperationExecutor.java
new file mode 100644
index 00000000000..dc69d248b2b
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IAtomicOperationExecutor.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.infra.widgets.creation;
+
+import java.util.concurrent.Callable;
+
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.papyrus.infra.widgets.Activator;
+
+
+/**
+ * An interface that ensures execution of model changes as an atomic unit that is potentially undoable and redoable, such as on a "command stack"
+ * (whatever form it may take).
+ */
+public interface IAtomicOperationExecutor {
+
+ IAtomicOperationExecutor DEFAULT = new Default();
+
+ /**
+ * Execute a runnable (an operation returning no result).
+ *
+ * @param operation
+ * the operation to execute
+ * @param label
+ * an optional label to associate with the operation for presentation in, for example, the Edit menu's Undo/Redo operations
+ */
+ void execute(Runnable operation, String label);
+
+ /**
+ * Execute a callable (an operation returning a result).
+ *
+ * @param operation
+ * the operation to execute
+ * @param label
+ * an optional label to associate with the operation for presentation in, for example, the Edit menu's Undo/Redo operations
+ * @return the {@code operation}'s result
+ */
+ <V> V execute(Callable<V> operation, String label);
+
+ //
+ // Nested types
+ //
+
+ class Default implements IAtomicOperationExecutor {
+
+ public void execute(final Runnable operation, String label) {
+ try {
+ operation.run();
+ } catch (OperationCanceledException e) {
+ // We cannot really implement cancel because there is not command/transaction to roll back
+ }
+ }
+
+ public <V> V execute(final Callable<V> operation, String label) {
+ class CallableWrapper implements Runnable {
+
+ V result;
+
+ @Override
+ public void run() {
+ try {
+ result = operation.call();
+ } catch (OperationCanceledException e) {
+ // Don't trap this one
+ throw e;
+ } catch (Exception e) {
+ Activator.log.error("Callable operation failed.", e); //$NON-NLS-1$
+ throw new OperationCanceledException(); // roll back
+ }
+ }
+ }
+
+ CallableWrapper wrapper = new CallableWrapper();
+
+ execute(wrapper, label);
+
+ return wrapper.result;
+ }
+
+ }
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IntegerEditionFactory.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IntegerEditionFactory.java
index 3f2c4b05b43..a254d03cda8 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IntegerEditionFactory.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/IntegerEditionFactory.java
@@ -1,7 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * 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
@@ -9,6 +8,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
*
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.creation;
@@ -69,16 +69,9 @@ public class IntegerEditionFactory extends StringEditionFactory {
this(title, label, new IntegerInputValidator());
}
- /**
- *
- * @see org.eclipse.papyrus.infra.widgets.creation.StringEditionFactory#createObject(org.eclipse.swt.widgets.Control)
- *
- * @param widget
- * @return
- */
@Override
- public Object createObject(Control widget) {
- String txt = super.createObject(widget).toString();
+ public Object createObject(Control widget, Object context) {
+ String txt = super.createObject(widget, context).toString();
if(txt != null) {
return Integer.parseInt(txt);
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/ReferenceValueFactory.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/ReferenceValueFactory.java
index 25586368f79..f6fac32bac1 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/ReferenceValueFactory.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/ReferenceValueFactory.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.infra.widgets.creation;
@@ -50,10 +52,13 @@ public interface ReferenceValueFactory {
* @param widget
* The widget calling this factory. It can be used for example to retrieve
* the Display for opening a 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}
* @return
* The newly created object, or null if no object has been created
*/
- public Object createObject(Control widget);
+ public Object createObject(Control widget, Object context);
/**
* The objects have been validated (For example, the user pressed "Ok")
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/StringEditionFactory.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/StringEditionFactory.java
index 837eaddffe9..cadc95e9bc0 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/StringEditionFactory.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/StringEditionFactory.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
+ * Copyright (c) 2011, 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.infra.widgets.creation;
@@ -90,7 +92,7 @@ public class StringEditionFactory implements ReferenceValueFactory {
return true;
}
- public Object createObject(Control widget) {
+ public Object createObject(Control widget, Object context) {
InputDialog dialog = new InputDialog(widget.getShell(), title, label, "", validator); //$NON-NLS-1$
if(contentProvider != null) {
dialog.setContentProvider(contentProvider);
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java
index 1b17b27193f..66e4780188c 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/creation/UnlimitedNaturalEditionFactory.java
@@ -1,7 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * 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
@@ -9,6 +8,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 402525
*
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.creation;
@@ -73,16 +73,9 @@ public class UnlimitedNaturalEditionFactory extends StringEditionFactory {
super(title, label, validator);
}
- /**
- *
- * @see org.eclipse.papyrus.infra.widgets.creation.StringEditionFactory#createObject(org.eclipse.swt.widgets.Control)
- *
- * @param widget
- * @return
- */
@Override
- public Object createObject(Control widget) {
- String txt = super.createObject(widget).toString();
+ public Object createObject(Control widget, Object context) {
+ String txt = super.createObject(widget, context).toString();
if(UnlimitedNaturalValidator.INFINITE_STAR.equals(txt)) {
txt = UnlimitedNaturalValidator.INFINITE_MINUS_ONE;
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java
index 4526632711c..04bd011276e 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.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.infra.widgets.editors;
@@ -17,6 +19,9 @@ import java.util.Set;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.widgets.creation.IAtomicOperationExecutor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
@@ -363,4 +368,24 @@ public abstract class AbstractEditor extends Composite implements DisposeListene
dispose();
}
+ /**
+ * 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/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java
index 5a5411df9e2..2907c9040a8 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.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.infra.widgets.editors;
@@ -16,6 +18,7 @@ import java.util.Collection;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObserving;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -25,6 +28,7 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;
+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;
@@ -401,11 +405,18 @@ public class MultipleValueEditor extends AbstractListEditor implements Selection
protected void addAction() {
if(directCreation) {
if(referenceFactory != null && referenceFactory.canCreateObject()) {
- Object newElement = referenceFactory.createObject(this);
- if(newElement != null) {
- modelProperty.add(newElement);
- commit();
- }
+ final Object context = (modelProperty instanceof IObserving) ? ((IObserving)modelProperty).getObserved() : null;
+ getOperationExecutor(context).execute(new Runnable() {
+
+ @Override
+ public void run() {
+ Object newElement = referenceFactory.createObject(MultipleValueEditor.this, context);
+ if(newElement != null) {
+ modelProperty.add(newElement);
+ commit();
+ }
+ }
+ }, NLS.bind(Messages.MultipleValueEditor_editOperation, labelText));
}
return;
@@ -513,19 +524,26 @@ public class MultipleValueEditor extends AbstractListEditor implements Selection
TreeItem selectedItem = treeViewer.getTree().getSelection()[0];
Tree parentTree = selectedItem.getParent();
- int index = parentTree.indexOf(selectedItem);
-
- Object currentValue = selection.getFirstElement();
- Object newValue = referenceFactory.edit(this.edit, selection.getFirstElement());
-
- if(newValue != currentValue && newValue != null) {
- modelProperty.remove(index);
- modelProperty.add(index, newValue);
-
- //commit(); // The commit only occurs in the case where we modify the list (We don't commit direct edition on objects)
- }
+ final int index = parentTree.indexOf(selectedItem);
+ final Object currentValue = selection.getFirstElement();
+
+ getOperationExecutor(currentValue).execute(new Runnable() {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void run() {
+ Object newValue = referenceFactory.edit(MultipleValueEditor.this.edit, currentValue);
+
+ if(newValue != currentValue && newValue != null) {
+ modelProperty.remove(index);
+ modelProperty.add(index, newValue);
+
+ //commit(); // The commit only occurs in the case where we modify the list (We don't commit direct edition on objects)
+ }
- commit();
+ commit();
+ }
+ }, NLS.bind(Messages.MultipleValueEditor_editOperation, labelText));
}
/**
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java
index dc5eeecdad0..174350ff089 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.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.infra.widgets.editors;
@@ -534,7 +536,7 @@ public class MultipleValueSelectorDialog extends SelectionDialog implements ISel
return;
}
- Object newObject = factory.createObject(this.create);
+ Object newObject = factory.createObject(this.create, null);
if(newObject == null) {
return;
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java
index 86a70c761e9..28dca683386 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.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.infra.widgets.editors;
@@ -15,10 +17,12 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.eclipse.core.databinding.observable.IObserving;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
+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.databinding.CLabelObservableValue;
@@ -213,14 +217,21 @@ public class ReferenceDialog extends AbstractValueEditor implements SelectionLis
*/
protected void createAction() {
if(valueFactory != null && valueFactory.canCreateObject()) {
- Object value = valueFactory.createObject(createInstanceButton);
- if(value == null) {
- return;
- }
- Collection<Object> validatedObjects = valueFactory.validateObjects(Collections.singleton(value));
- if(!validatedObjects.isEmpty()) {
- setValue(validatedObjects.iterator().next());
- }
+ final Object context = (modelProperty instanceof IObserving) ? ((IObserving)modelProperty).getObserved() : null;
+ getOperationExecutor(context).execute(new Runnable() {
+
+ @Override
+ public void run() {
+ Object value = valueFactory.createObject(createInstanceButton, context);
+ if(value == null) {
+ return;
+ }
+ Collection<Object> validatedObjects = valueFactory.validateObjects(Collections.singleton(value));
+ if(!validatedObjects.isEmpty()) {
+ setValue(validatedObjects.iterator().next());
+ }
+ }
+ }, NLS.bind(Messages.ReferenceDialog_setOperation, labelText));
}
}
@@ -229,13 +240,19 @@ public class ReferenceDialog extends AbstractValueEditor implements SelectionLis
* that is currently selected
*/
protected void editAction() {
- Object currentValue = getValue();
+ final Object currentValue = getValue();
if(currentValue != null && valueFactory != null && valueFactory.canEdit()) {
- Object newValue = valueFactory.edit(editInstanceButton, getValue());
- if(newValue != currentValue) {
- setValue(newValue);
- }
- updateLabel();
+ getOperationExecutor(currentValue).execute(new Runnable() {
+
+ @Override
+ public void run() {
+ Object newValue = valueFactory.edit(editInstanceButton, currentValue);
+ if(newValue != currentValue) {
+ setValue(newValue);
+ }
+ updateLabel();
+ }
+ }, NLS.bind(Messages.ReferenceDialog_editOperation, labelText));
}
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/Messages.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/Messages.java
index 7944870de3e..82dcdde6ce7 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/Messages.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/Messages.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.infra.widgets.messages;
@@ -32,6 +34,10 @@ public class Messages extends NLS {
/** The Multiple value editor_ add elements. */
public static String MultipleValueEditor_AddElements;
+ public static String MultipleValueEditor_addOperation;
+
+ public static String MultipleValueEditor_editOperation;
+
/** The Multiple value editor_ edit selected value */
public static String MultipleValueEditor_EditSelectedValue;
@@ -61,6 +67,8 @@ public class Messages extends NLS {
public static String ReferenceDialog_CreateANewObject;
+ public static String ReferenceDialog_editOperation;
+
public static String ReferenceDialog_EditTheCurrentValue;
/** The Reference dialog_ edit value */
@@ -69,6 +77,8 @@ public class Messages extends NLS {
/** The Reference dialog_ select value */
public static String ReferenceDialog_SelectValue;
+ public static String ReferenceDialog_setOperation;
+
/** The Reference dialog_ unset */
public static String ReferenceDialog_Unset;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties
index a5cdb982258..a9fbdf92c68 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties
@@ -1,8 +1,24 @@
-BooleanInputValidator_NotABoolean=The actual entry is not an Boolean.
+###############################################################################
+# 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
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+# Christian W. Damus (CEA) - bug 402525
+#
+###############################################################################
+
+BooleanInputValidator_NotABoolean=The actual entry is not a Boolean.
IntegerInputValidator_NotAnIntegerMessage=The actual entry is not an Integer.
RealInputValidator_NotaRealMessage=The actual entry is not a Real.
UnlimitedNaturalInputValidator_NotAnUnlimitedNaturalMessage=The actual entry is not an UnlimitedNatural. An UnlimitedNatural must be either -1, * or >= 0
MultipleValueEditor_AddElements=Add elements
+MultipleValueEditor_addOperation=Add {0}
+MultipleValueEditor_editOperation=Edit {0}
MultipleValueEditor_EditSelectedValue=Edit the selected value
MultipleValueEditor_MoveSelectedElementsDown=Move selected elements down
MultipleValueEditor_MoveSelectedElementsUp=Move selected elements up
@@ -13,9 +29,11 @@ MultipleValueSelectorDialog_RemoveAllElements=Remove all elements
MultipleValueSelectorDialog_CreateNewElement=Create a new element
MultipleValueSelectorDialog_DeleteNewElement=Deletes a newly created element
ReferenceDialog_CreateANewObject=Create a new object
+ReferenceDialog_editOperation=Edit {0}
ReferenceDialog_EditTheCurrentValue=Edit the current value
ReferenceDialog_EditValue=Edit the reference value
ReferenceDialog_SelectValue=Select the value for this reference
+ReferenceDialog_setOperation=Set {0}
ReferenceDialog_Unset=<Undefined>
ReferenceDialog_UnsetValue=Unset the reference value
ReferenceDialogObservable_Unchanged=<Unchanged>

Back to the top