1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.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.diagram.core.commands.DeleteCommand; |
11 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
16 | import org.eclipse.gmf.runtime.notation.Edge; |
17 | import org.eclipse.gmf.runtime.notation.View; |
18 | |
19 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureProvidedRoleCreateCommand; |
20 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureProvidedRoleReorientCommand; |
21 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureRequiredRoleCreateCommand; |
22 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.InfrastructureRequiredRoleReorientCommand; |
23 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationProvidedRoleCreateCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationProvidedRoleReorientCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationRequiredRoleCreateCommand; |
26 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.OperationRequiredRoleReorientCommand; |
27 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SinkRoleCreateCommand; |
28 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SinkRoleReorientCommand; |
29 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SourceRoleCreateCommand; |
30 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.commands.SourceRoleReorientCommand; |
31 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureProvidedRoleEditPart; |
32 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.InfrastructureRequiredRoleEditPart; |
33 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationProvidedRoleEditPart; |
34 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.OperationRequiredRoleEditPart; |
35 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SinkRoleEditPart; |
36 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.SourceRoleEditPart; |
37 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry; |
38 | import de.uka.ipd.sdq.pcm.gmf.repository.providers.PalladioComponentModelElementTypes; |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | public class SubSystemItemSemanticEditPolicy extends |
44 | PalladioComponentModelBaseItemSemanticEditPolicy { |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public SubSystemItemSemanticEditPolicy() { |
50 | super(PalladioComponentModelElementTypes.SubSystem_2106); |
51 | } |
52 | |
53 | /** |
54 | * @generated |
55 | */ |
56 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
57 | View view = (View) getHost().getModel(); |
58 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
59 | getEditingDomain(), null); |
60 | cmd.setTransactionNestingEnabled(false); |
61 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
62 | Edge outgoingLink = (Edge) it.next(); |
63 | if (PalladioComponentModelVisualIDRegistry |
64 | .getVisualID(outgoingLink) == OperationProvidedRoleEditPart.VISUAL_ID) { |
65 | DestroyElementRequest r = new DestroyElementRequest( |
66 | outgoingLink.getElement(), false); |
67 | cmd.add(new DestroyElementCommand(r)); |
68 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
69 | continue; |
70 | } |
71 | if (PalladioComponentModelVisualIDRegistry |
72 | .getVisualID(outgoingLink) == InfrastructureProvidedRoleEditPart.VISUAL_ID) { |
73 | DestroyElementRequest r = new DestroyElementRequest( |
74 | outgoingLink.getElement(), false); |
75 | cmd.add(new DestroyElementCommand(r)); |
76 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
77 | continue; |
78 | } |
79 | if (PalladioComponentModelVisualIDRegistry |
80 | .getVisualID(outgoingLink) == InfrastructureRequiredRoleEditPart.VISUAL_ID) { |
81 | DestroyElementRequest r = new DestroyElementRequest( |
82 | outgoingLink.getElement(), false); |
83 | cmd.add(new DestroyElementCommand(r)); |
84 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
85 | continue; |
86 | } |
87 | if (PalladioComponentModelVisualIDRegistry |
88 | .getVisualID(outgoingLink) == SinkRoleEditPart.VISUAL_ID) { |
89 | DestroyElementRequest r = new DestroyElementRequest( |
90 | outgoingLink.getElement(), false); |
91 | cmd.add(new DestroyElementCommand(r)); |
92 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
93 | continue; |
94 | } |
95 | if (PalladioComponentModelVisualIDRegistry |
96 | .getVisualID(outgoingLink) == OperationRequiredRoleEditPart.VISUAL_ID) { |
97 | DestroyElementRequest r = new DestroyElementRequest( |
98 | outgoingLink.getElement(), false); |
99 | cmd.add(new DestroyElementCommand(r)); |
100 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
101 | continue; |
102 | } |
103 | if (PalladioComponentModelVisualIDRegistry |
104 | .getVisualID(outgoingLink) == SourceRoleEditPart.VISUAL_ID) { |
105 | DestroyElementRequest r = new DestroyElementRequest( |
106 | outgoingLink.getElement(), false); |
107 | cmd.add(new DestroyElementCommand(r)); |
108 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
109 | continue; |
110 | } |
111 | } |
112 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
113 | if (annotation == null) { |
114 | // there are indirectly referenced children, need extra commands: false |
115 | addDestroyShortcutsCommand(cmd, view); |
116 | // delete host element |
117 | cmd.add(new DestroyElementCommand(req)); |
118 | } else { |
119 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
120 | } |
121 | return getGEFWrapper(cmd.reduce()); |
122 | } |
123 | |
124 | /** |
125 | * @generated |
126 | */ |
127 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
128 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
129 | : getCompleteCreateRelationshipCommand(req); |
130 | return command != null ? command : super |
131 | .getCreateRelationshipCommand(req); |
132 | } |
133 | |
134 | /** |
135 | * @generated |
136 | */ |
137 | protected Command getStartCreateRelationshipCommand( |
138 | CreateRelationshipRequest req) { |
139 | if (PalladioComponentModelElementTypes.OperationProvidedRole_4105 == req |
140 | .getElementType()) { |
141 | return getGEFWrapper(new OperationProvidedRoleCreateCommand(req, |
142 | req.getSource(), req.getTarget())); |
143 | } |
144 | if (PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111 == req |
145 | .getElementType()) { |
146 | return getGEFWrapper(new InfrastructureProvidedRoleCreateCommand( |
147 | req, req.getSource(), req.getTarget())); |
148 | } |
149 | if (PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112 == req |
150 | .getElementType()) { |
151 | return getGEFWrapper(new InfrastructureRequiredRoleCreateCommand( |
152 | req, req.getSource(), req.getTarget())); |
153 | } |
154 | if (PalladioComponentModelElementTypes.SinkRole_4109 == req |
155 | .getElementType()) { |
156 | return getGEFWrapper(new SinkRoleCreateCommand(req, |
157 | req.getSource(), req.getTarget())); |
158 | } |
159 | if (PalladioComponentModelElementTypes.OperationRequiredRole_4106 == req |
160 | .getElementType()) { |
161 | return getGEFWrapper(new OperationRequiredRoleCreateCommand(req, |
162 | req.getSource(), req.getTarget())); |
163 | } |
164 | if (PalladioComponentModelElementTypes.SourceRole_4110 == req |
165 | .getElementType()) { |
166 | return getGEFWrapper(new SourceRoleCreateCommand(req, req |
167 | .getSource(), req.getTarget())); |
168 | } |
169 | return null; |
170 | } |
171 | |
172 | /** |
173 | * @generated |
174 | */ |
175 | protected Command getCompleteCreateRelationshipCommand( |
176 | CreateRelationshipRequest req) { |
177 | if (PalladioComponentModelElementTypes.OperationProvidedRole_4105 == req |
178 | .getElementType()) { |
179 | return null; |
180 | } |
181 | if (PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111 == req |
182 | .getElementType()) { |
183 | return null; |
184 | } |
185 | if (PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112 == req |
186 | .getElementType()) { |
187 | return null; |
188 | } |
189 | if (PalladioComponentModelElementTypes.SinkRole_4109 == req |
190 | .getElementType()) { |
191 | return null; |
192 | } |
193 | if (PalladioComponentModelElementTypes.OperationRequiredRole_4106 == req |
194 | .getElementType()) { |
195 | return null; |
196 | } |
197 | if (PalladioComponentModelElementTypes.SourceRole_4110 == req |
198 | .getElementType()) { |
199 | return null; |
200 | } |
201 | return null; |
202 | } |
203 | |
204 | /** |
205 | * Returns command to reorient EClass based link. New link target or source |
206 | * should be the domain model element associated with this node. |
207 | * |
208 | * @generated |
209 | */ |
210 | protected Command getReorientRelationshipCommand( |
211 | ReorientRelationshipRequest req) { |
212 | switch (getVisualID(req)) { |
213 | case OperationProvidedRoleEditPart.VISUAL_ID: |
214 | return getGEFWrapper(new OperationProvidedRoleReorientCommand(req)); |
215 | case InfrastructureProvidedRoleEditPart.VISUAL_ID: |
216 | return getGEFWrapper(new InfrastructureProvidedRoleReorientCommand( |
217 | req)); |
218 | case InfrastructureRequiredRoleEditPart.VISUAL_ID: |
219 | return getGEFWrapper(new InfrastructureRequiredRoleReorientCommand( |
220 | req)); |
221 | case SinkRoleEditPart.VISUAL_ID: |
222 | return getGEFWrapper(new SinkRoleReorientCommand(req)); |
223 | case OperationRequiredRoleEditPart.VISUAL_ID: |
224 | return getGEFWrapper(new OperationRequiredRoleReorientCommand(req)); |
225 | case SourceRoleEditPart.VISUAL_ID: |
226 | return getGEFWrapper(new SourceRoleReorientCommand(req)); |
227 | } |
228 | return super.getReorientRelationshipCommand(req); |
229 | } |
230 | |
231 | } |