Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/commands/IntervalConstraintCreateCommand.java')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/commands/IntervalConstraintCreateCommand.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/commands/IntervalConstraintCreateCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/commands/IntervalConstraintCreateCommand.java
index a0e29dcc550..77cb5aac704 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/commands/IntervalConstraintCreateCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/src/org/eclipse/papyrus/uml/diagram/composite/edit/commands/IntervalConstraintCreateCommand.java
@@ -24,12 +24,16 @@ 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.composite.providers.ElementInitializers;
import org.eclipse.uml2.uml.IntervalConstraint;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* @generated
@@ -39,7 +43,7 @@ public class IntervalConstraintCreateCommand extends EditElementCommand {
/**
* @generated
*/
- private EClass eClass = null;
+ private Diagram diagram = null;
/**
* @generated
@@ -49,24 +53,25 @@ public class IntervalConstraintCreateCommand extends EditElementCommand {
/**
* @generated
*/
- public IntervalConstraintCreateCommand(CreateElementRequest req, EObject eObject) {
+ public IntervalConstraintCreateCommand(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 IntervalConstraintCreateCommand create(CreateElementRequest req, EObject eObject) {
- return new IntervalConstraintCreateCommand(req, eObject);
+ public static IntervalConstraintCreateCommand create(CreateElementRequest req, EObject eObject, Diagram diagram) {
+ return new IntervalConstraintCreateCommand(req, eObject, diagram);
}
/**
* @generated
*/
- public IntervalConstraintCreateCommand(CreateElementRequest req) {
+ public IntervalConstraintCreateCommand(CreateElementRequest req, Diagram diagram) {
super(req.getLabel(), null, req);
+ this.diagram = diagram;
}
/**
@@ -89,11 +94,9 @@ public class IntervalConstraintCreateCommand extends EditElementCommand {
* @generated
*/
public boolean canExecute() {
- // Creation constraint for TopLevelNodes
- if(!(getElementToEdit() instanceof Package)) {
- return false;
- }
- return true;
+ EObject target = getElementToEdit();
+ ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target.eClass(), UMLPackage.eINSTANCE.getIntervalConstraint());
+ return data.isPermitted();
}
/**
@@ -101,8 +104,19 @@ public class IntervalConstraintCreateCommand extends EditElementCommand {
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
IntervalConstraint newElement = UMLFactory.eINSTANCE.createIntervalConstraint();
- 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");
+ }
ElementInitializers.getInstance().init_IntervalConstraint_2112(newElement);
doConfigure(newElement, monitor, info);
((CreateElementRequest)getRequest()).setNewElement(newElement);

Back to the top