Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src/org/eclipse/papyrus/uml/diagram/clazz/edit/commands/NestedClassForComponentCreateCommand.java')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src/org/eclipse/papyrus/uml/diagram/clazz/edit/commands/NestedClassForComponentCreateCommand.java36
1 files changed, 27 insertions, 9 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src/org/eclipse/papyrus/uml/diagram/clazz/edit/commands/NestedClassForComponentCreateCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src/org/eclipse/papyrus/uml/diagram/clazz/edit/commands/NestedClassForComponentCreateCommand.java
index 2960f50eb37..1452be479db 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src/org/eclipse/papyrus/uml/diagram/clazz/edit/commands/NestedClassForComponentCreateCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src/org/eclipse/papyrus/uml/diagram/clazz/edit/commands/NestedClassForComponentCreateCommand.java
@@ -23,10 +23,14 @@ 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.clazz.providers.ElementInitializers;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* @generated
@@ -36,7 +40,7 @@ public class NestedClassForComponentCreateCommand extends EditElementCommand {
/**
* @generated
*/
- private EClass eClass = null;
+ private Diagram diagram = null;
/**
* @generated
@@ -46,24 +50,25 @@ public class NestedClassForComponentCreateCommand extends EditElementCommand {
/**
* @generated
*/
- public NestedClassForComponentCreateCommand(CreateElementRequest req, EObject eObject) {
+ public NestedClassForComponentCreateCommand(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 NestedClassForComponentCreateCommand create(CreateElementRequest req, EObject eObject) {
- return new NestedClassForComponentCreateCommand(req, eObject);
+ public static NestedClassForComponentCreateCommand create(CreateElementRequest req, EObject eObject, Diagram diagram) {
+ return new NestedClassForComponentCreateCommand(req, eObject, diagram);
}
/**
* @generated
*/
- public NestedClassForComponentCreateCommand(CreateElementRequest req) {
+ public NestedClassForComponentCreateCommand(CreateElementRequest req, Diagram diagram) {
super(req.getLabel(), null, req);
+ this.diagram = diagram;
}
/**
@@ -86,7 +91,9 @@ public class NestedClassForComponentCreateCommand extends EditElementCommand {
* @generated
*/
public boolean canExecute() {
- return true;
+ EObject target = getElementToEdit();
+ ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target.eClass(), UMLPackage.eINSTANCE.getClass_());
+ return data.isPermitted();
}
/**
@@ -94,8 +101,19 @@ public class NestedClassForComponentCreateCommand extends EditElementCommand {
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Class newElement = UMLFactory.eINSTANCE.createClass();
- Class owner = (Class)getElementToEdit();
- owner.getNestedClassifiers().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 {
+ Class qualifiedTarget = (Class)target;
+ qualifiedTarget.getNestedClassifiers().add(newElement);
+ }
+ } else {
+ return CommandResult.newErrorCommandResult("The active policy restricts the addition of this element");
+ }
ElementInitializers.getInstance().init_Class_3004(newElement);
doConfigure(newElement, monitor, info);
((CreateElementRequest)getRequest()).setNewElement(newElement);

Back to the top