blob: d72b16e195ab92bb06c8cb77a6d4cbc53d838c6e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
package org.eclipse.papyrus.uml.service.types.helper;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.command.MoveCommand;
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.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.uml.service.types.command.NotContainmentMoveCommand;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.InterruptibleActivityRegion;
import org.eclipse.uml2.uml.UMLPackage;
public class InterruptibleActivityRegionHelper extends ActivityGroupHelper {
@Override
protected ICommand getCreateCommand(CreateElementRequest req) {
CreateElementRequest createRequest = isActivityNode(req.getElementType()) ? initCreateActivityNodeRequestInInterruptibleRegion(req) : req;
return super.getCreateCommand(createRequest);
}
/**
* {@link InterruptibleActivityRegion} cannot contain any {@link ActivityNode}.
* That's why we create new element in {@link Activity} and added it to {@link InterruptibleActivityRegion#getNodes()} referenced list
*
* @param baseReq {@link CreateElementRequest} from ItemSemanticEditPolicy with not containment {@link InterruptibleActivityRegion#getNodes()} feature
* @return new {@link CreateElementRequest} with {@link Activity} as container and right containment {@link ActivityNode} feature
*/
protected CreateElementRequest initCreateActivityNodeRequestInInterruptibleRegion(CreateElementRequest baseReq) {
if (baseReq == null) {
return null;
}
CreateElementRequest req = new CreateElementRequest(baseReq.getElementType());
InterruptibleActivityRegion inrruptibleActivityRegion = ((InterruptibleActivityRegion)baseReq.getContainer());
req.setContainer(inrruptibleActivityRegion.getInActivity());
req.setContainmentFeature(findActivityFeature(baseReq.getElementType().getEClass()));
req.setParameter(ActivityNodeHelper.IN_INTERRUPTIBLE_ACTIVITY_REGION, inrruptibleActivityRegion);
return req;
}
/**
* Find {@link Activity} feature appropriate to {@link InterruptibleActivityRegion} feature.
*
* @return Appropriate feature.
*/
protected EReference findActivityFeature(EClass eClass) {
if (UMLPackage.eINSTANCE.getStructuredActivityNode().isSuperTypeOf(eClass)) {
return UMLPackage.eINSTANCE.getActivity_StructuredNode();
}
return UMLPackage.eINSTANCE.getActivity_OwnedNode();
}
private boolean isActivityNode(IElementType type) {
return UMLPackage.eINSTANCE.getActivityNode().isSuperTypeOf(type.getEClass());
}
@Override
protected ICommand getMoveCommand(MoveRequest req) {
if (req != null) {
if (isTargetContainerInterruptibleActivityRegioin(req)) {
return createMoveCommandWithSetReference(req, UMLPackage.eINSTANCE.getInterruptibleActivityRegion_Node());
}
}
return super.getMoveCommand(req);
}
private boolean isTargetContainerInterruptibleActivityRegioin(MoveRequest req) {
return req.getTargetContainer() instanceof InterruptibleActivityRegion;
}
/**
* This method create {@link CompositeCommand}. It contain redirected {@link MoveCommand} to Activity
* and commands to set references on ActivityNodes for base container which can't contain they.
*
* @param req base {@MoveRequest}
* @param featureToSetReference {@link EReference} to set {@link ActivityNode} in base request target container's referenced list
* @return {@link CompositeCommand} which contain {@link MoveCommand} elements to Activity and {@link SetValueCommand}s to base container's referenced list
*/
protected ICommand createMoveCommandWithSetReference(MoveRequest req, EReference featureToSetReference) {
EObject nonContainmentContainer = (EObject)req.getTargetContainer();
CompositeCommand result = new CompositeCommand("Move elements in non containment Activity container");
MoveElementsCommand moveCommand = new NotContainmentMoveCommand(createMoveToActivityRequest(req));
result.add(moveCommand);
for (Object o: req.getElementsToMove().keySet()) {
if (o instanceof ActivityNode) {
result.add(new SetValueCommand(new SetRequest(nonContainmentContainer, featureToSetReference, o)));
}
}
return result;
}
/**
* @param base move request in which target container can't contain {@link ActivityNode}
* @return {@link MoveRequest} in which replaced base container on {@link Activity}and replaced containment features for it.
*/
protected MoveRequest createMoveToActivityRequest(MoveRequest baseReq) {
if (baseReq == null) {
return null;
}
MoveRequest result = new MoveRequest(baseReq.getEditingDomain(), ((InterruptibleActivityRegion)(baseReq.getTargetContainer())).getInActivity(), baseReq.getElementsToMove());
for (Object o : baseReq.getElementsToMove().keySet()) {
if (o instanceof ActivityNode) {
ActivityNode node = (ActivityNode)o;
result.setTargetFeature(node ,findActivityFeature(node.eClass()));
}
}
return result;
}
}
|