1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.edit.parts; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.List; |
8 | |
9 | import org.eclipse.draw2d.ColorConstants; |
10 | import org.eclipse.draw2d.Ellipse; |
11 | import org.eclipse.draw2d.IFigure; |
12 | import org.eclipse.draw2d.MarginBorder; |
13 | import org.eclipse.draw2d.PositionConstants; |
14 | import org.eclipse.draw2d.Shape; |
15 | import org.eclipse.draw2d.StackLayout; |
16 | import org.eclipse.draw2d.geometry.Dimension; |
17 | import org.eclipse.gef.EditPart; |
18 | import org.eclipse.gef.EditPolicy; |
19 | import org.eclipse.gef.Request; |
20 | import org.eclipse.gef.commands.Command; |
21 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
22 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
23 | import org.eclipse.gef.editpolicies.ResizableEditPolicy; |
24 | import org.eclipse.gef.requests.CreateRequest; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
28 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
29 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
30 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
31 | import org.eclipse.gmf.runtime.notation.View; |
32 | import org.eclipse.swt.graphics.Color; |
33 | |
34 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.StopItemSemanticEditPolicy; |
35 | import de.uka.ipd.sdq.pcm.gmf.usage.providers.PalladioComponentModelElementTypes; |
36 | |
37 | /** |
38 | * @generated |
39 | */ |
40 | public class StopEditPart extends ShapeNodeEditPart { |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | public static final int VISUAL_ID = 3002; |
46 | |
47 | /** |
48 | * @generated |
49 | */ |
50 | protected IFigure contentPane; |
51 | |
52 | /** |
53 | * @generated |
54 | */ |
55 | protected IFigure primaryShape; |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | public StopEditPart(View view) { |
61 | super(view); |
62 | } |
63 | |
64 | /** |
65 | * @generated |
66 | */ |
67 | protected void createDefaultEditPolicies() { |
68 | super.createDefaultEditPolicies(); |
69 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
70 | new StopItemSemanticEditPolicy()); |
71 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
72 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
73 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
74 | } |
75 | |
76 | /** |
77 | * @generated |
78 | */ |
79 | protected LayoutEditPolicy createLayoutEditPolicy() { |
80 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
81 | |
82 | protected EditPolicy createChildEditPolicy(EditPart child) { |
83 | EditPolicy result = child |
84 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
85 | if (result == null) { |
86 | result = new NonResizableEditPolicy(); |
87 | } |
88 | return result; |
89 | } |
90 | |
91 | protected Command getMoveChildrenCommand(Request request) { |
92 | return null; |
93 | } |
94 | |
95 | protected Command getCreateCommand(CreateRequest request) { |
96 | return null; |
97 | } |
98 | }; |
99 | return lep; |
100 | } |
101 | |
102 | /** |
103 | * @generated |
104 | */ |
105 | protected IFigure createNodeShape() { |
106 | StopFigure figure = new StopFigure(); |
107 | return primaryShape = figure; |
108 | } |
109 | |
110 | /** |
111 | * @generated |
112 | */ |
113 | public StopFigure getPrimaryShape() { |
114 | return (StopFigure) primaryShape; |
115 | } |
116 | |
117 | /** |
118 | * @generated |
119 | */ |
120 | protected NodeFigure createNodePlate() { |
121 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(30, 30); |
122 | return result; |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | public EditPolicy getPrimaryDragEditPolicy() { |
129 | EditPolicy result = super.getPrimaryDragEditPolicy(); |
130 | if (result instanceof ResizableEditPolicy) { |
131 | ResizableEditPolicy ep = (ResizableEditPolicy) result; |
132 | ep.setResizeDirections(PositionConstants.NONE); |
133 | } |
134 | return result; |
135 | } |
136 | |
137 | /** |
138 | * Creates figure for this edit part. |
139 | * |
140 | * Body of this method does not depend on settings in generation model |
141 | * so you may safely remove <i>generated</i> tag and modify it. |
142 | * |
143 | * @generated |
144 | */ |
145 | protected NodeFigure createNodeFigure() { |
146 | NodeFigure figure = createNodePlate(); |
147 | figure.setLayoutManager(new StackLayout()); |
148 | IFigure shape = createNodeShape(); |
149 | figure.add(shape); |
150 | contentPane = setupContentPane(shape); |
151 | return figure; |
152 | } |
153 | |
154 | /** |
155 | * Default implementation treats passed figure as content pane. |
156 | * Respects layout one may have set for generated figure. |
157 | * @param nodeShape instance of generated figure class |
158 | * @generated |
159 | */ |
160 | protected IFigure setupContentPane(IFigure nodeShape) { |
161 | return nodeShape; // use nodeShape itself as contentPane |
162 | } |
163 | |
164 | /** |
165 | * @generated |
166 | */ |
167 | public IFigure getContentPane() { |
168 | if (contentPane != null) { |
169 | return contentPane; |
170 | } |
171 | return super.getContentPane(); |
172 | } |
173 | |
174 | /** |
175 | * @generated |
176 | */ |
177 | protected void setForegroundColor(Color color) { |
178 | if (primaryShape != null) { |
179 | primaryShape.setForegroundColor(color); |
180 | } |
181 | } |
182 | |
183 | /** |
184 | * @generated |
185 | */ |
186 | protected void setBackgroundColor(Color color) { |
187 | if (primaryShape != null) { |
188 | primaryShape.setBackgroundColor(color); |
189 | } |
190 | } |
191 | |
192 | /** |
193 | * @generated |
194 | */ |
195 | protected void setLineWidth(int width) { |
196 | if (primaryShape instanceof Shape) { |
197 | ((Shape) primaryShape).setLineWidth(width); |
198 | } |
199 | } |
200 | |
201 | /** |
202 | * @generated |
203 | */ |
204 | protected void setLineType(int style) { |
205 | if (primaryShape instanceof Shape) { |
206 | ((Shape) primaryShape).setLineStyle(style); |
207 | } |
208 | } |
209 | |
210 | /** |
211 | * @generated |
212 | */ |
213 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
214 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
215 | types |
216 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
217 | return types; |
218 | } |
219 | |
220 | /** |
221 | * @generated |
222 | */ |
223 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
224 | IGraphicalEditPart targetEditPart) { |
225 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
226 | if (targetEditPart instanceof StartEditPart) { |
227 | types |
228 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
229 | } |
230 | if (targetEditPart instanceof de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.StopEditPart) { |
231 | types |
232 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
233 | } |
234 | if (targetEditPart instanceof EntryLevelSystemCallEditPart) { |
235 | types |
236 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
237 | } |
238 | if (targetEditPart instanceof LoopEditPart) { |
239 | types |
240 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
241 | } |
242 | if (targetEditPart instanceof BranchEditPart) { |
243 | types |
244 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
245 | } |
246 | if (targetEditPart instanceof DelayEditPart) { |
247 | types |
248 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
249 | } |
250 | return types; |
251 | } |
252 | |
253 | /** |
254 | * @generated |
255 | */ |
256 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
257 | IElementType relationshipType) { |
258 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
259 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
260 | types.add(PalladioComponentModelElementTypes.Start_3001); |
261 | } |
262 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
263 | types.add(PalladioComponentModelElementTypes.Stop_3002); |
264 | } |
265 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
266 | types |
267 | .add(PalladioComponentModelElementTypes.EntryLevelSystemCall_3003); |
268 | } |
269 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
270 | types.add(PalladioComponentModelElementTypes.Loop_3005); |
271 | } |
272 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
273 | types.add(PalladioComponentModelElementTypes.Branch_3008); |
274 | } |
275 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
276 | types.add(PalladioComponentModelElementTypes.Delay_3017); |
277 | } |
278 | return types; |
279 | } |
280 | |
281 | /** |
282 | * @generated |
283 | */ |
284 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
285 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
286 | types |
287 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
288 | return types; |
289 | } |
290 | |
291 | /** |
292 | * @generated |
293 | */ |
294 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
295 | IElementType relationshipType) { |
296 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
297 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
298 | types.add(PalladioComponentModelElementTypes.Start_3001); |
299 | } |
300 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
301 | types.add(PalladioComponentModelElementTypes.Stop_3002); |
302 | } |
303 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
304 | types |
305 | .add(PalladioComponentModelElementTypes.EntryLevelSystemCall_3003); |
306 | } |
307 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
308 | types.add(PalladioComponentModelElementTypes.Loop_3005); |
309 | } |
310 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
311 | types.add(PalladioComponentModelElementTypes.Branch_3008); |
312 | } |
313 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
314 | types.add(PalladioComponentModelElementTypes.Delay_3017); |
315 | } |
316 | return types; |
317 | } |
318 | |
319 | /** |
320 | * @generated |
321 | */ |
322 | public class StopFigure extends Ellipse { |
323 | /** |
324 | * @generated |
325 | */ |
326 | public StopFigure() { |
327 | this.setLayoutManager(new StackLayout()); |
328 | this.setLineWidth(1); |
329 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(30), |
330 | getMapMode().DPtoLP(30))); |
331 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
332 | getMapMode().DPtoLP(0))); |
333 | |
334 | this.setBorder(new MarginBorder(getMapMode().DPtoLP(3), |
335 | getMapMode().DPtoLP(3), getMapMode().DPtoLP(3), |
336 | getMapMode().DPtoLP(3))); |
337 | createContents(); |
338 | } |
339 | |
340 | /** |
341 | * @generated |
342 | */ |
343 | private void createContents() { |
344 | |
345 | Ellipse innerCircle0 = new Ellipse(); |
346 | innerCircle0.setLineWidth(1); |
347 | innerCircle0.setBackgroundColor(ColorConstants.black); |
348 | |
349 | this.add(innerCircle0); |
350 | |
351 | } |
352 | |
353 | /** |
354 | * @generated |
355 | */ |
356 | private boolean myUseLocalCoordinates = false; |
357 | |
358 | /** |
359 | * @generated |
360 | */ |
361 | protected boolean useLocalCoordinates() { |
362 | return myUseLocalCoordinates; |
363 | } |
364 | |
365 | /** |
366 | * @generated |
367 | */ |
368 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
369 | myUseLocalCoordinates = useLocalCoordinates; |
370 | } |
371 | |
372 | } |
373 | |
374 | } |