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.CreateRelationshipRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
18 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
19 | import org.eclipse.gmf.runtime.notation.Edge; |
20 | import org.eclipse.gmf.runtime.notation.Node; |
21 | import org.eclipse.gmf.runtime.notation.View; |
22 | |
23 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionCreateCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionReorientCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.AbstractActionSuccessor_AbstractActionEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.RecoveryActionBehaviourEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviourEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.RecoveryActionRecoveryBlockCompartmentEditPart; |
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 RecoveryAction2ItemSemanticEditPolicy extends |
36 | PalladioComponentModelBaseItemSemanticEditPolicy { |
37 | |
38 | /** |
39 | * @generated |
40 | */ |
41 | public RecoveryAction2ItemSemanticEditPolicy() { |
42 | super(PalladioComponentModelElementTypes.RecoveryAction_3057); |
43 | } |
44 | |
45 | /** |
46 | * @generated |
47 | */ |
48 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
49 | View view = (View) getHost().getModel(); |
50 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
51 | getEditingDomain(), null); |
52 | cmd.setTransactionNestingEnabled(false); |
53 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
54 | Edge incomingLink = (Edge) it.next(); |
55 | if (PalladioComponentModelVisualIDRegistry |
56 | .getVisualID(incomingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
57 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
58 | incomingLink.getSource().getElement(), null, |
59 | incomingLink.getTarget().getElement(), false); |
60 | cmd.add(new DestroyReferenceCommand(r)); |
61 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
62 | continue; |
63 | } |
64 | } |
65 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
66 | Edge outgoingLink = (Edge) it.next(); |
67 | if (PalladioComponentModelVisualIDRegistry |
68 | .getVisualID(outgoingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
69 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
70 | outgoingLink.getSource().getElement(), null, |
71 | outgoingLink.getTarget().getElement(), false); |
72 | cmd.add(new DestroyReferenceCommand(r)); |
73 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
74 | continue; |
75 | } |
76 | } |
77 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
78 | if (annotation == null) { |
79 | // there are indirectly referenced children, need extra commands: false |
80 | addDestroyChildNodesCommand(cmd); |
81 | addDestroyShortcutsCommand(cmd, view); |
82 | // delete host element |
83 | cmd.add(new DestroyElementCommand(req)); |
84 | } else { |
85 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
86 | } |
87 | return getGEFWrapper(cmd.reduce()); |
88 | } |
89 | |
90 | /** |
91 | * @generated |
92 | */ |
93 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
94 | View view = (View) getHost().getModel(); |
95 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
96 | Node node = (Node) nit.next(); |
97 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
98 | case RecoveryActionRecoveryBlockCompartmentEditPart.VISUAL_ID: |
99 | for (Iterator cit = node.getChildren().iterator(); cit |
100 | .hasNext();) { |
101 | Node cnode = (Node) cit.next(); |
102 | switch (PalladioComponentModelVisualIDRegistry |
103 | .getVisualID(cnode)) { |
104 | case RecoveryActionBehaviourEditPart.VISUAL_ID: |
105 | for (Iterator it = cnode.getTargetEdges().iterator(); it |
106 | .hasNext();) { |
107 | Edge incomingLink = (Edge) it.next(); |
108 | if (PalladioComponentModelVisualIDRegistry |
109 | .getVisualID(incomingLink) == RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviourEditPart.VISUAL_ID) { |
110 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
111 | incomingLink.getSource().getElement(), |
112 | null, incomingLink.getTarget() |
113 | .getElement(), false); |
114 | cmd.add(new DestroyReferenceCommand(r)); |
115 | cmd.add(new DeleteCommand(getEditingDomain(), |
116 | incomingLink)); |
117 | continue; |
118 | } |
119 | } |
120 | for (Iterator it = cnode.getSourceEdges().iterator(); it |
121 | .hasNext();) { |
122 | Edge outgoingLink = (Edge) it.next(); |
123 | if (PalladioComponentModelVisualIDRegistry |
124 | .getVisualID(outgoingLink) == RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviourEditPart.VISUAL_ID) { |
125 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
126 | outgoingLink.getSource().getElement(), |
127 | null, outgoingLink.getTarget() |
128 | .getElement(), false); |
129 | cmd.add(new DestroyReferenceCommand(r)); |
130 | cmd.add(new DeleteCommand(getEditingDomain(), |
131 | outgoingLink)); |
132 | continue; |
133 | } |
134 | } |
135 | cmd.add(new DestroyElementCommand( |
136 | new DestroyElementRequest(getEditingDomain(), |
137 | cnode.getElement(), false))); // directlyOwned: true |
138 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
139 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
140 | break; |
141 | } |
142 | } |
143 | break; |
144 | } |
145 | } |
146 | } |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
152 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
153 | : getCompleteCreateRelationshipCommand(req); |
154 | return command != null ? command : super |
155 | .getCreateRelationshipCommand(req); |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected Command getStartCreateRelationshipCommand( |
162 | CreateRelationshipRequest req) { |
163 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
164 | .getElementType()) { |
165 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
166 | req, req.getSource(), req.getTarget())); |
167 | } |
168 | return null; |
169 | } |
170 | |
171 | /** |
172 | * @generated |
173 | */ |
174 | protected Command getCompleteCreateRelationshipCommand( |
175 | CreateRelationshipRequest req) { |
176 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
177 | .getElementType()) { |
178 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
179 | req, req.getSource(), req.getTarget())); |
180 | } |
181 | return null; |
182 | } |
183 | |
184 | /** |
185 | * Returns command to reorient EReference based link. New link target or source |
186 | * should be the domain model element associated with this node. |
187 | * |
188 | * @generated |
189 | */ |
190 | protected Command getReorientReferenceRelationshipCommand( |
191 | ReorientReferenceRelationshipRequest req) { |
192 | switch (getVisualID(req)) { |
193 | case AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID: |
194 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionReorientCommand( |
195 | req)); |
196 | } |
197 | return super.getReorientReferenceRelationshipCommand(req); |
198 | } |
199 | |
200 | } |