Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/src/org/eclipse/papyrus/uml/diagram/activity/edit/commands/ConstraintInActivityAsPrecondCreateCommand.java')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/src/org/eclipse/papyrus/uml/diagram/activity/edit/commands/ConstraintInActivityAsPrecondCreateCommand.java37
1 files changed, 28 insertions, 9 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/src/org/eclipse/papyrus/uml/diagram/activity/edit/commands/ConstraintInActivityAsPrecondCreateCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/src/org/eclipse/papyrus/uml/diagram/activity/edit/commands/ConstraintInActivityAsPrecondCreateCommand.java
index 7be74dd391a..818d64cd7fc 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/src/org/eclipse/papyrus/uml/diagram/activity/edit/commands/ConstraintInActivityAsPrecondCreateCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/src/org/eclipse/papyrus/uml/diagram/activity/edit/commands/ConstraintInActivityAsPrecondCreateCommand.java
@@ -25,12 +25,17 @@ import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
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.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.viewpoints.policy.ModelAddData;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.uml.diagram.activity.providers.ElementInitializers;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* @generated
@@ -40,7 +45,7 @@ public class ConstraintInActivityAsPrecondCreateCommand extends EditElementComma
/**
* @generated
*/
- private EClass eClass = null;
+ private Diagram diagram = null;
/**
* @generated
@@ -50,24 +55,25 @@ public class ConstraintInActivityAsPrecondCreateCommand extends EditElementComma
/**
* @generated
*/
- public ConstraintInActivityAsPrecondCreateCommand(CreateElementRequest req, EObject eObject) {
+ public ConstraintInActivityAsPrecondCreateCommand(CreateElementRequest req, EObject eObject, Diagram diagram) {
super(req.getLabel(), null, req);
this.eObject = eObject;
- this.eClass = eObject != null ? eObject.eClass() : null;
+ this.diagram = diagram;
}
/**
* @generated
*/
- public static ConstraintInActivityAsPrecondCreateCommand create(CreateElementRequest req, EObject eObject) {
- return new ConstraintInActivityAsPrecondCreateCommand(req, eObject);
+ public static ConstraintInActivityAsPrecondCreateCommand create(CreateElementRequest req, EObject eObject, Diagram diagram) {
+ return new ConstraintInActivityAsPrecondCreateCommand(req, eObject, diagram);
}
/**
* @generated
*/
- public ConstraintInActivityAsPrecondCreateCommand(CreateElementRequest req) {
+ public ConstraintInActivityAsPrecondCreateCommand(CreateElementRequest req, Diagram diagram) {
super(req.getLabel(), null, req);
+ this.diagram = diagram;
}
/**
@@ -90,7 +96,9 @@ public class ConstraintInActivityAsPrecondCreateCommand extends EditElementComma
* @generated
*/
public boolean canExecute() {
- return true;
+ EObject target = getElementToEdit();
+ ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target.eClass(), UMLPackage.eINSTANCE.getConstraint());
+ return data.isPermitted();
}
/**
@@ -98,8 +106,19 @@ public class ConstraintInActivityAsPrecondCreateCommand extends EditElementComma
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Constraint newElement = UMLFactory.eINSTANCE.createConstraint();
- Namespace owner = (Namespace)getElementToEdit();
- owner.getOwnedRules().add(newElement);
+ EObject target = getElementToEdit();
+ ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target, newElement);
+ if(data.isPermitted()) {
+ if(data.isPathDefined()) {
+ if(!data.execute(target, newElement))
+ return CommandResult.newErrorCommandResult("Failed to follow the policy-specified for the insertion of the new element");
+ } else {
+ Namespace qualifiedTarget = (Namespace)target;
+ qualifiedTarget.getOwnedRules().add(newElement);
+ }
+ } else {
+ return CommandResult.newErrorCommandResult("The active policy restricts the addition of this element");
+ }
Behavior childHolder = (Behavior)getElementToEdit();
childHolder.getPreconditions().add(newElement);
ElementInitializers.getInstance().init_Constraint_3002(newElement);

Back to the top