Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/src/org/eclipse/papyrus/uml/diagram/deployment/edit/commands/DeviceCreateCommandCN.java')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/src/org/eclipse/papyrus/uml/diagram/deployment/edit/commands/DeviceCreateCommandCN.java45
1 files changed, 27 insertions, 18 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/src/org/eclipse/papyrus/uml/diagram/deployment/edit/commands/DeviceCreateCommandCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/src/org/eclipse/papyrus/uml/diagram/deployment/edit/commands/DeviceCreateCommandCN.java
index bc450bb1af0..9d3d053bf98 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/src/org/eclipse/papyrus/uml/diagram/deployment/edit/commands/DeviceCreateCommandCN.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/src/org/eclipse/papyrus/uml/diagram/deployment/edit/commands/DeviceCreateCommandCN.java
@@ -14,11 +14,15 @@ 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.deployment.providers.ElementInitializers;
import org.eclipse.uml2.uml.Device;
import org.eclipse.uml2.uml.Node;
import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* @generated
@@ -28,7 +32,7 @@ public class DeviceCreateCommandCN extends EditElementCommand {
/**
* @generated
*/
- private EClass eClass = null;
+ private Diagram diagram = null;
/**
* @generated
@@ -38,24 +42,25 @@ public class DeviceCreateCommandCN extends EditElementCommand {
/**
* @generated
*/
- public DeviceCreateCommandCN(CreateElementRequest req, EObject eObject) {
+ public DeviceCreateCommandCN(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 DeviceCreateCommandCN create(CreateElementRequest req, EObject eObject) {
- return new DeviceCreateCommandCN(req, eObject);
+ public static DeviceCreateCommandCN create(CreateElementRequest req, EObject eObject, Diagram diagram) {
+ return new DeviceCreateCommandCN(req, eObject, diagram);
}
/**
* @generated
*/
- public DeviceCreateCommandCN(CreateElementRequest req) {
+ public DeviceCreateCommandCN(CreateElementRequest req, Diagram diagram) {
super(req.getLabel(), null, req);
+ this.diagram = diagram;
}
/**
@@ -64,7 +69,6 @@ public class DeviceCreateCommandCN extends EditElementCommand {
* @generated
*/
protected EObject getElementToEdit() {
-
EObject container = ((CreateElementRequest)getRequest()).getContainer();
if(container instanceof View) {
container = ((View)container).getElement();
@@ -79,25 +83,31 @@ public class DeviceCreateCommandCN extends EditElementCommand {
* @generated
*/
public boolean canExecute() {
-
- return true;
-
+ EObject target = getElementToEdit();
+ ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target.eClass(), UMLPackage.eINSTANCE.getDevice());
+ return data.isPermitted();
}
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
Device newElement = UMLFactory.eINSTANCE.createDevice();
-
- Node owner = (Node)getElementToEdit();
- owner.getNestedNodes().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 {
+ Node qualifiedTarget = (Node)target;
+ qualifiedTarget.getNestedNodes().add(newElement);
+ }
+ } else {
+ return CommandResult.newErrorCommandResult("The active policy restricts the addition of this element");
+ }
ElementInitializers.getInstance().init_Device_16(newElement);
-
doConfigure(newElement, monitor, info);
-
((CreateElementRequest)getRequest()).setNewElement(newElement);
return CommandResult.newOKCommandResult(newElement);
}
@@ -115,5 +125,4 @@ public class DeviceCreateCommandCN extends EditElementCommand {
configureCommand.execute(monitor, info);
}
}
-
}

Back to the top