Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormvelten2013-04-10 07:16:54 -0400
committermvelten2013-04-10 07:16:54 -0400
commitbc55b6d8785c1f389e3dbe9bd084015483c22f2a (patch)
tree2c62beb335385f1780d7926d2843a8edbc94843f /plugins
parentc502ff6df3a5390031b33ae50d52d038398e0e7c (diff)
downloadorg.eclipse.papyrus-bc55b6d8785c1f389e3dbe9bd084015483c22f2a.tar.gz
org.eclipse.papyrus-bc55b6d8785c1f389e3dbe9bd084015483c22f2a.tar.xz
org.eclipse.papyrus-bc55b6d8785c1f389e3dbe9bd084015483c22f2a.zip
389247: [Palette framework] the current implementation bypass the command framework which brakes undo/redo
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389247 376276: Palette entry should use IPreAction interface https://bugs.eclipse.org/bugs/show_bug.cgi?id=376276
Diffstat (limited to 'plugins')
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java53
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java6
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteAspectToolEntryProxy.java26
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common.palette.customaction/src/org/eclipse/papyrus/uml/diagram/common/palette/customaction/providers/ToolAspectAction.java12
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ApplyStereotypeCommand.java64
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java38
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java185
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java66
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PapyrusPalettePreferences.java13
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/ApplyStereotypeRequest.java42
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeConnectionTool.java240
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeCreationTool.java142
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AbstractPreConditionAction.java169
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AssociationEndPostAction.java132
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java103
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java105
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java88
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/GraphicalPostAction.java92
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IAspectAction.java8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPaletteAspectToolEntryProxy.java7
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPostAction.java32
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPreAction.java24
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ModelPostAction.java11
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/SemanticPostAction.java122
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java172
25 files changed, 929 insertions, 1023 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java
index 92c4440a2d6..d1d3ca29430 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/AspectActionsInformationComposite.java
@@ -11,6 +11,7 @@
*****************************************************************************/
package org.eclipse.papyrus.customization.palette.dialog;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -29,6 +30,7 @@ import org.eclipse.papyrus.uml.diagram.common.Messages;
import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPaletteAspectToolEntryProxy;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
import org.eclipse.swt.SWT;
@@ -164,8 +166,10 @@ public class AspectActionsInformationComposite {
ITreeSelection selection = (ITreeSelection)viewer.getSelection();
if(selection != null && selection.size() > 0) {
for(Object selected : selection.toList()) {
- if(selected instanceof IPostAction && selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().remove(selected);
+ if(selected instanceof IPostAction && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
+ ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().remove(selected);
+ } else if(selected instanceof IPreAction && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
+ ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions().remove(selected);
}
}
}
@@ -196,10 +200,10 @@ public class AspectActionsInformationComposite {
*/
public void mouseUp(MouseEvent e) {
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
- if(selection != null && selection.size() > 0 && selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
+ if(selection != null && selection.size() > 0 && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
IAspectAction action = (IAspectAction)selection.getFirstElement();
- List<IPreAction> initialPreList = ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions();
- List<IPostAction> initialPostList = ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions();
+ List<IPreAction> initialPreList = ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions();
+ List<IPostAction> initialPostList = ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions();
if(action instanceof IPreAction) {
// move from pre action list
@@ -212,9 +216,6 @@ public class AspectActionsInformationComposite {
}
}
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).setPreActions(initialPreList);
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).setPostActions(initialPostList);
-
// update content
viewer.setInput(selectedEntryProxy);
// restore selection
@@ -247,10 +248,10 @@ public class AspectActionsInformationComposite {
*/
public void mouseUp(MouseEvent e) {
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
- if(selection != null && selection.size() > 0 && selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
+ if(selection != null && selection.size() > 0 && selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
IAspectAction action = (IAspectAction)selection.getFirstElement();
- List<IPreAction> initialPreList = ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions();
- List<IPostAction> initialPostList = ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions();
+ List<IPreAction> initialPreList = ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions();
+ List<IPostAction> initialPostList = ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions();
if(action instanceof IPreAction) {
// move from pre action list
@@ -263,9 +264,6 @@ public class AspectActionsInformationComposite {
}
}
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).setPreActions(initialPreList);
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).setPostActions(initialPostList);
-
// update content
viewer.setInput(selectedEntryProxy);
// restore selection
@@ -334,11 +332,11 @@ public class AspectActionsInformationComposite {
public void widgetSelected(SelectionEvent e) {
IAspectActionProvider factory = (IAspectActionProvider)((MenuItem)e.getSource()).getData();
IAspectAction action = factory.createAction(null);
- if(selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
+ if(selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
if(action instanceof IPostAction) {
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().add((IPostAction)action);
- } else {
- ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions().add((IPreAction)action);
+ ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().add((IPostAction)action);
+ } else if(action instanceof IPreAction) {
+ ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions().add((IPreAction)action);
}
setSelectedEntryProxy(selectedEntryProxy);
}
@@ -397,8 +395,12 @@ public class AspectActionsInformationComposite {
handleActionListSelectionChanged(null);
// select first post action
- if(selectedEntryProxy instanceof PaletteAspectToolEntryProxy && ((PaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().size() > 0) {
- viewer.setSelection(new StructuredSelection(((PaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().get(0)), true);
+ if(selectedEntryProxy instanceof IPaletteAspectToolEntryProxy && ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().size() > 0) {
+ viewer.setSelection(new StructuredSelection(((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().get(0)), true);
+ }
+ //select first pre action
+ else if(selectedEntryProxy instanceof IPaletteAspectToolEntryProxy && ((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions().size() > 0) {
+ viewer.setSelection(new StructuredSelection(((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions().get(0)), true);
}
updateButtons();
@@ -409,9 +411,9 @@ public class AspectActionsInformationComposite {
* Call this method to update the buttons enablement.
*/
protected void updateButtons() {
- if(selectedEntryProxy instanceof PaletteAspectToolEntryProxy) {
+ if(selectedEntryProxy instanceof IPaletteAspectToolEntryProxy) {
addActionButton.setEnabled(true);
- if(((PaletteAspectToolEntryProxy)selectedEntryProxy).getAspectActions().size() > 0) {
+ if(((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPreActions().isEmpty() && !((IPaletteAspectToolEntryProxy)selectedEntryProxy).getPostActions().isEmpty()) {
removeActionButton.setEnabled(true);
moveUpActionButton.setEnabled(true);
moveDownActionButton.setEnabled(true);
@@ -438,8 +440,11 @@ public class AspectActionsInformationComposite {
* @{inheritDoc
*/
public Object[] getChildren(Object parentElement) {
- if(parentElement instanceof PaletteAspectToolEntryProxy) {
- return ((PaletteAspectToolEntryProxy)parentElement).getPostActions().toArray();
+ if(parentElement instanceof IPaletteAspectToolEntryProxy) {
+ List<IAspectAction> actions = new ArrayList<IAspectAction>();
+ actions.addAll(((IPaletteAspectToolEntryProxy)parentElement).getPostActions());
+ actions.addAll(((IPaletteAspectToolEntryProxy)parentElement).getPreActions());
+ return actions.toArray();
}
return new Object[0];
}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java
index 33533015f24..8e02014cde3 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteContentPage.java
@@ -1994,6 +1994,12 @@ public class LocalPaletteContentPage extends WizardPage implements Listener {
action.save(postActionNode);
element.appendChild(postActionNode);
}
+ for(IAspectAction action : ((PaletteAspectToolEntryProxy)containerProxy).getPreActions()) {
+ Element preActionNode = document.createElement(IPapyrusPaletteConstant.PRE_ACTION);
+ preActionNode.setAttribute(IPapyrusPaletteConstant.ID, action.getFactoryId());
+ action.save(preActionNode);
+ element.appendChild(preActionNode);
+ }
}
default:
break;
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteAspectToolEntryProxy.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteAspectToolEntryProxy.java
index 0a2f8f5e657..f19a2852d2f 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteAspectToolEntryProxy.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PaletteAspectToolEntryProxy.java
@@ -17,17 +17,15 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPaletteAspectToolEntryProxy;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypePostAction;
import org.eclipse.swt.graphics.Image;
-import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
@@ -41,7 +39,6 @@ public class PaletteAspectToolEntryProxy extends PaletteEntryProxy implements IP
/** list of pre actions executed by the tool */
protected List<IPreAction> preActions = new ArrayList<IPreAction>();
-
/**
* Creates a new {@link PaletteAspectToolEntryProxy}
*
@@ -81,7 +78,7 @@ public class PaletteAspectToolEntryProxy extends PaletteEntryProxy implements IP
*
* @return the list of pre actions attached to this {@link PaletteAspectToolEntryProxy}
*/
- protected List<IPreAction> getPreActions() {
+ public List<IPreAction> getPreActions() {
return preActions;
}
@@ -115,25 +112,8 @@ public class PaletteAspectToolEntryProxy extends PaletteEntryProxy implements IP
protected void initAspectActions() {
Object value = getEntry().getAspectProperties(IPapyrusPaletteConstant.ASPECT_ACTION_KEY);
if(value instanceof NodeList) {
- NodeList nodeList = ((NodeList)value);
- for(int i = 0; i < nodeList.getLength(); i++) {
- Node childNode = nodeList.item(i);
- String childName = childNode.getNodeName();
- if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
- // node is a post action => retrieve the id of the factory in charge of this configuration
- IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
- if(provider != null) {
- IPostAction action = (IPostAction)provider.createAction(childNode);
- postActions.add(action);
- } else {
- Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
- }
- } else if(IPapyrusPaletteConstant.PRE_ACTION.equals(childName)) {
- // no implementation yet
- }
- }
+ PaletteUtil.initAspectActions((NodeList)value, postActions, preActions);
}
-
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common.palette.customaction/src/org/eclipse/papyrus/uml/diagram/common/palette/customaction/providers/ToolAspectAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common.palette.customaction/src/org/eclipse/papyrus/uml/diagram/common/palette/customaction/providers/ToolAspectAction.java
index b00e0943c80..1b0e92e1ae6 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common.palette.customaction/src/org/eclipse/papyrus/uml/diagram/common/palette/customaction/providers/ToolAspectAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common.palette.customaction/src/org/eclipse/papyrus/uml/diagram/common/palette/customaction/providers/ToolAspectAction.java
@@ -16,10 +16,12 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.papyrus.uml.diagram.common.palette.customaction.Activator;
import org.eclipse.papyrus.uml.diagram.common.palette.customaction.control.ToolSelectionComposite;
import org.eclipse.papyrus.uml.diagram.common.palette.customaction.utils.ICallback;
@@ -116,8 +118,16 @@ public class ToolAspectAction extends ModelPostAction implements
}
}
+ public ICommand getPostCommand(IAdaptable viewAdapter) {
+ return null;
+ }
+
+ public boolean needsPostCommitRun() {
+ return true;
+ }
+
@Override
- public void run(EditPart editPart) {
+ public void runInPostCommit(EditPart editPart) {
ITool tool = selection.getCreator().create(editPart);
tool.run(editPart);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ApplyStereotypeCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ApplyStereotypeCommand.java
new file mode 100644
index 00000000000..c72f9e21fe8
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ApplyStereotypeCommand.java
@@ -0,0 +1,64 @@
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.helper.NamedElementHelper;
+import org.eclipse.papyrus.uml.diagram.common.service.ApplyStereotypeRequest;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Stereotype;
+
+
+public class ApplyStereotypeCommand extends AbstractTransactionalCommand {
+
+ protected ApplyStereotypeRequest req;
+
+ public ApplyStereotypeCommand(TransactionalEditingDomain domain, ApplyStereotypeRequest req) {
+ super(domain, "Apply stereotype", null);
+ this.req = req;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // retrieves the list of stereotypes to be applied
+ List<String> stereotypeQNames = req.getStereotypesToApply();
+ Element element = req.getElement();
+ List<EObject> result = new ArrayList<EObject>();
+ for(String stereotypeQName : stereotypeQNames) {
+ // retrieve the stereotype to apply
+ Stereotype stereotype = element.getApplicableStereotype(stereotypeQName);
+ if(stereotype == null) {
+ // stereotype has no been found. should ask for
+ // profile application ?
+ Activator.log.warn("impossible to retrieve the stereotype " + stereotypeQName);
+ } else {
+ result.add(element.applyStereotype(stereotype));
+ }
+ }
+
+ if (req.renameWithFirstStereotype() && element instanceof NamedElement && !stereotypeQNames.isEmpty()) {
+ String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQNames.get(0));
+ // find a new name for the element
+ String name = NamedElementHelper.EINSTANCE.getNewUMLElementName(element.getOwner(), stereotypeName);
+ ((NamedElement)element).setName(name);
+ }
+
+
+ if (result.size() > 1) {
+ return CommandResult.newOKCommandResult(result);
+ } else if (result.size() == 1) {
+ return CommandResult.newOKCommandResult(result.get(0));
+ }
+ return CommandResult.newOKCommandResult();
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java
index 0b21e9b5a75..33045403115 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java
@@ -13,7 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.commands;
-import java.util.Iterator;
+import java.util.Collection;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAnnotation;
@@ -23,9 +23,13 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.commands.CreateEAnnotationCommand;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+
/**
* The Class AddAppliedStereotypeToDisplayCommand used to set the list of
* applied stereotype to display
@@ -35,9 +39,6 @@ public class DefferedAppliedStereotypeToDisplayCommand extends CreateEAnnotation
/** The qualified names' stereotypes list . */
protected String stereotypeList;
- /** the presentation kind of applied stereotypes */
- protected String appliedStereotypePresentationKind;
-
/** adapter on which to apply stereotypes */
protected IAdaptable adapter;
@@ -51,19 +52,10 @@ public class DefferedAppliedStereotypeToDisplayCommand extends CreateEAnnotation
* @param stereotypeList
* the stereotype list
*/
- public DefferedAppliedStereotypeToDisplayCommand(TransactionalEditingDomain domain, IAdaptable adapter, String stereotypeList, String appliedStereotypepresentationKind) {
+ public DefferedAppliedStereotypeToDisplayCommand(TransactionalEditingDomain domain, IAdaptable adapter, String stereotypeList) {
super(domain, null, UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION);
this.adapter = adapter;
this.stereotypeList = stereotypeList;
- this.appliedStereotypePresentationKind = appliedStereotypepresentationKind;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean canUndo() {
- return true;
}
/**
@@ -74,17 +66,13 @@ public class DefferedAppliedStereotypeToDisplayCommand extends CreateEAnnotation
View view = (View)adapter.getAdapter(View.class);
EObject view_element = view.getElement();
Element element = (Element)view_element;
- Iterator<Stereotype> listStereotype = element.getAppliedStereotypes().iterator();
- StringBuffer buffer = new StringBuffer();
- while(listStereotype.hasNext()) {
- Stereotype stereotypec = listStereotype.next();
- String stereotype_string = stereotypec.getQualifiedName();
- buffer.append(stereotype_string);
- if(listStereotype.hasNext()) {
- buffer.append(",");
+ Collection<String> strStereotypes = Collections2.transform(element.getAppliedStereotypes(), new Function<Stereotype, String>() {
+
+ public String apply(Stereotype st) {
+ return st.getQualifiedName();
}
- }
- stereotypeList = buffer.toString();
+ });
+ stereotypeList = PaletteUtil.getSerializedStereotypeList(strStereotypes);
String stereoList = AppliedStereotypeHelper.getStereotypesToDisplay(view);
if(!"".equals(stereoList)) {
@@ -98,7 +86,7 @@ public class DefferedAppliedStereotypeToDisplayCommand extends CreateEAnnotation
}
replaceEntry(oldAnnotation, UMLVisualInformationPapyrusConstant.STEREOTYPE_WITHQN_LIST, AppliedStereotypeHelper.getStereotypesQNToDisplay(view));
replaceEntry(oldAnnotation, UMLVisualInformationPapyrusConstant.STEREOTYPE_LIST, stereoList);
- replaceEntry(oldAnnotation, UMLVisualInformationPapyrusConstant.STEREOTYPE_PRESENTATION_KIND, appliedStereotypePresentationKind);
+ replaceEntry(oldAnnotation, UMLVisualInformationPapyrusConstant.STEREOTYPE_PRESENTATION_KIND, AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view));
replaceEntry(oldAnnotation, UMLVisualInformationPapyrusConstant.PROPERTY_STEREOTYPE_DISPLAY, AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(view));
replaceEntry(oldAnnotation, UMLVisualInformationPapyrusConstant.STEREOTYPE_PROPERTY_LOCATION, AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization(view));
replaceEannotation(view.getEAnnotation(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION), view);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java
index 491543224fc..c7c72d99095 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java
@@ -13,52 +13,20 @@
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.AbstractEditPolicy;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.util.Log;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.common.core.util.Trace;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIDebugOptions;
-import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
-import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIStatusCodes;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.utils.PapyrusTrace;
-import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
+import org.eclipse.papyrus.uml.diagram.common.commands.ApplyStereotypeCommand;
import org.eclipse.papyrus.uml.diagram.common.commands.DefferedAppliedStereotypeToDisplayCommand;
-import org.eclipse.papyrus.uml.diagram.common.editparts.IUMLEditPart;
-import org.eclipse.papyrus.uml.diagram.common.helper.NamedElementHelper;
import org.eclipse.papyrus.uml.diagram.common.service.ApplyStereotypeRequest;
-import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Stereotype;
/**
* Apply Stereotype edit policy.
@@ -81,8 +49,7 @@ public class ApplyStereotypeEditPolicy extends AbstractEditPolicy {
@Override
public Command getCommand(Request request) {
if(understandsRequest(request)) {
- executeCommand(getApplyStereotypeCommand((ApplyStereotypeRequest)request));
- return null;
+ return getApplyStereotypeCommand((ApplyStereotypeRequest)request);
} else
return super.getCommand(request);
}
@@ -98,61 +65,6 @@ public class ApplyStereotypeEditPolicy extends AbstractEditPolicy {
return super.understandsRequest(req);
}
- //
- // /**
- // * {@inheritDoc}
- // */
- // @Override
- // public Command getCommand(Request request) {
- // // command should be a composed command: apply stereotype, display
- // stereotype and eventually
- // // change the name of the semantic element
- // if
- // (ApplyStereotypeRequest.APPLY_STEREOTYPE_REQUEST.equals(request.getType()))
- // return getApplyStereotypeCommand((ApplyStereotypeRequest) request);
- //
- // return super.getCommand(request);
- // }
-
- /**
- * Executes the supplied command inside an <code>unchecked action</code>
- *
- * @param cmd
- * command that can be executed (i.e., cmd.canExecute() == true)
- */
- protected void executeCommand(final Command cmd) {
- Map<String, Boolean> options = null;
- EditPart ep = getHost();
- boolean isActivating = true;
- // use the viewer to determine if we are still initializing the diagram
- // do not use the DiagramEditPart.isActivating since
- // ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = ep.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
-
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)getHost(), false, false))
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
-
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)getHost()).getEditingDomain(), StringStatics.BLANK, options) {
-
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- cmd.execute();
-
- return Status.OK_STATUS;
- }
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "executeCommand", e); //$NON-NLS-1$
- Log.warning(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "executeCommand", e); //$NON-NLS-1$
- }
- }
-
/**
* {@inheritDoc}
*/
@@ -172,102 +84,21 @@ public class ApplyStereotypeEditPolicy extends AbstractEditPolicy {
* @return the command that applies the stereotype or <code>null</code>
*/
protected Command getApplyStereotypeCommand(ApplyStereotypeRequest request) {
- final ApplyStereotypeRequest _request = request;
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain();
CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, "Apply Stereotype");
- final List<EObject> result = new ArrayList<EObject>();
final Element element = (Element)(((View)getHost().getModel()).getElement());
+
+ if (request.getElement() == null) {
+ request.setElement(element);
+ }
// 1. apply stereotypes
- cc.compose(new AbstractTransactionalCommand(editingDomain, "Apply Stereotype", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- // retrieves the edit part on which stereotype request is made
- if(getHost() instanceof IUMLEditPart || ((getHost().getModel() instanceof View) && (((View)getHost().getModel()).getElement()) instanceof Element)) {
- if(element == null) {
- return null;
- }
- // retrieves the list of stereotypes to be applied
- List<String> stereotypeQNames = _request.getStereotypesToApply();
- for(String stereotypeQName : stereotypeQNames) {
- // retrieve the stereotype to apply
- Stereotype stereotype = element.getApplicableStereotype(stereotypeQName);
- if(stereotype == null) {
- // stereotype has no been found. should ask for
- // profile application ?
- PapyrusTrace.log(IStatus.WARNING, "impossible to retrieve the stereotype " + stereotypeQName);
- } else {
- result.add(element.applyStereotype(stereotype));
- }
- }
-
- }
- return CommandResult.newOKCommandResult(result);
- }
- });
-
- // check if the name of base element must be changed (don't bother what
- // is the value of the
- // element, only the key is needed
- Object newName = request.getExtendedData().get(ApplyStereotypeRequest.NEW_EDIT_PART_NAME);
- if(newName != null) {
- cc.compose(new AbstractTransactionalCommand(editingDomain, "Edit Base Element Name", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- // retrieves the edit part on which stereotype request is
- // made
- if(getHost() instanceof IUMLEditPart || ((getHost().getModel() instanceof View) && (((View)getHost().getModel()).getElement()) instanceof Element)) {
- if(!(element instanceof NamedElement)) {
- return null;
- }
-
- // retrieves the list of stereotypes to be applied
- // (qualified names)
- List<String> stereotypeQNames = _request.getStereotypesToApply();
- String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQNames.get(0));
- // find a new name for the element
- String name = NamedElementHelper.EINSTANCE.getNewUMLElementName(element.getOwner(), stereotypeName);
- ((NamedElement)element).setName(name);
-
- }
- return CommandResult.newOKCommandResult(result);
- }
- });
- }
+ cc.compose(new ApplyStereotypeCommand(editingDomain, request));
// 2. display stereotypes
- String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(element);
- // should display real applied stereotypes and not the list of
- // stereotypes to apply...
- cc.compose(new EMFtoGMFCommandWrapper(new DefferedAppliedStereotypeToDisplayCommand(editingDomain, getHost(), "", presentationKind)));
+ cc.compose(new EMFtoGMFCommandWrapper(new DefferedAppliedStereotypeToDisplayCommand(editingDomain, getHost(), "")));
return new ICommandProxy(cc.reduce());
}
- /**
- * Returns the list of stereotypes to display
- *
- * @param request
- * the request that triggers this policy
- * @return the list of stereotypes to display
- */
- public String getStereotypeList(ApplyStereotypeRequest request) {
- // transforms the list of stereotypes in the request into a string
- // corresponding to the
- // string input of the display stereotype command.
- StringBuffer buffer = new StringBuffer();
- Iterator<String> it = request.getStereotypesToApply().iterator();
- while(it.hasNext()) {
- String stereotypeQN = it.next();
- buffer.append(stereotypeQN);
- if(it.hasNext()) {
- buffer.append(", ");
- }
- }
- return buffer.toString();
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java
index 25c630d946e..9d0f41eca2a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java
@@ -40,17 +40,25 @@ import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.SpecializationType;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.utils.PapyrusTrace;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeConnectionTool;
import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
import org.eclipse.papyrus.uml.diagram.common.service.IProfileDependantPaletteProvider;
import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IMemento;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Profile;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* Utility class for palette.
@@ -325,16 +333,8 @@ public class PaletteUtil {
* the list of stereotypes to serialize
* @return the list of stereotypes String under a serialized form
*/
- public static String getSerializedStereotypeListFromList(List<String> list) {
- StringBuffer buffer = new StringBuffer();
- Iterator<String> it = list.listIterator();
- while(it.hasNext()) {
- buffer.append(it.next());
- if(it.hasNext()) {
- buffer.append(",");
- }
- }
- return buffer.toString();
+ public static String getSerializedStereotypeList(Collection<String> stereotypes) {
+ return convertToCommaSeparatedRepresentation(stereotypes);
}
/**
@@ -357,13 +357,21 @@ public class PaletteUtil {
* the list of profiles to serialize
* @return the list of profiles String under a serialized form
*/
- public static String getSerializedProfileListFromSet(Set<String> profiles) {
- StringBuffer buffer = new StringBuffer();
- Iterator<String> it = profiles.iterator();
+ public static String getSerializedProfileList(Collection<String> profiles) {
+ return convertToCommaSeparatedRepresentation(profiles);
+ }
+
+ public static String convertToCommaSeparatedRepresentation(Collection objects) {
+ return convertToFlatRepresentation(objects, ",");
+ }
+
+ public static String convertToFlatRepresentation(Collection objects, String separator) {
+ StringBuilder buffer = new StringBuilder();
+ Iterator it = objects.iterator();
while(it.hasNext()) {
buffer.append(it.next());
if(it.hasNext()) {
- buffer.append(",");
+ buffer.append(separator);
}
}
return buffer.toString();
@@ -457,4 +465,34 @@ public class PaletteUtil {
return true;
}
+ public static void initAspectActions(NodeList aspectActionNodes, List<IPostAction> postActions, List<IPreAction> preActions) {
+ for(int i = 0; i < aspectActionNodes.getLength(); i++) {
+ Node childNode = aspectActionNodes.item(i);
+ String childName = childNode.getNodeName();
+ if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
+ // node is a post action => retrieve the id of the factory in charge of this configuration
+ IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
+ if(provider != null) {
+ IAspectAction action = provider.createAction(childNode);
+ if (action instanceof IPostAction) {
+ postActions.add((IPostAction)action);
+ }
+ } else {
+ Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
+ }
+ } else if(IPapyrusPaletteConstant.PRE_ACTION.equals(childName)) {
+ // node is a pre action => retrieve the id of the factory in charge of this configuration
+ IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
+ if(provider != null) {
+ IAspectAction action = provider.createAction(childNode);
+ if (action instanceof IPreAction) {
+ preActions.add((IPreAction)action);
+ }
+ } else {
+ Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
+ }
+ }
+ }
+ }
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PapyrusPalettePreferences.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PapyrusPalettePreferences.java
index c0c33d0e35a..11445bc7896 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PapyrusPalettePreferences.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PapyrusPalettePreferences.java
@@ -17,7 +17,6 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
@@ -403,15 +402,7 @@ public class PapyrusPalettePreferences implements IPapyrusPaletteConstant {
*/
protected static String serializeHiddenPalettes(List<String> hiddenPalettes) {
// builds the new id list
- StringBuffer buffer = new StringBuffer();
- Iterator<String> it = hiddenPalettes.iterator();
- while(it.hasNext()) {
- buffer.append(it.next());
- if(it.hasNext()) {
- buffer.append(";");
- }
- }
- return buffer.toString();
+ return PaletteUtil.convertToFlatRepresentation(hiddenPalettes, ";");
}
/**
@@ -458,7 +449,7 @@ public class PapyrusPalettePreferences implements IPapyrusPaletteConstant {
// add properties if required
IMemento propertiesMemento = paletteMemento.createChild(IPapyrusPaletteConstant.PALETTE_DESCRIPTION_PROPERTIES);
- propertiesMemento.putString(IPapyrusPaletteConstant.PROFILE_LIST, PaletteUtil.getSerializedProfileListFromSet(requiredProfiles));
+ propertiesMemento.putString(IPapyrusPaletteConstant.PROFILE_LIST, PaletteUtil.getSerializedProfileList(requiredProfiles));
// saves the root memento
saveLocalPalettes(rootMemento);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/ApplyStereotypeRequest.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/ApplyStereotypeRequest.java
index b477b03dfa4..d01f2721940 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/ApplyStereotypeRequest.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/ApplyStereotypeRequest.java
@@ -15,7 +15,10 @@ package org.eclipse.papyrus.uml.diagram.common.service;
import java.util.List;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.uml2.uml.Element;
/**
* Request to apply stereotype on elements
@@ -25,12 +28,16 @@ public class ApplyStereotypeRequest extends CreateRequest {
/** type of the Apply stereotype request */
public static String APPLY_STEREOTYPE_REQUEST = "applyStereotype";
- /** key for the new edit part name base extended metadata */
- public static String NEW_EDIT_PART_NAME = "editPartNameBase";
-
/** stereotypes to apply */
final protected List<String> stereotypes;
+ protected IAdaptable viewAdapter;
+
+ protected Element element;
+
+ protected boolean renameWithFirstStereotype;
+
+
/**
* Creates a new ApplyStereotypeRequest
*
@@ -38,9 +45,18 @@ public class ApplyStereotypeRequest extends CreateRequest {
* the list of stereotypes to apply, identified by their
* qualified names
*/
- public ApplyStereotypeRequest(List<String> stereotypes) {
+ public ApplyStereotypeRequest(IAdaptable viewAdapter, List<String> stereotypes, boolean renameWithFirstStereotype) {
super();
this.stereotypes = stereotypes;
+ this.viewAdapter = viewAdapter;
+ this.renameWithFirstStereotype = renameWithFirstStereotype;
+ // initialize the type of this request
+ setType(APPLY_STEREOTYPE_REQUEST);
+ }
+
+ public ApplyStereotypeRequest(Element element, List<String> stereotypes) {
+ this.stereotypes = stereotypes;
+ this.element = element;
// initialize the type of this request
setType(APPLY_STEREOTYPE_REQUEST);
}
@@ -55,4 +71,22 @@ public class ApplyStereotypeRequest extends CreateRequest {
public List<String> getStereotypesToApply() {
return stereotypes;
}
+
+ public boolean renameWithFirstStereotype() {
+ return renameWithFirstStereotype;
+ }
+
+ public void setElement(Element elem) {
+ this.element = elem;
+ }
+
+ public Element getElement() {
+ if (element == null && viewAdapter != null) {
+ View view = (View)viewAdapter.getAdapter(View.class);
+ if (view != null && view.getElement() instanceof Element) {
+ element = (Element)view.getElement();
+ }
+ }
+ return element;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeConnectionTool.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeConnectionTool.java
index 8dbf7814d21..611322b3f9e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeConnectionTool.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeConnectionTool.java
@@ -9,17 +9,18 @@
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
* Vincent Lorenzo (CEA LIST)
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - use commands instead of running code in post commit
+ * Philippe ROLAND (Atos) philippe.roland@atos.net - Implemented PreActions
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.service;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
@@ -28,18 +29,22 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateConnectionViewCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedAdapter;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeConnectionRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor;
@@ -48,19 +53,20 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescrip
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.util.INotationType;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Connector;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.preferences.ConnectionToolPreferences;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.layout.LayoutUtils;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -77,7 +83,10 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
// protected List elementTypes;
/** post action list */
- protected List<IAspectAction> postActions = new ArrayList<IAspectAction>();
+ protected List<IPostAction> postActions = new ArrayList<IPostAction>();
+
+ /** preaction list */
+ protected List<IPreAction> preActions = new ArrayList<IPreAction>();
/** List of elements to create */
private final List<IElementType> elementTypes;
@@ -143,7 +152,6 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
List<?> selectedEditParts = getCurrentViewer().getSelectedEditParts();
List<EObject> eobjects = new ArrayList<EObject>();
List<NotificationListener> listeners = new ArrayList<NotificationListener>();
- CompoundCommand cmd = new CompoundCommand("Create Links");
DiagramEventBroker eventBroker = null;
final EditPartViewer viewer = getCurrentViewer();
// only attempt to create connection if there are two shapes selected
@@ -178,14 +186,16 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
connectionRequest.setLocation(newLocation[1]);
+ setTargetRequest(connectionRequest);
+
// inits the listener
View eObject = (View)targetEditPart.getAdapter(View.class);
NotificationListener listener = null;
- boolean requiresPostAction = requiresPostAction();
+ boolean requiresPostCommitRun = requiresPostCommitRun();
// adds the listener
- if(requiresPostAction) {
+ if(requiresPostCommitRun) {
// register a listener to have information about element
// creation
// retrieves editing domain
@@ -204,8 +214,8 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
Map<?, ?> map = viewer.getEditPartRegistry();
EditPart editPart = (EditPart)map.get(newValue);
- for(IAspectAction action : postActions) {
- action.run(editPart);
+ for(IPostAction action : postActions) {
+ action.runInPostCommit(editPart);
}
}
};
@@ -224,24 +234,28 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
}
Command command = targetEditPart.getCommand(connectionRequest);
- cmd.add(command);
- }
- }
- setCurrentCommand(cmd);
+ if (command != null) {
+ ICommand completeCommand = getCompleteCommand(command);
- executeCurrentCommand();
+ setCurrentCommand(new ICommandProxy(completeCommand));
+
+ executeCurrentCommand();
+ }
- if(requiresPostAction()) {
- if(eventBroker != null) {
- for(int ii = 0; ii < eobjects.size(); ii++) {
- eventBroker.removeNotificationListener(eobjects.get(ii), listeners.get(ii));
+ if(requiresPostCommitRun) {
+ if(eventBroker != null) {
+ for(int ii = 0; ii < eobjects.size(); ii++) {
+ eventBroker.removeNotificationListener(eobjects.get(ii), listeners.get(ii));
+ }
+ }
}
+
+ selectAddedObject(getCurrentViewer(), DiagramCommandStack.getReturnValues(command));
+
}
}
- selectAddedObject(viewer, DiagramCommandStack.getReturnValues(cmd));
-
setAvoidDeactivation(false);
eraseSourceFeedback();
deactivate();
@@ -249,6 +263,40 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
}
}
+ protected ICommand getCompleteCommand(Command createConnectionCommand) {
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+ CompositeTransactionalCommand compositeCmd = new CompositeTransactionalCommand (editingDomain, "Create Link");
+
+ for(IPreAction preAction : preActions) {
+ if(getTargetRequest() instanceof CreateConnectionRequest) {
+ Object sourceModel = ((CreateConnectionRequest)getTargetRequest()).getSourceEditPart().getModel();
+ Object targetModel = ((CreateConnectionRequest)getTargetRequest()).getTargetEditPart().getModel();
+ if(sourceModel instanceof View && targetModel instanceof View) {
+ ICommand cmd = preAction.getConnectionPreCommand((View)sourceModel, (View)targetModel);
+ if(cmd != null) {
+ compositeCmd.add(cmd);
+ }
+ }
+ }
+ }
+
+ compositeCmd.add(new CommandProxy(createConnectionCommand));
+
+ if (getTargetRequest() instanceof CreateRequest) {
+ CreateUnspecifiedAdapter viewAdapter = new CreateUnspecifiedAdapter();
+ viewAdapter.add((CreateRequest)getTargetRequest());
+
+ for (IPostAction action : postActions) {
+ ICommand cmd = action.getPostCommand(viewAdapter);
+ if (cmd != null) {
+ compositeCmd.add(cmd);
+ }
+ }
+ }
+
+ return compositeCmd;
+ }
+
/**
* {@inheritDoc}
*/
@@ -263,19 +311,19 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
if(getTargetEditPart() == null) {
return false;
}
+
// inits the listener
View eObject = (View)getTargetEditPart().getAdapter(View.class);
DiagramEventBroker eventBroker = null;
NotificationListener listener = null;
- boolean requiresPostAction = requiresPostAction();
+ boolean requiresPostCommitRun = requiresPostCommitRun();
// adds the listener
- if(requiresPostAction) {
+ if(requiresPostCommitRun) {
// register a listener to have information about element creation
// retrieves editing domain
- TransactionalEditingDomain domain;
try {
- domain = EditorUtils.getServiceRegistry().getService(TransactionalEditingDomain.class);
+ TransactionalEditingDomain domain = EditorUtils.getServiceRegistry().getService(TransactionalEditingDomain.class);
eventBroker = DiagramEventBroker.getInstance(domain);
if(eventBroker == null) {
@@ -284,10 +332,10 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
listener = new NotificationListener() {
public void notifyChanged(Notification notification) {
- Edge newValue = (Edge)notification.getNewValue();
+ Connector newValue = (Connector)notification.getNewValue();
EditPart editPart = (EditPart)getCurrentViewer().getEditPartRegistry().get(newValue);
- for(IAspectAction action : postActions) {
- action.run(editPart);
+ for(IPostAction action : postActions) {
+ action.runInPostCommit(editPart);
}
}
};
@@ -300,11 +348,16 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
EditPartViewer viewer = getCurrentViewer();
Command endCommand = getCommand();
- setCurrentCommand(endCommand);
- executeCurrentCommand();
+ if (endCommand != null) {
+ ICommand completeCommand = getCompleteCommand(endCommand);
+
+ setCurrentCommand(new ICommandProxy(completeCommand));
- if(requiresPostAction) {
+ executeCurrentCommand();
+ }
+
+ if(requiresPostCommitRun) {
if(eventBroker != null) {
eventBroker.removeNotificationListener(eObject, listener);
}
@@ -320,12 +373,17 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
}
/**
- * checks if this tool realizes post actions
+ * checks if this tool needs a post commit run
*
- * @return <code>true</code> if post actions must be executed
+ * @return <code>true</code> if post actions need a post commit run
*/
- protected boolean requiresPostAction() {
- return postActions.size() > 0;
+ protected boolean requiresPostCommitRun() {
+ for (IPostAction action : postActions) {
+ if (action.needsPostCommitRun()) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -337,28 +395,11 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
// initialize the pre and post actions
// the value should be a NodeList
if(value instanceof NodeList) {
- NodeList nodeList = ((NodeList)value);
- for(int i = 0; i < nodeList.getLength(); i++) {
- Node childNode = nodeList.item(i);
- String childName = childNode.getNodeName();
- if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
- // node is a post action => retrieve the id of the
- // provider in charge of this configuration
- IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
- if(provider != null) {
- IAspectAction action = provider.createAction(childNode);
- postActions.add(action);
- } else {
- Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
- }
- } else if(IPapyrusPaletteConstant.PRE_ACTION.equals(childName)) {
- // no implementation yet
- }
- }
+ PaletteUtil.initAspectActions((NodeList)value, postActions, preActions);
}
- return;
+ } else {
+ super.applyProperty(key, value);
}
- super.applyProperty(key, value);
}
/**
@@ -384,7 +425,10 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
* A map containing the <code>CreateConnectionRequest</code> for each
* element type.
*/
- private Map requests = new HashMap();
+ private Map<IElementType, CreateConnectionRequest> requests = new HashMap<IElementType, CreateConnectionRequest>();
+
+ /** The result to be returned from which the new views can be retrieved. */
+ private List newObjectList = new ArrayList();
/**
* A flag to indicate if the Modeling Assistant Service should be used
@@ -431,13 +475,43 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
}
/**
+ * See bug 288695
+ *
+ * if there is only one {@link CreateRequest}, returns this {@link CreateRequest#getNewObject()},
+ * else, returns a list containing a single {@link IAdaptable} that delegates to the
+ * {@link CreateRequest#getNewObject()} after the command is executed.
+ * It is safe to use the return {@link IAdaptable} in a {@link DeferredCreateConnectionViewCommand}.
+ */
+ public Object getNewObject() {
+ if (newObjectList.isEmpty()) {
+ if (requests.size() == 1) {
+ Object createRequest = requests.values().iterator().next();
+ if (createRequest instanceof CreateRequest) {
+ newObjectList.add(((CreateRequest)createRequest).getNewObject());
+ }
+ } else if (requests.size() > 1) {
+ /* See bug 288695 */
+ CreateUnspecifiedAdapter adapter = new CreateUnspecifiedAdapter();
+ for (Object request : requests.values()) {
+ if (request instanceof CreateRequest) {
+ adapter.add((CreateRequest)request);
+ }
+ }
+ List<IAdaptable> newObjects = new ArrayList<IAdaptable>();
+ newObjects.add(adapter);
+ return newObjects;
+ }
+ }
+ return newObjectList;
+ }
+
+ /**
* Creates a <code>CreateConnectionRequest</code> for each relationship
* type and adds it to the map of requests.
*/
protected void createRequests() {
- for(Iterator<IElementType> iter = getElementTypes().iterator(); iter.hasNext();) {
- IElementType elementType = iter.next();
- Request request = PapyrusCreateViewRequestFactory.getCreateConnectionRequest(elementType, getPreferencesHint());
+ for(IElementType elementType : (List<IElementType>)getElementTypes()) {
+ CreateConnectionRequest request = PapyrusCreateViewRequestFactory.getCreateConnectionRequest(elementType, getPreferencesHint());
request.setType(getType());
requests.put(elementType, request);
}
@@ -452,16 +526,13 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
*/
@Override
public CreateRequest getRequestForType(IElementType relationshipType) {
- if(requests != null) {
- return (CreateConnectionRequest)requests.get(relationshipType);
- }
- return null;
+ return requests.get(relationshipType);
}
@Override
public void addRequest(IElementType relationshipType, Request request) {
- if(requests != null) {
- requests.put(relationshipType, request);
+ if (request instanceof CreateConnectionRequest) {
+ requests.put(relationshipType, (CreateConnectionRequest)request);
}
}
@@ -472,10 +543,7 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
*/
@Override
public List getAllRequests() {
- if(requests != null) {
- return new ArrayList(requests.values());
- }
- return Collections.EMPTY_LIST;
+ return new ArrayList(requests.values());
}
// /**
@@ -492,11 +560,8 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
*/
@Override
public void setSourceEditPart(EditPart part) {
- if(requests != null) {
- for(Iterator iter = requests.values().iterator(); iter.hasNext();) {
- CreateConnectionRequest request = (CreateConnectionRequest)iter.next();
- request.setSourceEditPart(part);
- }
+ for(CreateConnectionRequest request : requests.values()) {
+ request.setSourceEditPart(part);
}
super.setSourceEditPart(part);
}
@@ -506,11 +571,8 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
*/
@Override
public void setTargetEditPart(EditPart part) {
- if(requests != null) {
- for(Iterator iter = requests.values().iterator(); iter.hasNext();) {
- CreateConnectionRequest request = (CreateConnectionRequest)iter.next();
- request.setTargetEditPart(part);
- }
+ for(CreateConnectionRequest request : requests.values()) {
+ request.setTargetEditPart(part);
}
super.setTargetEditPart(part);
}
@@ -520,11 +582,8 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
*/
@Override
public void setLocation(Point location) {
- if(requests != null) {
- for(Iterator iter = requests.values().iterator(); iter.hasNext();) {
- CreateConnectionRequest request = (CreateConnectionRequest)iter.next();
- request.setLocation(location);
- }
+ for(CreateConnectionRequest request : requests.values()) {
+ request.setLocation(location);
}
super.setLocation(location);
}
@@ -534,11 +593,8 @@ public class AspectUnspecifiedTypeConnectionTool extends UnspecifiedTypeConnecti
*/
@Override
public void setType(Object type) {
- if(requests != null) {
- for(Iterator iter = requests.values().iterator(); iter.hasNext();) {
- CreateConnectionRequest request = (CreateConnectionRequest)iter.next();
- request.setType(type);
- }
+ for(CreateConnectionRequest request : requests.values()) {
+ request.setType(type);
}
super.setType(type);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeCreationTool.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeCreationTool.java
index afa62d2b560..77838853616 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeCreationTool.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AspectUnspecifiedTypeCreationTool.java
@@ -8,6 +8,8 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - use commands instead of running code in post commit
+ * Philippe ROLAND (Atos) philippe.roland@atos.net - Implemented PreActions
*
*****************************************************************************/
@@ -15,23 +17,24 @@ package org.eclipse.papyrus.uml.diagram.common.service;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedAdapter;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor;
@@ -39,6 +42,7 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.diagram.ui.util.INotationType;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
@@ -47,10 +51,10 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IFeatureSetterAspectAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
import org.w3c.dom.NodeList;
/**
@@ -64,7 +68,10 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
protected List<IElementType> elementTypes;
/** post action list */
- protected List<IAspectAction> postActions = new ArrayList<IAspectAction>();
+ protected List<IPostAction> postActions = new ArrayList<IPostAction>();
+
+ /** preaction list */
+ protected List<IPreAction> preActions = new ArrayList<IPreAction>();
private static String ID_ASPECT_ACTION = "palette_aspect_actions" ;
@@ -86,12 +93,12 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
@Override
protected void performCreation(int button) {
antiScroll = true;
- boolean requiresPostAction = requiresPostAction();
+ boolean requiresPostCommitRun = requiresPostCommitRun();
// EObject to listen
View eObject = (View)getTargetEditPart().getAdapter(View.class);
DiagramEventBroker eventBroker = null;
NotificationListener listener = null;
- if(requiresPostAction) {
+ if(requiresPostCommitRun) {
// register a listener to have information about element creation
// retrieves editing domain
TransactionalEditingDomain domain;
@@ -113,8 +120,8 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
if(viewer != null) {
EditPart editPart = (EditPart)getCurrentViewer().getEditPartRegistry().get(newValue);
- for(IAspectAction action : postActions) {
- action.run(editPart);
+ for(IPostAction action : postActions) {
+ action.runInPostCommit(editPart);
}
} else {
Activator.log.error("Impossible to find the current viewer", null);
@@ -128,28 +135,68 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
}
}
- EditPartViewer viewer = getCurrentViewer();
- Command c = getCurrentCommand();
- executeCurrentCommand();
+ Command command = getCurrentCommand();
+
+ if(command != null) {
+ ICommand completeCommand = getCompleteCommand(command);
+
+ setCurrentCommand(new ICommandProxy(completeCommand));
+
+ executeCurrentCommand();
+ }
- if(requiresPostAction) {
+ if(requiresPostCommitRun) {
if(eventBroker != null) {
eventBroker.removeNotificationListener(eObject, listener);
}
}
- selectAddedObject(viewer, DiagramCommandStack.getReturnValues(c));
+ selectAddedObject(getCurrentViewer(), DiagramCommandStack.getReturnValues(command));
antiScroll = false;
}
+ protected ICommand getCompleteCommand(Command createCommand) {
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+ CompositeTransactionalCommand compositeCmd = new CompositeTransactionalCommand(editingDomain, "Create Element");
+
+ for(IPreAction preAction : preActions) {
+ Object context = getTargetEditPart().getModel();
+ if(context instanceof View) {
+ ICommand cmd = preAction.getNodePreCommand((View)context);
+ if(cmd != null) {
+ compositeCmd.add(cmd);
+ }
+ }
+ }
+
+ compositeCmd.add(new CommandProxy(createCommand));
+
+ CreateUnspecifiedAdapter viewAdapter = new CreateUnspecifiedAdapter();
+ viewAdapter.add(getCreateRequest());
+
+ for(IPostAction action : postActions) {
+ ICommand cmd = action.getPostCommand(viewAdapter);
+ if(cmd != null) {
+ compositeCmd.add(cmd);
+ }
+ }
+
+ return compositeCmd;
+ }
+
/**
- * checks if this tool realizes post actions
+ * checks if this tool needs a post commit run
*
- * @return <code>true</code> if post actions must be executed
+ * @return <code>true</code> if post actions need a post commit run
*/
- protected boolean requiresPostAction() {
- return postActions.size() > 0;
+ protected boolean requiresPostCommitRun() {
+ for(IPostAction action : postActions) {
+ if(action.needsPostCommitRun()) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -161,30 +208,11 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
// initialize the pre and post actions
// the value should be a NodeList
if(value instanceof NodeList) {
- NodeList nodeList = ((NodeList)value);
- for(int i = 0; i < nodeList.getLength(); i++) {
- org.w3c.dom.Node childNode = nodeList.item(i);
- String childName = childNode.getNodeName();
- if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
- // node is a post action => retrieve the id of the
- // factory in charge of this configuration
- // node is a post action => retrieve the id of the
- // provider in charge of this configuration
- IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
- if(provider != null) {
- IAspectAction action = provider.createAction(childNode);
- postActions.add(action);
- } else {
- Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
- }
- } else if(IPapyrusPaletteConstant.PRE_ACTION.equals(childName)) {
- // no implementation yet
- }
- }
+ PaletteUtil.initAspectActions((NodeList)value, postActions, preActions);
}
- return;
+ } else {
+ super.applyProperty(key, value);
}
- super.applyProperty(key, value);
}
/**
@@ -218,32 +246,6 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
return (List<IAspectAction>) (map == null ? Collections.emptyList() : map.get(ID_ASPECT_ACTION));
}
- public String createPrePostActionRepresentation ()
- {
- StringBuffer buffer = new StringBuffer();
- boolean flag = false ;
- for (IAspectAction post : postActions)
- {
- if (post instanceof IFeatureSetterAspectAction) {
- IFeatureSetterAspectAction featureSetter = (IFeatureSetterAspectAction) post;
- if (flag)
- {
- buffer.append("|");
- for (EStructuralFeature f : featureSetter.getAllImpactedFeatures()) {
- EClass eClass = f.eClass();
- buffer.append(eClass.getEPackage().getNsURI());
- buffer.append(",");
- buffer.append(eClass.getName());
- buffer.append(",");
- buffer.append(f.getName());
- }
- }
- flag = true ;
- }
- }
- return buffer.toString();
- }
-
public class CreateAspectUnspecifiedTypeRequest extends CreateUnspecifiedTypeRequest {
/**
@@ -262,9 +264,7 @@ public class AspectUnspecifiedTypeCreationTool extends UnspecifiedTypeCreationTo
*/
@Override
protected void createRequests() {
- for(Iterator<IElementType> iter = elementTypes.iterator(); iter.hasNext();) {
- IElementType elementType = iter.next();
-
+ for(IElementType elementType : (List<IElementType>)getElementTypes()) {
Request request = null;
if(elementType instanceof INotationType) {
ViewDescriptor viewDescriptor = new ViewDescriptor(null, Node.class, ((INotationType)elementType).getSemanticHint(), getPreferencesHint());
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AbstractPreConditionAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AbstractPreConditionAction.java
new file mode 100644
index 00000000000..aae6bdb1233
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AbstractPreConditionAction.java
@@ -0,0 +1,169 @@
+/*****************************************************************************
+ * Copyright (c) 2012 Atos
+ *
+ * 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:
+ * Philippe ROLAND (Atos) philippe.roland@atos.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.service.palette;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.w3c.dom.Node;
+
+/**
+ * Abstract aspect action class for preconditions
+ *
+ * @author proland
+ */
+public abstract class AbstractPreConditionAction implements IPreAction {
+
+ /** factory used to create this action */
+ protected IAspectActionProvider factory;
+
+ /**
+ * @{inheritDoc
+ */
+ public void init(Node configurationNode, IAspectActionProvider factory) {
+ this.factory = factory;
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ public Image getImage() {
+ return factory.getImage();
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ public String getLabel() {
+ return factory.getName();
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ public String getFactoryId() {
+ return factory.getFactoryId();
+ }
+
+ public IStatus checkPostCondition() {
+ //Do nothing
+ return null;
+ }
+
+ public IStatus checkPreCondition() {
+ //Do nothing; this is already covered by the command itself,
+ //which can return an Unexecutable command
+ return null;
+ }
+
+ public ICommand getConnectionPreCommand(View sourceView, View targetView) {
+ List<IStatus> preConditionStatusList = checkConnectionPreCondition(sourceView, targetView);
+ return handlePreconditionFailure(preConditionStatusList);
+ }
+
+ /**
+ * Check the preCondition
+ *
+ * @param sourceView
+ * the future connection's source's View
+ * @param targetView
+ * the future connection's target's View
+ * @return
+ */
+ protected abstract List<IStatus> checkConnectionPreCondition(View sourceView, View targetView);
+
+ public ICommand getNodePreCommand(View containerView) {
+ List<IStatus> preConditionStatusList = checkNodePreCondition(containerView);
+ return handlePreconditionFailure(preConditionStatusList);
+ }
+
+ /**
+ * Check the preCondition
+ *
+ * @param containerView
+ * the future node's container's View
+ * @return
+ */
+ protected abstract List<IStatus> checkNodePreCondition(View containerView);
+
+ /**
+ * If the precondition check fails, call this method. It generates an appropiate log window and offers the user to continue regardless if
+ * allowContinue() returns true
+ *
+ * @param preConditionStatusList
+ * the list of IStatus resulting from the precondition check
+ * @return the appropriate command; null if no problems were encountered or the user chose to continue, UnexecutableCommand otherwise.
+ */
+ protected ICommand handlePreconditionFailure(List<IStatus> preConditionStatusList) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("The following precondition(s) failed with the error messages:");
+ boolean failed = false;
+ for(IStatus status : preConditionStatusList) {
+ if(!status.isOK()) {
+ stringBuilder.append("\n\r\n\r" + status.getMessage());
+ failed = true;
+ }
+ }
+
+ if(failed) {
+ //If this precondition allows the user to continue regardless
+ if(allowContinue()) {
+ stringBuilder.append("\n\r\n\rDo you wish to continue?");
+
+ //attempts to use NotificationBuilder cause the transaction to fail for reasons yet unknown (a rollback causes the view's element to be unset,
+ //prompting NPEs in following postActions. See commented code below)
+ MessageBox dialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
+ dialog.setText("Precondition failure");
+ dialog.setMessage(stringBuilder.toString());
+ int returnCode = dialog.open();
+ if(returnCode == SWT.OK) {
+ return null;
+ }
+
+ /** XXX This is cleaner and allows for the use of html tags for improved readability, but causes errors */
+ // NotificationBuilder builder = NotificationBuilder
+ // .createYesNo(stringBuilder.toString())
+ // .setHTML(true)
+ // .setMessage(stringBuilder.toString());
+ // INotification notification = builder.run();
+ // if(notification instanceof PopupNotification) {
+ // PopupNotification popupNotification = (PopupNotification)notification;
+ // if(popupNotification.getResult() == SWT.YES) {
+ // return null;
+ // }
+ // }
+ return new UnexecutableCommand(Status.CANCEL_STATUS);
+ } else {
+ MessageBox dialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
+ dialog.setText("Precondition failure");
+ dialog.setMessage(stringBuilder.toString());
+ dialog.open();
+ return new UnexecutableCommand(Status.CANCEL_STATUS);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return true if this preCondition should allow the user to continue even if it returns false
+ */
+ protected abstract boolean allowContinue();
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AssociationEndPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AssociationEndPostAction.java
index bf56ab3a48f..0e3e9db3099 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AssociationEndPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/AssociationEndPostAction.java
@@ -13,32 +13,23 @@ package org.eclipse.papyrus.uml.diagram.common.service.palette;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.helper.AssociationHelper;
import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
@@ -202,88 +193,61 @@ public class AssociationEndPostAction extends ModelPostAction {
/**
* {@inheritDoc}
*/
- public void run(EditPart editPart) {
+ public ICommand getPostCommand(final IAdaptable viewAdapter) {
- final CompositeCommand compositeCommand = new CompositeCommand("Modify Association End");
- EObject objectToEdit = ((View)editPart.getModel()).getElement();
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
- // object to edit should be an association...
- if(objectToEdit instanceof Association) {
- for(PropertyEndConfiguration configuration : configurations) {
+ return new AbstractTransactionalCommand(editingDomain, "Modify Association End", null) {
- // retrieve Property... more tests to do!!
- Property property = ((Association)objectToEdit).getMemberEnds().get(configuration.getIndex());
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ View view = (View)viewAdapter.getAdapter(View.class);
- if(!("".equals(configuration.getOwner()))) {
- // change the owner to the specified one
- IUndoableOperation operation = AssociationHelper.createSetOwnerCommand((Association)objectToEdit, property, CLASS_OWNER.equals(configuration.getOwner()));
- if(operation != null) {
- compositeCommand.compose(operation);
- }
- }
+ if(view != null && view.getElement() instanceof Association) {
+ EObject objectToEdit = view.getElement();
- if(!("".equals(configuration.getAggregationKind()))) {
- // change the aggregation kind
- AggregationKind aggregationKind = AggregationKind.get(configuration.getAggregationKind());
- compositeCommand.compose(AssociationHelper.createSetAggregationCommand(property, aggregationKind));
- }
+ for(PropertyEndConfiguration configuration : configurations) {
- if(!("".equals(configuration.getMultiplicity()))) {
- // change the aggregation kind
- String multiplicity = configuration.getMultiplicity();
- try {
- int[] values = MultiplicityElementUtil.parseMultiplicity(multiplicity);
- if(values.length == 2) {
- compositeCommand.compose(AssociationHelper.createSetMultiplicityCommand(property, values[0], values[1]));
- }
- } catch (NumberFormatException e) {
- Activator.log.error("Multiplicity [" + multiplicity + "] can not be parsed", e);
- }
- }
-
- if(!("".equals(configuration.getNavigation()))) {
- String navigation = configuration.getNavigation();
- boolean isNavigable = NAVIGABLE_YES.equals(navigation);
- compositeCommand.compose(AssociationHelper.createSetNavigableCommand(((Association)objectToEdit), property, isNavigable));
- }
- }
- }
-
- compositeCommand.reduce();
-
- if(compositeCommand.canExecute()) {
- boolean isActivating = true;
- Map<String, Boolean> options = null;
- // use the viewer to determine if we are still initializing the
- // diagram
- // do not use the DiagramEditPart.isActivating since
- // ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = editPart.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
+ // retrieve Property... more tests to do!!
+ Property property = ((Association)objectToEdit).getMemberEnds().get(configuration.getIndex());
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)editPart, false, false)) {
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
- }
-
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), StringStatics.BLANK, options) {
+ if(!("".equals(configuration.getOwner()))) {
+ // change the owner to the specified one
+ IUndoableOperation operation = AssociationHelper.createSetOwnerCommand((Association)objectToEdit, property, CLASS_OWNER.equals(configuration.getOwner()));
+ if(operation != null && operation.canExecute()) {
+ operation.execute(null, null);
+ }
+ }
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ if(!("".equals(configuration.getAggregationKind()))) {
+ // change the aggregation kind
+ AggregationKind aggregationKind = AggregationKind.get(configuration.getAggregationKind());
+ AssociationHelper.createSetAggregationCommand(property, aggregationKind).execute(null, null);
+ }
- compositeCommand.execute(monitor, info);
+ if(!("".equals(configuration.getMultiplicity()))) {
+ // change the aggregation kind
+ String multiplicity = configuration.getMultiplicity();
+ try {
+ int[] values = MultiplicityElementUtil.parseMultiplicity(multiplicity);
+ if(values.length == 2) {
+ AssociationHelper.createSetMultiplicityCommand(property, values[0], values[1]).execute(null, null);
+ }
+ } catch (NumberFormatException e) {
+ Activator.log.error("Multiplicity [" + multiplicity + "] can not be parsed", e);
+ }
+ }
- return Status.OK_STATUS;
+ if(!("".equals(configuration.getNavigation()))) {
+ String navigation = configuration.getNavigation();
+ boolean isNavigable = NAVIGABLE_YES.equals(navigation);
+ AssociationHelper.createSetNavigableCommand(((Association)objectToEdit), property, isNavigable).execute(null, null);
+ }
+ }
}
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
+ return CommandResult.newOKCommandResult();
}
- }
-
+ };
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java
index bd447c91f1a..a4dfa8bd24b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java
@@ -12,30 +12,17 @@
package org.eclipse.papyrus.uml.diagram.common.service.palette;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EModelElement;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.common.Activator;
@@ -48,7 +35,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.uml2.uml.Profile;
import org.w3c.dom.Element;
@@ -152,70 +138,23 @@ public class ChangeStereotypeDisplayPostAction extends GraphicalPostAction {
* @{inheritDoc
*/
@Override
- public void run(final EditPart editPart) {
-
- final CompositeCommand compositeCommand = new CompositeCommand("Modify Stereotype Display");
- // View view = (View)editPart.getModel();
-
- final EModelElement view = (EModelElement)((GraphicalEditPart)editPart).getModel();
- final TransactionalEditingDomain editingDomain = org.eclipse.papyrus.infra.core.utils.EditorUtils.getTransactionalEditingDomain();
- try {
- editingDomain.runExclusive(new Runnable() {
-
- public void run() {
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
-
- String stereotypetoDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(view);
- final RecordingCommand command = AppliedStereotypeHelper.getAppliedStereotypeToDisplayCommand(editingDomain, view, stereotypetoDisplay, displayKind);
- compositeCommand.compose(new EMFtoGMFCommandWrapper(command));
- compositeCommand.reduce();
-
- if(compositeCommand.canExecute()) {
- boolean isActivating = true;
- Map<String, Boolean> options = null;
- // use the viewer to determine if we are still
- // initializing the diagram
- // do not use the DiagramEditPart.isActivating
- // since ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = editPart.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
-
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)editPart, false, false)) {
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
- }
-
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), StringStatics.BLANK, options) {
-
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- editingDomain.getCommandStack().execute(command);
-
- return Status.OK_STATUS;
- }
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
- }
- } else {
- Activator.log.error("Impossible to execute graphical post action " + propertiesToUpdate, null);
- }
- }
- });
+ public ICommand getPostCommand(final IAdaptable viewAdapter) {
+
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+ return new AbstractTransactionalCommand(editingDomain, "Modify Stereotype Display", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ View view = (View)viewAdapter.getAdapter(View.class);
+
+ if(view != null) {
+ String stereotypetoDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(view);
+ AppliedStereotypeHelper.getAppliedStereotypeToDisplayCommand(editingDomain, view, stereotypetoDisplay, displayKind).execute();
}
-
- });
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ return null;
+ }
+ };
+
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java
index e0e2691b335..130073a3caa 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java
@@ -12,28 +12,16 @@
package org.eclipse.papyrus.uml.diagram.common.service.palette;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
@@ -45,9 +33,8 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
@@ -157,74 +144,36 @@ public class DisplayAppliedStereotypePostAction extends GraphicalPostAction {
/**
* @{inheritDoc
*/
- @Override
- public void run(EditPart editPart) {
-
- final CompositeCommand compositeCommand = new CompositeCommand("Modify Stereotype Display");
- View view = (View)editPart.getModel();
- TransactionalEditingDomain editingDomain = org.eclipse.papyrus.infra.core.utils.EditorUtils.getTransactionalEditingDomain();
-
- // creates the commands to display simple stereotypes name
- for(String stereotypeName : stereotypesToDisplay) {
- String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);
- RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypeCommand(editingDomain, view, stereotypeName, presentationKind);
- compositeCommand.add(new EMFtoGMFCommandWrapper(command));
- }
-
- // creates the commands to display qualified names of stereotypes
- for(String stereotypeName : stereotypesQNToDisplay) {
- RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypeToDisplayWithQNCommand(editingDomain, view, stereotypeName);
- compositeCommand.add(new EMFtoGMFCommandWrapper(command));
- }
-
- org.eclipse.uml2.uml.Element element = (org.eclipse.uml2.uml.Element)((View)editPart.getModel()).getElement();
- for(Stereotype stereo : element.getAppliedStereotypes()) {
- if(!stereotypesQNToDisplay.contains(stereo.getQualifiedName()) && !stereotypesToDisplay.contains(stereo.getQualifiedName())) {
- String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);
- RecordingCommand command = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(editingDomain, view, stereo.getQualifiedName(), presentationKind);
- compositeCommand.add(new EMFtoGMFCommandWrapper(command));
- }
- }
+ public ICommand getPostCommand(final IAdaptable viewAdapter) {
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
- compositeCommand.reduce();
-
- // AppliedStereotypeHelper.ge
-
- if(compositeCommand.canExecute()) {
- boolean isActivating = true;
- Map<String, Boolean> options = null;
- // use the viewer to determine if we are still initializing the
- // diagram
- // do not use the DiagramEditPart.isActivating since
- // ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = editPart.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
-
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)editPart, false, false)) {
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
- }
+ return new AbstractTransactionalCommand(editingDomain, "Modify Stereotype Display", null) {
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), StringStatics.BLANK, options) {
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ View view = (View)viewAdapter.getAdapter(View.class);
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // creates the commands to display simple stereotypes name
+ for(String stereotypeName : stereotypesToDisplay) {
+ String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);
+ AppliedStereotypeHelper.getAddAppliedStereotypeCommand(editingDomain, view, stereotypeName, presentationKind).execute();
+ }
- compositeCommand.execute(monitor, info);
+ // creates the commands to display qualified names of stereotypes
+ for(String stereotypeName : stereotypesQNToDisplay) {
+ AppliedStereotypeHelper.getAddAppliedStereotypeToDisplayWithQNCommand(editingDomain, view, stereotypeName).execute();
+ }
- return Status.OK_STATUS;
+ org.eclipse.uml2.uml.Element element = (org.eclipse.uml2.uml.Element)view.getElement();
+ for(Stereotype stereo : element.getAppliedStereotypes()) {
+ if(!stereotypesQNToDisplay.contains(stereo.getQualifiedName()) && !stereotypesToDisplay.contains(stereo.getQualifiedName())) {
+ String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);
+ AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(editingDomain, view, stereo.getQualifiedName(), presentationKind).execute();
+ }
}
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
+ return CommandResult.newOKCommandResult();
}
- } else {
- Activator.log.error("Impossible to execute graphical post action " + propertiesToUpdate, null);
- }
+ };
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java
index ce5ac877fda..4c6faa016b3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java
@@ -12,10 +12,8 @@
package org.eclipse.papyrus.uml.diagram.common.service.palette;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -23,20 +21,10 @@ import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
@@ -45,10 +33,11 @@ import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -143,58 +132,23 @@ public class DisplayAppliedStereotypePropertiesInCompartmentPostAction extends G
* @{inheritDoc
*/
@Override
- public void run(EditPart editPart) {
- final CompositeCommand compositeCommand = new CompositeCommand("Modify Stereotype Properties Display");
- View view = (View)editPart.getModel();
- TransactionalEditingDomain editingDomain = org.eclipse.papyrus.infra.core.utils.EditorUtils.getTransactionalEditingDomain();
- // create commands for properties
- StringBuffer buffer = new StringBuffer();
- Iterator<String> it = listOfDisplayableStereotypeProperties.iterator();
- while(it.hasNext()) {
- String value = it.next();
- buffer.append(value);
- if(it.hasNext()) {
- buffer.append(",");
- }
- }
- RecordingCommand propertyCommand = AppliedStereotypeHelper.getAddAppliedStereotypePropertiesCommand(editingDomain, view, buffer.toString());
- compositeCommand.add(new EMFtoGMFCommandWrapper(propertyCommand));
-
- RecordingCommand stereotypeCommand = AppliedStereotypeHelper.getAppliedStereotypeToDisplayCommand(editingDomain, view, "", UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION) ;
- compositeCommand.add(new EMFtoGMFCommandWrapper(stereotypeCommand));
-
- compositeCommand.reduce();
- if(compositeCommand.canExecute()) {
- boolean isActivating = true;
- Map<String, Boolean> options = null;
- // use the viewer to determine if we are still initializing the
- // diagram
- // do not use the DiagramEditPart.isActivating since
- // ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = editPart.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)editPart, false, false)) {
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
- }
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), StringStatics.BLANK, options) {
+ public ICommand getPostCommand(final IAdaptable viewAdapter) {
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- compositeCommand.execute(monitor, info);
- return Status.OK_STATUS;
- }
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
+ return new AbstractTransactionalCommand(editingDomain, "Modify Stereotype Properties Display", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ View view = (View)viewAdapter.getAdapter(View.class);
+ String stereotypesStrList = PaletteUtil.convertToCommaSeparatedRepresentation(listOfDisplayableStereotypeProperties);
+
+ AppliedStereotypeHelper.getAddAppliedStereotypePropertiesCommand(editingDomain, view, stereotypesStrList).execute();
+ AppliedStereotypeHelper.getAppliedStereotypeToDisplayCommand(editingDomain, view, "", UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION).execute();
+
+ return CommandResult.newOKCommandResult();
}
- } else {
- Activator.log.error("Impossible to execute graphical post action " + propertiesToUpdate, null);
- }
+ };
}
/**
@@ -382,7 +336,7 @@ public class DisplayAppliedStereotypePropertiesInCompartmentPostAction extends G
}
public String getPropertyName(Stereotype stereotype, Property property) {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append(stereotype.getQualifiedName());
buffer.append(".");
buffer.append(property.getName());
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/GraphicalPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/GraphicalPostAction.java
index 0b83a8cda3a..1f713c8b3b3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/GraphicalPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/GraphicalPostAction.java
@@ -11,7 +11,6 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.service.palette;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -19,23 +18,13 @@ import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
import org.eclipse.swt.SWT;
@@ -97,61 +86,26 @@ public class GraphicalPostAction extends ModelPostAction {
/**
* {@inheritDoc}
*/
- public void run(EditPart editPart) {
-
- final CompositeCommand compositeCommand = new CompositeCommand("Modify Graphic");
- EObject objectToEdit = (View)editPart.getModel();
-
- for(String featureName : propertiesToUpdate.keySet()) {
- // retrieve feature to set
- EStructuralFeature feature = objectToEdit.eClass().getEStructuralFeature(featureName);
- if(feature == null) {
- Activator.log.error("Impossible to find the feature " + featureName + " for element " + objectToEdit, null);
- return;
- } else {
-
- SetRequest request = new SetRequest(objectToEdit, feature, getValue(feature, propertiesToUpdate.get(featureName)));
- // request.getExtendedData().put(ApplyStereotypeRequest.NEW_EDIT_PART_NAME,
- // "NEW");
- compositeCommand.compose(new SetValueCommand(request));
- }
- }
- compositeCommand.reduce();
-
- if(compositeCommand.canExecute()) {
- boolean isActivating = true;
- Map<String, Boolean> options = null;
- // use the viewer to determine if we are still initializing the
- // diagram
- // do not use the DiagramEditPart.isActivating since
- // ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = editPart.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
-
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)editPart, false, false)) {
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
- }
-
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), StringStatics.BLANK, options) {
-
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- compositeCommand.execute(monitor, info);
-
- return Status.OK_STATUS;
+ public ICommand getPostCommand(final IAdaptable viewAdapter) {
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+
+ return new AbstractTransactionalCommand(editingDomain, "Modify Graphic", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ View view = (View)viewAdapter.getAdapter(View.class);
+ for(String featureName : propertiesToUpdate.keySet()) {
+ // retrieve feature to set
+ EStructuralFeature feature = view.eClass().getEStructuralFeature(featureName);
+ if(feature == null) {
+ Activator.log.error("Impossible to find the feature " + featureName + " for element " + view, null);
+ } else {
+ view.eSet(feature, getValue(feature, propertiesToUpdate.get(featureName)));
+ }
}
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
+ return CommandResult.newOKCommandResult();
}
- } else {
- Activator.log.error("Impossible to execute graphical post action " + propertiesToUpdate, null);
- }
+ };
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IAspectAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IAspectAction.java
index 9b97ced1133..606650e84b1 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IAspectAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IAspectAction.java
@@ -35,14 +35,6 @@ public interface IAspectAction {
public void init(Node configurationNode, IAspectActionProvider factory);
/**
- * action performed by this class
- *
- * @param editPart
- * the edit part on which the action occurs
- */
- public void run(EditPart editPart);
-
- /**
* Runs post condition tests before runnning the action
*
* @return the status corresponding to the check
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPaletteAspectToolEntryProxy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPaletteAspectToolEntryProxy.java
index 346cd29d974..a1232a67728 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPaletteAspectToolEntryProxy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPaletteAspectToolEntryProxy.java
@@ -26,4 +26,11 @@ public interface IPaletteAspectToolEntryProxy extends IPaletteEntryProxy {
*/
public List<IPostAction> getPostActions();
+ /**
+ * Returns the list of pre actions to execute on creation
+ *
+ * @return the list of pre actions to execute on creation
+ */
+ public List<IPreAction> getPreActions();
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPostAction.java
index fbc083cb63f..84fc2ff9d09 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPostAction.java
@@ -11,9 +11,41 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.service.palette;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+
/**
* Interface implemented by post exectuion actions
*/
public interface IPostAction extends IAspectAction {
+ /**
+ * command that will be execute after the creation command
+ *
+ * @param viewAdapter
+ * an adapter to retrieve the view created by the creation command.
+ * the view will be available in the adapter
+ * during the execute() of the command but is not available when
+ * this method is called.
+ * @return
+ */
+ public ICommand getPostCommand(IAdaptable viewAdapter);
+
+ /**
+ * Do an action after the edit part has been created from the view.
+ * This is executed in post commit so you can't run a transactional command
+ * Except in unprotected mode which is dangerous.
+ * Please consider the use of getPostCommand instead if possible.
+ *
+ * @param editPart
+ */
+ public void runInPostCommit(EditPart editPart);
+
+ /**
+ * Needs to return true if an action is specified in runInPostCommit()
+ * @return
+ */
+ public boolean needsPostCommitRun();
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPreAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPreAction.java
index 77f50623539..6a47564ce21 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPreAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/IPreAction.java
@@ -8,12 +8,36 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Philippe ROLAND (Atos) philippe.roland@atos.net - Defined additional methods for Nodes and Connections
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.service.palette;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.notation.View;
+
/**
* Interface implemented by pre execution actions
*/
public interface IPreAction extends IAspectAction {
+ /**
+ * Get the precommand for a node element.
+ *
+ * @param containerView
+ * the View corresponding to the parent of the element that is about to created
+ * @return
+ */
+ public ICommand getNodePreCommand(View containerView);
+
+ /**
+ * Get the precommand for a connection element.
+ *
+ * @param sourceView
+ * the View corresponding to the connection's source
+ * @param targetView
+ * the View corresponding to the connection's target
+ * @return
+ */
+ public ICommand getConnectionPreCommand(View sourceView, View targetView);
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ModelPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ModelPostAction.java
index 26fa89f2ce7..31ed3c7938f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ModelPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ModelPostAction.java
@@ -75,11 +75,6 @@ public abstract class ModelPostAction implements IPostAction {
}
/**
- * @{inheritDoc
- */
- public abstract void run(EditPart editPart);
-
- /**
* Retrieves the valid type of an object given the structural feature for
* which it gives a value
*
@@ -244,4 +239,10 @@ public abstract class ModelPostAction implements IPostAction {
return value;
}
+ public void runInPostCommit(EditPart editPart) {
+ }
+
+ public boolean needsPostCommitRun() {
+ return false;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/SemanticPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/SemanticPostAction.java
index 68b2a501e10..cee5a341927 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/SemanticPostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/SemanticPostAction.java
@@ -13,9 +13,8 @@ package org.eclipse.papyrus.uml.diagram.common.service.palette;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
+import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -23,9 +22,6 @@ import java.util.StringTokenizer;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
@@ -33,18 +29,11 @@ import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
@@ -58,6 +47,7 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
@@ -181,67 +171,38 @@ public class SemanticPostAction extends ModelPostAction {
/**
* {@inheritDoc}
*/
- public void run(EditPart editPart) {
-
- final CompositeCommand compositeCommand = new CompositeCommand("Modify Semantic");
- EObject objectToEdit = ((View)editPart.getModel()).getElement();
-
- for(String featureName : propertiesToUpdate.keySet()) {
- // retrieve feature to set
- EStructuralFeature feature = objectToEdit.eClass().getEStructuralFeature(featureName);
- if(feature == null) {
- Activator.log.error("Impossible to find the feature " + featureName + " for element " + objectToEdit, null);
- return;
- } else {
-
- SetRequest request = new SetRequest(objectToEdit, feature, getValue(feature, propertiesToUpdate.get(featureName)));
- // request.getExtendedData().put(ApplyStereotypeRequest.NEW_EDIT_PART_NAME,
- // "NEW");
- compositeCommand.compose(new SetValueCommand(request));
- }
- }
-
- // create the command to open the dialog to set properties on runtime
- if(runtimeDefinedProperties.size() > 0) {
- DynamicConfigureRequest request = new DynamicConfigureRequest(objectToEdit, runtimeDefinedProperties);
- compositeCommand.compose(new SetDynamicValueCommand(request));
- }
-
- compositeCommand.reduce();
-
- if(compositeCommand.canExecute()) {
- boolean isActivating = true;
- Map<String, Boolean> options = null;
- // use the viewer to determine if we are still initializing the
- // diagram
- // do not use the DiagramEditPart.isActivating since
- // ConnectionEditPart's
- // parent will not be a diagram edit part
- EditPartViewer viewer = editPart.getViewer();
- if(viewer instanceof DiagramGraphicalViewer) {
- isActivating = ((DiagramGraphicalViewer)viewer).isInitializing();
- }
-
- if(isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart)editPart, false, false)) {
- options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
- }
-
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), StringStatics.BLANK, options) {
-
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ public ICommand getPostCommand(final IAdaptable viewAdpater) {
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
+
+ return new AbstractTransactionalCommand(editingDomain, "Modify Semantic", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ View view = (View)viewAdpater.getAdapter(View.class);
+
+ if (view != null) {
+ EObject objectToEdit = view.getElement();
+
+ for(String featureName : propertiesToUpdate.keySet()) {
+ // retrieve feature to set
+ EStructuralFeature feature = objectToEdit.eClass().getEStructuralFeature(featureName);
+ if(feature == null) {
+ Activator.log.error("Impossible to find the feature " + featureName + " for element " + objectToEdit, null);
+ } else {
+ objectToEdit.eSet(feature, getValue(feature, propertiesToUpdate.get(featureName)));
+ }
+ }
- compositeCommand.execute(monitor, info);
+ // create the command to open the dialog to set properties on runtime
+ if(runtimeDefinedProperties.size() > 0) {
+ DynamicConfigureRequest request = new DynamicConfigureRequest(objectToEdit, runtimeDefinedProperties);
+ new SetDynamicValueCommand(request).doExecuteWithResult(null, null);
+ }
- return Status.OK_STATUS;
}
- };
- try {
- operation.execute(new NullProgressMonitor(), null);
- } catch (ExecutionException e) {
- Activator.log.error(e);
+ return CommandResult.newOKCommandResult();
}
- }
-
+ };
}
/**
@@ -359,19 +320,10 @@ public class SemanticPostAction extends ModelPostAction {
* the object to serialize
* @return the string corresponding to the serialize value
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
protected String serializeValue(Object object, String separator) {
- if(object instanceof List<?>) {
- StringBuffer result = new StringBuffer();
- Iterator<Object> it = ((List<Object>)object).iterator();
- while(it.hasNext()) {
- Object o = (Object)it.next();
- result.append(o);
- if(it.hasNext()) {
- result.append(separator);
- }
- }
- return result.toString();
+ if(object instanceof Collection) {
+ return PaletteUtil.convertToFlatRepresentation((Collection)object, separator);
}
return object.toString();
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java
index f1dd5d862bd..4a18d9f3263 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java
@@ -15,20 +15,21 @@ package org.eclipse.papyrus.uml.diagram.common.service.palette;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.palette.ToolEntry;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
-import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.CellEditor;
@@ -53,9 +54,11 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.Messages;
+import org.eclipse.papyrus.uml.diagram.common.commands.ApplyStereotypeCommand;
+import org.eclipse.papyrus.uml.diagram.common.commands.DefferedAppliedStereotypeToDisplayCommand;
import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.ApplyStereotypeRequest;
import org.eclipse.papyrus.uml.diagram.common.ui.dialogs.PropertyEditors;
@@ -72,7 +75,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
@@ -267,123 +269,87 @@ public class StereotypePostAction extends ModelPostAction {
/**
* {@inheritDoc}
*/
- @Override
- @SuppressWarnings("unchecked")
- public void run(final EditPart editPart) {
+ public ICommand getPostCommand(IAdaptable viewAdapter) {
// so, we doesn't need to save the default values which can be modified
// during the runtime
config = new Configuration(config.getConfigurationNode());
- // Apply the required stereotypes
- ApplyStereotypeRequest request = new ApplyStereotypeRequest(config.getStereotypesToApplyQN());
- request.getExtendedData().put(ApplyStereotypeRequest.NEW_EDIT_PART_NAME, "NEW"); //$NON-NLS-1$
- editPart.performRequest(request);
+ final TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain();
- /*
- * Looks like updateValue in ValueTreeObject and CompositeProperty to
- * apply the values properties to the elements
- */
+ CompositeTransactionalCommand cmd = new CompositeTransactionalCommand (editingDomain, "Apply stereotype");
- // element where are the properties
- final EObject objectToEdit = ((View)editPart.getModel()).getElement();
+ // Apply the required stereotypes
+ final ApplyStereotypeRequest request = new ApplyStereotypeRequest(viewAdapter, config.getStereotypesToApplyQN(), true);
- if(!(objectToEdit instanceof org.eclipse.uml2.uml.NamedElement)) {
- // TODO for the Element which are not NamedElement
- return;
- }
- // we search the container for the object
- org.eclipse.uml2.uml.Element packageContainerTmp = ((org.eclipse.uml2.uml.Element)objectToEdit);
- do {
- packageContainerTmp = packageContainerTmp.getOwner();
- } while(!(packageContainerTmp instanceof org.eclipse.uml2.uml.Package));
- final org.eclipse.uml2.uml.Element packageContainer = packageContainerTmp;
+ cmd.add(new ApplyStereotypeCommand(editingDomain, request));
+
+ // 2. display stereotypes
+ cmd.add(new EMFtoGMFCommandWrapper(new DefferedAppliedStereotypeToDisplayCommand(editingDomain, viewAdapter, "")));
- config.setAppliedProfiles(((org.eclipse.uml2.uml.Package)packageContainer).getAllAppliedProfiles());
+ AbstractTransactionalCommand setPropertiesCommand = new AbstractTransactionalCommand(editingDomain, "Set stereotype values", null) {
- if(config.hasRuntimeProperties()) {
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // we search the container for the object
+ org.eclipse.uml2.uml.Element element = request.getElement();
+ org.eclipse.uml2.uml.Element packageContainer = element;
+ do {
+ packageContainer = packageContainer.getOwner();
+ } while(!(packageContainer instanceof org.eclipse.uml2.uml.Package) && packageContainer != null);
- defineRuntimeProperties(config);
- }
- final TransactionalEditingDomain editingDomain = org.eclipse.papyrus.infra.core.utils.EditorUtils.getTransactionalEditingDomain();
-
- // -----------------create a composite command
- CompositeCommand cmd = new CompositeCommand("Apply values for properties");
- ArrayList<StereotypeRepresentation> stereotypes = config.getStereotypesRepresentations();
- for(StereotypeRepresentation stereotype : stereotypes) {
- final Stereotype stereotypeToEdit = stereotype.getUMLStereotype();
- ArrayList<PropertyRepresentation> properties = stereotype.getPropertiesWithValues();
- for(PropertyRepresentation property : properties) {
- if(property.hasValues()) {
- Type type = property.getType();
- final String propertyName = property.getUMLProperty().getName();
- if(type != null && propertyName != null) {
- final Object newValue;
- if(type instanceof PrimitiveType) {
- newValue = Util.getValueFromString(property.getUMLProperty(), property.getStringValue());
- } else if(Util.isMetaclass(type)) {
- newValue = Util.retrievesMetaclassElementFromString(property.getUMLProperty(), property.getStringValue(), packageContainer);
- // property is an Enumeration
- } else if(type instanceof org.eclipse.uml2.uml.Enumeration) {
- newValue = Util.retrievesEnumerationLiteralFromString(property.getUMLProperty(), property.getStringValue(), packageContainer);
- // property is a DataType
- } else if(type instanceof org.eclipse.uml2.uml.DataType) {
- newValue = Util.getValueFromString(property.getUMLProperty(), property.getStringValue());
- // property is a Stereotype
- } else if(type instanceof Stereotype) {
- newValue = Util.retrievesStereotypedElementFromString(property.getUMLProperty(), property.getStringValue(), packageContainer);
- // property is a composite class
- } else if((type instanceof org.eclipse.uml2.uml.Class) && !(type instanceof Stereotype) && property.getUMLProperty().isMultivalued()) {
- // TODO
- newValue = null;
- } else {
- Activator.log.error("impossible to find a correct editor for the property" + property, null); //$NON-NLS-1$
- return;
- }
- // we create and execute the recording command
- RecordingCommand command = null;
- if(newValue != null) {
- command = new RecordingCommand(editingDomain) {
+ config.setAppliedProfiles(((org.eclipse.uml2.uml.Package)packageContainer).getAllAppliedProfiles());
- @Override
- protected void doExecute() {
- ((org.eclipse.uml2.uml.Element)objectToEdit).setValue(stereotypeToEdit, propertyName, newValue);
+ if(config.hasRuntimeProperties()) {
+ defineRuntimeProperties(config);
+ }
+ ArrayList<StereotypeRepresentation> stereotypes = config.getStereotypesRepresentations();
+ for(StereotypeRepresentation stereotype : stereotypes) {
+ final Stereotype stereotypeToEdit = stereotype.getUMLStereotype();
+ ArrayList<PropertyRepresentation> properties = stereotype.getPropertiesWithValues();
+ for(PropertyRepresentation property : properties) {
+ if(property.hasValues()) {
+ Type type = property.getType();
+ final String propertyName = property.getUMLProperty().getName();
+ if(type != null && propertyName != null) {
+ Object newValue = null;
+ if(type instanceof PrimitiveType) {
+ newValue = Util.getValueFromString(property.getUMLProperty(), property.getStringValue());
+ } else if(Util.isMetaclass(type)) {
+ newValue = Util.retrievesMetaclassElementFromString(property.getUMLProperty(), property.getStringValue(), packageContainer);
+ // property is an Enumeration
+ } else if(type instanceof org.eclipse.uml2.uml.Enumeration) {
+ newValue = Util.retrievesEnumerationLiteralFromString(property.getUMLProperty(), property.getStringValue(), packageContainer);
+ // property is a DataType
+ } else if(type instanceof org.eclipse.uml2.uml.DataType) {
+ newValue = Util.getValueFromString(property.getUMLProperty(), property.getStringValue());
+ // property is a Stereotype
+ } else if(type instanceof Stereotype) {
+ newValue = Util.retrievesStereotypedElementFromString(property.getUMLProperty(), property.getStringValue(), packageContainer);
+ // property is a composite class
+ } else if((type instanceof org.eclipse.uml2.uml.Class) && !(type instanceof Stereotype) && property.getUMLProperty().isMultivalued()) {
+ // TODO
+ newValue = null;
+ } else {
+ Activator.log.error("impossible to find a correct editor for the property" + property, null); //$NON-NLS-1$
}
- };
- }
- if(command != null) {
- cmd.add(new EMFtoGMFCommandWrapper(command));
+ if (newValue != null) {
+ element.setValue(stereotypeToEdit, propertyName, newValue);
+ }
+
+ }
}
}
}
+ return CommandResult.newOKCommandResult();
}
- }
-
- final ICommand iCmd = cmd.reduce();
- try {
- if(iCmd.canExecute()) {
- // execute the command
- editingDomain.runExclusive(new Runnable() {
-
- //
- public void run() {
- Display.getCurrent().asyncExec(new Runnable() {
+ };
- public void run() {
- editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(iCmd));
-
- }
- });
- }
- });
-
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ cmd.add(setPropertiesCommand);
+ return cmd;
}
private void saveValues() {

Back to the top