Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2017-05-11 11:34:16 +0000
committerFlorian Noyrit2017-06-01 07:48:02 +0000
commitbef75de88911901117d2fb08ac7c91661715a993 (patch)
tree466b5f197dde56d07b37d2bce016e4549b63fb23 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus
parent97c7dde3411e673d5bb26f318864979e9b2c9984 (diff)
downloadorg.eclipse.papyrus-bef75de88911901117d2fb08ac7c91661715a993.tar.gz
org.eclipse.papyrus-bef75de88911901117d2fb08ac7c91661715a993.tar.xz
org.eclipse.papyrus-bef75de88911901117d2fb08ac7c91661715a993.zip
Bug 460022 - [Activity Diagram] Automatically create pins on opaque
actions for object flow Change-Id: I7a12a8b5a3788ae554fc1177ebbdce03c444ae0a
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ObjectFlowEditHelperAdvice.java112
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ObjectFlowWithPinsCreationEditPolicy.java256
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/OpaqueActionObjectFlowWithPinsCreationEditPolicy.java74
3 files changed, 112 insertions, 330 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ObjectFlowEditHelperAdvice.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ObjectFlowEditHelperAdvice.java
new file mode 100644
index 00000000000..fdc5dee05ff
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/advices/ObjectFlowEditHelperAdvice.java
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Pauline DEVILLE (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.activity.edit.advices;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.papyrus.uml.tools.utils.ObjectFlowUtil;
+import org.eclipse.uml2.uml.Action;
+import org.eclipse.uml2.uml.ActivityNode;
+import org.eclipse.uml2.uml.InputPin;
+import org.eclipse.uml2.uml.ObjectFlow;
+import org.eclipse.uml2.uml.OutputPin;
+
+/**
+ * This Advice Helper is user to create pin between an ObjectFlow and an action (if it is authorized)
+ */
+public class ObjectFlowEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ protected ICommand getAfterConfigureCommand(final ConfigureRequest req) {
+ ICommand configureCommand = new ConfigureElementCommand(req) {
+
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ ObjectFlow element = (ObjectFlow) req.getElementToConfigure();
+ ActivityNode source = getSourceObject(req);
+ ActivityNode target = getTargetObject(req);
+ // add pin if the source or the target is an action (see Bug 460022)
+ if (source instanceof Action) {
+ if (ObjectFlowUtil.insertPinForStartingNewObjectFlow(source)) {
+ CreateElementRequest req = new CreateElementRequest(source, UMLElementTypes.OUTPUT_PIN);
+ CreateElementCommand cmd = new CreateElementCommand(req);
+ cmd.execute(null, null);
+ CommandResult commandResult = cmd.getCommandResult();
+ if (commandResult != null) {
+ if (!commandResult.getStatus().isOK()) {
+ return commandResult;
+ }
+ }
+ OutputPin pin = (OutputPin) commandResult.getReturnValue();
+ ObjectFlowUtil.insertOutputPin((Action) source, pin);
+ source = pin;
+ }
+ }
+ if (target instanceof Action) {
+ if (ObjectFlowUtil.insertPinForStartingNewObjectFlow(target)) {
+ CreateElementRequest req = new CreateElementRequest(target, UMLElementTypes.INPUT_PIN);
+ CreateElementCommand cmd = new CreateElementCommand(req);
+ cmd.execute(null, null);
+ CommandResult commandResult = cmd.getCommandResult();
+ if (commandResult != null) {
+ if (!commandResult.getStatus().isOK()) {
+ return commandResult;
+ }
+ }
+ InputPin pin = (InputPin) commandResult.getReturnValue();
+ ObjectFlowUtil.insertInputPin((Action) target, pin);
+ target = pin;
+ }
+ }
+ if (source != null) {
+ element.setSource(source);
+ }
+ if (target != null) {
+ element.setTarget(target);
+ }
+ return CommandResult.newOKCommandResult(element);
+ }
+ };
+ return CompositeCommand.compose(configureCommand, super.getAfterConfigureCommand(req));
+ }
+
+ /**
+ * This method provides the object to be use as source.
+ *
+ * @return the source value
+ */
+ protected ActivityNode getSourceObject(ConfigureRequest req) {
+ Object result = req.getParameter(CreateRelationshipRequest.SOURCE);
+ return (result instanceof ActivityNode) ? (ActivityNode) result : null;
+ }
+
+ /**
+ * This method provides the object to be used as target.
+ *
+ * @return the target value
+ */
+ protected ActivityNode getTargetObject(ConfigureRequest req) {
+ Object result = req.getParameter(CreateRelationshipRequest.TARGET);
+ return (result instanceof ActivityNode) ? (ActivityNode) result : null;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ObjectFlowWithPinsCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ObjectFlowWithPinsCreationEditPolicy.java
deleted file mode 100644
index 44222f1647a..00000000000
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ObjectFlowWithPinsCreationEditPolicy.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 Atos Origin.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.activity.edit.policies;
-
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.geometry.PointList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.requests.CreateConnectionRequest;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionAnchorsCommand;
-import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionEndsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
-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.editparts.INodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.internal.commands.SetConnectionBendpointsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.notation.Connector;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.gmf.runtime.notation.impl.ShapeImpl;
-import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes;
-import org.eclipse.uml2.uml.ActivityNode;
-import org.eclipse.uml2.uml.ObjectFlow;
-
-public class ObjectFlowWithPinsCreationEditPolicy extends GraphicalNodeEditPolicy {
-
- /**
- * Returns a command that will initialize connection creation.
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy#getConnectionCreateCommand(org.eclipse.gef.requests.CreateConnectionRequest)
- * @param request
- * the request for creating the connection
- * @return the command
- */
- @Override
- protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
- if (!(request instanceof CreateConnectionViewRequest)) {
- return null;
- }
- CreateConnectionViewRequest req = (CreateConnectionViewRequest) request;
- CompositeCommand cc = new CompositeCommand(DiagramUIMessages.Commands_CreateCommand_Connection_Label);
- Diagram diagramView = ((View) getHost().getModel()).getDiagram();
- TransactionalEditingDomain editingDomain = getEditingDomain();
- CreateCommand createCommand = new CreateCommand(editingDomain, req.getConnectionViewDescriptor(), diagramView.getDiagram());
- setViewAdapter((IAdaptable) createCommand.getCommandResult().getReturnValue());
- SetConnectionEndsCommand sceCommand = new SetConnectionEndsCommand(editingDomain, StringStatics.BLANK);
- sceCommand.setEdgeAdaptor(getViewAdapter());
- if (getObjectFlowHint().equals(req.getConnectionViewDescriptor().getSemanticHint())) {
- // handle redirection of Object flow on created child pin
- sceCommand.setNewSourceAdaptor(getObjectFlowSourceViewAdapter(request));
- } else {
- sceCommand.setNewSourceAdaptor(new EObjectAdapter(getView()));
- }
- ConnectionAnchor sourceAnchor = getConnectableEditPart().getSourceConnectionAnchor(request);
- SetConnectionAnchorsCommand scaCommand = new SetConnectionAnchorsCommand(editingDomain, StringStatics.BLANK);
- scaCommand.setEdgeAdaptor(getViewAdapter());
- scaCommand.setNewSourceTerminal(getConnectableEditPart().mapConnectionAnchorToTerminal(sourceAnchor));
- SetConnectionBendpointsCommand sbbCommand = new SetConnectionBendpointsCommand(editingDomain);
- sbbCommand.setEdgeAdapter(getViewAdapter());
- cc.compose(createCommand);
- cc.compose(sceCommand);
- cc.compose(scaCommand);
- cc.compose(sbbCommand);
- Command c = new ICommandProxy(cc);
- request.setStartCommand(c);
- return c;
- }
-
- /**
- * Get the semantic hint for an object flow edge
- *
- * @return semantic hint
- */
- private static String getObjectFlowHint() {
- IHintedType objectFlowType = (IHintedType) UMLElementTypes.ObjectFlow_Edge;
- return objectFlowType.getSemanticHint();
- }
-
- /**
- * Returns a command that will create the connection.
- *
- * @see org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getConnectionCompleteCommand(org.eclipse.gef.requests.CreateConnectionRequest)
- * @param request
- * the request for creating the connection
- * @return the command
- */
- @Override
- protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
- ICommandProxy proxy = (ICommandProxy) request.getStartCommand();
- if (proxy == null) {
- return null;
- }
- // reset the target edit-part for the request
- INodeEditPart targetEP = getConnectionCompleteEditPart(request);
- if (targetEP == null) {
- return null;
- }
- CompositeCommand cc = (CompositeCommand) proxy.getICommand();
- ConnectionAnchor targetAnchor = targetEP.getTargetConnectionAnchor(request);
- Iterator commandItr = cc.iterator();
- commandItr.next(); // 0
- SetConnectionEndsCommand sceCommand = (SetConnectionEndsCommand) commandItr.next(); // 1
- if (request instanceof CreateConnectionViewRequest && getObjectFlowHint().equals(((CreateConnectionViewRequest) request).getConnectionViewDescriptor().getSemanticHint())) {
- // handle redirection of Object flow on created child pin
- sceCommand.setNewTargetAdaptor(getObjectFlowTargetViewAdapter(request));
- } else {
- sceCommand.setNewTargetAdaptor(new EObjectAdapter(((IGraphicalEditPart) targetEP).getNotationView()));
- }
- SetConnectionAnchorsCommand scaCommand = (SetConnectionAnchorsCommand) commandItr.next(); // 2
- scaCommand.setNewTargetTerminal(targetEP.mapConnectionAnchorToTerminal(targetAnchor));
- setViewAdapter(sceCommand.getEdgeAdaptor());
- INodeEditPart sourceEditPart = (INodeEditPart) request.getSourceEditPart();
- ConnectionAnchor sourceAnchor = sourceEditPart.mapTerminalToConnectionAnchor(scaCommand.getNewSourceTerminal());
- PointList pointList = new PointList();
- if (request.getLocation() == null) {
- pointList.addPoint(sourceAnchor.getLocation(targetAnchor.getReferencePoint()));
- pointList.addPoint(targetAnchor.getLocation(sourceAnchor.getReferencePoint()));
- } else {
- pointList.addPoint(sourceAnchor.getLocation(request.getLocation()));
- pointList.addPoint(targetAnchor.getLocation(request.getLocation()));
- }
- SetConnectionBendpointsCommand sbbCommand = (SetConnectionBendpointsCommand) commandItr.next(); // 3
- sbbCommand.setNewPointList(pointList, sourceAnchor.getReferencePoint(), targetAnchor.getReferencePoint());
- return request.getStartCommand();
- }
-
- /**
- * Get the adapter to recover the object flow source view
- *
- * @param request
- * connection creation request
- * @return adapter
- */
- private IAdaptable getObjectFlowSourceViewAdapter(final CreateConnectionRequest request) {
- return new IAdaptable() {
-
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter != null && adapter.isAssignableFrom(ShapeImpl.class)) {
- return getObjectFlowExtremityView(true);
- }
- return null;
- }
- };
- }
-
- /**
- * Get the adapter to recover the object flow target view
- *
- * @param request
- * connection creation request
- * @return adapter
- */
- private IAdaptable getObjectFlowTargetViewAdapter(final CreateConnectionRequest request) {
- return new IAdaptable() {
-
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter != null && adapter.isAssignableFrom(ShapeImpl.class)) {
- return getObjectFlowExtremityView(false);
- }
- return null;
- }
- };
- }
-
- /**
- * Try and get an extremity view of the object flow contained in this host.
- *
- * @param isStartEnd
- * true if view is the object flow start end, false for the
- * target end
- * @return the view or null
- */
- protected View getObjectFlowExtremityView(boolean isStartEnd) {
- Object objectFlowView = getViewAdapter().getAdapter(Connector.class);
- if (objectFlowView instanceof Connector) {
- EObject objectFlow = ((Connector) objectFlowView).getElement();
- if (objectFlow instanceof ObjectFlow) {
- ActivityNode actNode = null;
- if (isStartEnd) {
- actNode = ((ObjectFlow) objectFlow).getSource();
- } else {
- actNode = ((ObjectFlow) objectFlow).getTarget();
- }
- if (actNode != null) {
- if (getHost().getModel() instanceof View) {
- View view = (View) getHost().getModel();
- if (actNode.equals(view.getElement())) {
- return view;
- }
- }
- // refresh view children which have not been created yet.
- EditPolicy policy = getHost().getEditPolicy(EditPolicyRoles.CANONICAL_ROLE);
- if (policy instanceof CanonicalEditPolicy) {
- CanonicalEditPolicy canonical = (CanonicalEditPolicy) policy;
- if (!canonical.isEnabled()) {
- canonical.setEnable(true);
- canonical.refresh();
- canonical.setEnable(false);
- } else {
- canonical.refresh();
- }
- }
- // recover the appropriate child view
- for (Object childPart : getHost().getChildren()) {
- if (childPart instanceof EditPart) {
- Object containedView = ((EditPart) childPart).getModel();
- if (containedView instanceof View) {
- if (actNode.equals(((View) containedView).getElement())) {
- return (View) containedView;
- }
- }
- }
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Get the editing domain
- *
- * @return editing domain
- */
- private TransactionalEditingDomain getEditingDomain() {
- return ((IGraphicalEditPart) getHost()).getEditingDomain();
- }
-}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/OpaqueActionObjectFlowWithPinsCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/OpaqueActionObjectFlowWithPinsCreationEditPolicy.java
deleted file mode 100644
index 30364809022..00000000000
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/OpaqueActionObjectFlowWithPinsCreationEditPolicy.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- * Atos - Initial API and implementation
- * Arthur Daussy - Bug 367894 - [activity diagram] pins can not be deleted or hidden directly from selection in diagram
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.activity.edit.policies;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.Request;
-import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.notation.Connector;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.activity.part.UMLDiagramEditorPlugin;
-import org.eclipse.papyrus.uml.diagram.activity.part.UMLVisualIDRegistry;
-import org.eclipse.uml2.uml.ActivityNode;
-import org.eclipse.uml2.uml.ObjectFlow;
-
-/**
- * Used to create pin when creating Object Flow
- *
- * @author arthur daussy
- *
- */
-public class OpaqueActionObjectFlowWithPinsCreationEditPolicy extends ObjectFlowWithPinsCreationEditPolicy {
-
- @Override
- protected View getObjectFlowExtremityView(boolean isStartEnd) {
- Object objectFlowView = getViewAdapter().getAdapter(Connector.class);
- if (objectFlowView instanceof Connector) {
- EObject objectFlow = ((Connector) objectFlowView).getElement();
- if (objectFlow instanceof ObjectFlow) {
- ActivityNode actNode = null;
- if (isStartEnd) {
- actNode = ((ObjectFlow) objectFlow).getSource();
- } else {
- actNode = ((ObjectFlow) objectFlow).getTarget();
- }
- if (actNode != null) {
- if (getHost().getModel() instanceof View) {
- View view = (View) getHost().getModel();
- if (actNode.equals(view.getElement())) {
- return view;
- }
- // if there is no existing view we create it
- Node node = ViewService.createNode(view, actNode, UMLVisualIDRegistry.getType(UMLVisualIDRegistry.getNodeVisualID(view, actNode)), UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
- if (node != null) {
- return node;
- }
- }
- }
- }
- }
- return null;
- }
-
- @Override
- public void eraseSourceFeedback(Request request) {
- if (connectionFeedback != null) {
- removeFeedback(connectionFeedback);
- feedbackHelper = null;
- connectionFeedback = null;
- }
- }
-}

Back to the top