1 | /* |
2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.edit.policies; |
5 | |
6 | import java.util.Iterator; |
7 | |
8 | import org.eclipse.emf.ecore.EAnnotation; |
9 | import org.eclipse.gef.commands.Command; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand; |
11 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
12 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
18 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
19 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
20 | import org.eclipse.gmf.runtime.notation.Edge; |
21 | import org.eclipse.gmf.runtime.notation.Node; |
22 | import org.eclipse.gmf.runtime.notation.View; |
23 | |
24 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionCreateCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionReorientCommand; |
26 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.ResourceDemandingBehaviourCreateCommand; |
27 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.AbstractActionSuccessor_AbstractActionEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.ResourceDemandingBehaviourEditPart; |
29 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
30 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
31 | |
32 | /** |
33 | * @generated |
34 | */ |
35 | public class LoopActionItemSemanticEditPolicy extends |
36 | PalladioComponentModelBaseItemSemanticEditPolicy { |
37 | |
38 | /** |
39 | * @generated |
40 | */ |
41 | public LoopActionItemSemanticEditPolicy() { |
42 | super(PalladioComponentModelElementTypes.LoopAction_2004); |
43 | } |
44 | |
45 | /** |
46 | * @generated |
47 | */ |
48 | protected Command getCreateCommand(CreateElementRequest req) { |
49 | if (PalladioComponentModelElementTypes.ResourceDemandingBehaviour_3003 == req |
50 | .getElementType()) { |
51 | return getGEFWrapper(new ResourceDemandingBehaviourCreateCommand( |
52 | req)); |
53 | } |
54 | return super.getCreateCommand(req); |
55 | } |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
61 | View view = (View) getHost().getModel(); |
62 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
63 | getEditingDomain(), null); |
64 | cmd.setTransactionNestingEnabled(false); |
65 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
66 | Edge incomingLink = (Edge) it.next(); |
67 | if (PalladioComponentModelVisualIDRegistry |
68 | .getVisualID(incomingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
69 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
70 | incomingLink.getSource().getElement(), null, |
71 | incomingLink.getTarget().getElement(), false); |
72 | cmd.add(new DestroyReferenceCommand(r)); |
73 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
74 | continue; |
75 | } |
76 | } |
77 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
78 | Edge outgoingLink = (Edge) it.next(); |
79 | if (PalladioComponentModelVisualIDRegistry |
80 | .getVisualID(outgoingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
81 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
82 | outgoingLink.getSource().getElement(), null, |
83 | outgoingLink.getTarget().getElement(), false); |
84 | cmd.add(new DestroyReferenceCommand(r)); |
85 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
86 | continue; |
87 | } |
88 | } |
89 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
90 | if (annotation == null) { |
91 | // there are indirectly referenced children, need extra commands: false |
92 | addDestroyChildNodesCommand(cmd); |
93 | addDestroyShortcutsCommand(cmd, view); |
94 | // delete host element |
95 | cmd.add(new DestroyElementCommand(req)); |
96 | } else { |
97 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
98 | } |
99 | return getGEFWrapper(cmd.reduce()); |
100 | } |
101 | |
102 | /** |
103 | * @generated |
104 | */ |
105 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
106 | View view = (View) getHost().getModel(); |
107 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
108 | Node node = (Node) nit.next(); |
109 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
110 | case ResourceDemandingBehaviourEditPart.VISUAL_ID: |
111 | cmd.add(new DestroyElementCommand(new DestroyElementRequest( |
112 | getEditingDomain(), node.getElement(), false))); // directlyOwned: true |
113 | // don't need explicit deletion of node as parent's view deletion would clean child views as well |
114 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), node)); |
115 | break; |
116 | } |
117 | } |
118 | } |
119 | |
120 | /** |
121 | * @generated |
122 | */ |
123 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
124 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
125 | : getCompleteCreateRelationshipCommand(req); |
126 | return command != null ? command : super |
127 | .getCreateRelationshipCommand(req); |
128 | } |
129 | |
130 | /** |
131 | * @generated |
132 | */ |
133 | protected Command getStartCreateRelationshipCommand( |
134 | CreateRelationshipRequest req) { |
135 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
136 | .getElementType()) { |
137 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
138 | req, req.getSource(), req.getTarget())); |
139 | } |
140 | return null; |
141 | } |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | protected Command getCompleteCreateRelationshipCommand( |
147 | CreateRelationshipRequest req) { |
148 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
149 | .getElementType()) { |
150 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
151 | req, req.getSource(), req.getTarget())); |
152 | } |
153 | return null; |
154 | } |
155 | |
156 | /** |
157 | * Returns command to reorient EReference based link. New link target or source |
158 | * should be the domain model element associated with this node. |
159 | * |
160 | * @generated |
161 | */ |
162 | protected Command getReorientReferenceRelationshipCommand( |
163 | ReorientReferenceRelationshipRequest req) { |
164 | switch (getVisualID(req)) { |
165 | case AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID: |
166 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionReorientCommand( |
167 | req)); |
168 | } |
169 | return super.getReorientReferenceRelationshipCommand(req); |
170 | } |
171 | |
172 | } |