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.GridData; |
10 | import org.eclipse.draw2d.GridLayout; |
11 | import org.eclipse.draw2d.IFigure; |
12 | import org.eclipse.draw2d.MarginBorder; |
13 | import org.eclipse.draw2d.RoundedRectangle; |
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.requests.CreateRequest; |
24 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; |
28 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
29 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
30 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
31 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
32 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
33 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
34 | import org.eclipse.gmf.runtime.notation.View; |
35 | import org.eclipse.swt.SWT; |
36 | import org.eclipse.swt.graphics.Color; |
37 | |
38 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.LoopCanonicalEditPolicy; |
39 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.LoopItemSemanticEditPolicy; |
40 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
41 | import de.uka.ipd.sdq.pcm.gmf.usage.providers.PalladioComponentModelElementTypes; |
42 | |
43 | /** |
44 | * @generated |
45 | */ |
46 | public class LoopEditPart extends ShapeNodeEditPart { |
47 | |
48 | /** |
49 | * @generated |
50 | */ |
51 | public static final int VISUAL_ID = 3005; |
52 | |
53 | /** |
54 | * @generated |
55 | */ |
56 | protected IFigure contentPane; |
57 | |
58 | /** |
59 | * @generated |
60 | */ |
61 | protected IFigure primaryShape; |
62 | |
63 | /** |
64 | * @generated |
65 | */ |
66 | public LoopEditPart(View view) { |
67 | super(view); |
68 | } |
69 | |
70 | /** |
71 | * @generated |
72 | */ |
73 | protected void createDefaultEditPolicies() { |
74 | installEditPolicy(EditPolicyRoles.CREATION_ROLE, |
75 | new CreationEditPolicy()); |
76 | super.createDefaultEditPolicies(); |
77 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
78 | new LoopItemSemanticEditPolicy()); |
79 | installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, |
80 | new DragDropEditPolicy()); |
81 | installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, |
82 | new LoopCanonicalEditPolicy()); |
83 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
84 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
85 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
86 | } |
87 | |
88 | /** |
89 | * @generated |
90 | */ |
91 | protected LayoutEditPolicy createLayoutEditPolicy() { |
92 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
93 | |
94 | protected EditPolicy createChildEditPolicy(EditPart child) { |
95 | EditPolicy result = child |
96 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
97 | if (result == null) { |
98 | result = new NonResizableEditPolicy(); |
99 | } |
100 | return result; |
101 | } |
102 | |
103 | protected Command getMoveChildrenCommand(Request request) { |
104 | return null; |
105 | } |
106 | |
107 | protected Command getCreateCommand(CreateRequest request) { |
108 | return null; |
109 | } |
110 | }; |
111 | return lep; |
112 | } |
113 | |
114 | /** |
115 | * @generated |
116 | */ |
117 | protected IFigure createNodeShape() { |
118 | UsageLoopFigure figure = new UsageLoopFigure(); |
119 | return primaryShape = figure; |
120 | } |
121 | |
122 | /** |
123 | * @generated |
124 | */ |
125 | public UsageLoopFigure getPrimaryShape() { |
126 | return (UsageLoopFigure) primaryShape; |
127 | } |
128 | |
129 | /** |
130 | * @generated |
131 | */ |
132 | protected boolean addFixedChild(EditPart childEditPart) { |
133 | if (childEditPart instanceof UsageLoopIterationsLabelEditPart) { |
134 | ((UsageLoopIterationsLabelEditPart) childEditPart) |
135 | .setLabel(getPrimaryShape() |
136 | .getFigureUsageLoopIterationsLabelFigure()); |
137 | return true; |
138 | } |
139 | return false; |
140 | } |
141 | |
142 | /** |
143 | * @generated |
144 | */ |
145 | protected boolean removeFixedChild(EditPart childEditPart) { |
146 | if (childEditPart instanceof UsageLoopIterationsLabelEditPart) { |
147 | return true; |
148 | } |
149 | return false; |
150 | } |
151 | |
152 | /** |
153 | * @generated |
154 | */ |
155 | protected void addChildVisual(EditPart childEditPart, int index) { |
156 | if (addFixedChild(childEditPart)) { |
157 | return; |
158 | } |
159 | super.addChildVisual(childEditPart, -1); |
160 | } |
161 | |
162 | /** |
163 | * @generated |
164 | */ |
165 | protected void removeChildVisual(EditPart childEditPart) { |
166 | if (removeFixedChild(childEditPart)) { |
167 | return; |
168 | } |
169 | super.removeChildVisual(childEditPart); |
170 | } |
171 | |
172 | /** |
173 | * @generated |
174 | */ |
175 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
176 | return getContentPane(); |
177 | } |
178 | |
179 | /** |
180 | * @generated |
181 | */ |
182 | protected NodeFigure createNodePlate() { |
183 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
184 | return result; |
185 | } |
186 | |
187 | /** |
188 | * Creates figure for this edit part. |
189 | * |
190 | * Body of this method does not depend on settings in generation model |
191 | * so you may safely remove <i>generated</i> tag and modify it. |
192 | * |
193 | * @generated |
194 | */ |
195 | protected NodeFigure createNodeFigure() { |
196 | NodeFigure figure = createNodePlate(); |
197 | figure.setLayoutManager(new StackLayout()); |
198 | IFigure shape = createNodeShape(); |
199 | figure.add(shape); |
200 | contentPane = setupContentPane(shape); |
201 | return figure; |
202 | } |
203 | |
204 | /** |
205 | * Default implementation treats passed figure as content pane. |
206 | * Respects layout one may have set for generated figure. |
207 | * @param nodeShape instance of generated figure class |
208 | * @generated |
209 | */ |
210 | protected IFigure setupContentPane(IFigure nodeShape) { |
211 | if (nodeShape.getLayoutManager() == null) { |
212 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
213 | layout.setSpacing(5); |
214 | nodeShape.setLayoutManager(layout); |
215 | } |
216 | return nodeShape; // use nodeShape itself as contentPane |
217 | } |
218 | |
219 | /** |
220 | * @generated |
221 | */ |
222 | public IFigure getContentPane() { |
223 | if (contentPane != null) { |
224 | return contentPane; |
225 | } |
226 | return super.getContentPane(); |
227 | } |
228 | |
229 | /** |
230 | * @generated |
231 | */ |
232 | protected void setForegroundColor(Color color) { |
233 | if (primaryShape != null) { |
234 | primaryShape.setForegroundColor(color); |
235 | } |
236 | } |
237 | |
238 | /** |
239 | * @generated |
240 | */ |
241 | protected void setBackgroundColor(Color color) { |
242 | if (primaryShape != null) { |
243 | primaryShape.setBackgroundColor(color); |
244 | } |
245 | } |
246 | |
247 | /** |
248 | * @generated |
249 | */ |
250 | protected void setLineWidth(int width) { |
251 | if (primaryShape instanceof Shape) { |
252 | ((Shape) primaryShape).setLineWidth(width); |
253 | } |
254 | } |
255 | |
256 | /** |
257 | * @generated |
258 | */ |
259 | protected void setLineType(int style) { |
260 | if (primaryShape instanceof Shape) { |
261 | ((Shape) primaryShape).setLineStyle(style); |
262 | } |
263 | } |
264 | |
265 | /** |
266 | * @generated |
267 | */ |
268 | public EditPart getPrimaryChildEditPart() { |
269 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
270 | .getType(UsageLoopIterationsLabelEditPart.VISUAL_ID)); |
271 | } |
272 | |
273 | /** |
274 | * @generated |
275 | */ |
276 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
277 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
278 | types |
279 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
280 | return types; |
281 | } |
282 | |
283 | /** |
284 | * @generated |
285 | */ |
286 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
287 | IGraphicalEditPart targetEditPart) { |
288 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
289 | if (targetEditPart instanceof StartEditPart) { |
290 | types |
291 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
292 | } |
293 | if (targetEditPart instanceof StopEditPart) { |
294 | types |
295 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
296 | } |
297 | if (targetEditPart instanceof EntryLevelSystemCallEditPart) { |
298 | types |
299 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
300 | } |
301 | if (targetEditPart instanceof de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.LoopEditPart) { |
302 | types |
303 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
304 | } |
305 | if (targetEditPart instanceof BranchEditPart) { |
306 | types |
307 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
308 | } |
309 | if (targetEditPart instanceof DelayEditPart) { |
310 | types |
311 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
312 | } |
313 | return types; |
314 | } |
315 | |
316 | /** |
317 | * @generated |
318 | */ |
319 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
320 | IElementType relationshipType) { |
321 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
322 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
323 | types.add(PalladioComponentModelElementTypes.Start_3001); |
324 | } |
325 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
326 | types.add(PalladioComponentModelElementTypes.Stop_3002); |
327 | } |
328 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
329 | types |
330 | .add(PalladioComponentModelElementTypes.EntryLevelSystemCall_3003); |
331 | } |
332 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
333 | types.add(PalladioComponentModelElementTypes.Loop_3005); |
334 | } |
335 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
336 | types.add(PalladioComponentModelElementTypes.Branch_3008); |
337 | } |
338 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
339 | types.add(PalladioComponentModelElementTypes.Delay_3017); |
340 | } |
341 | return types; |
342 | } |
343 | |
344 | /** |
345 | * @generated |
346 | */ |
347 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
348 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
349 | types |
350 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
351 | return types; |
352 | } |
353 | |
354 | /** |
355 | * @generated |
356 | */ |
357 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
358 | IElementType relationshipType) { |
359 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
360 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
361 | types.add(PalladioComponentModelElementTypes.Start_3001); |
362 | } |
363 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
364 | types.add(PalladioComponentModelElementTypes.Stop_3002); |
365 | } |
366 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
367 | types |
368 | .add(PalladioComponentModelElementTypes.EntryLevelSystemCall_3003); |
369 | } |
370 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
371 | types.add(PalladioComponentModelElementTypes.Loop_3005); |
372 | } |
373 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
374 | types.add(PalladioComponentModelElementTypes.Branch_3008); |
375 | } |
376 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
377 | types.add(PalladioComponentModelElementTypes.Delay_3017); |
378 | } |
379 | return types; |
380 | } |
381 | |
382 | /** |
383 | * @generated |
384 | */ |
385 | public class UsageLoopFigure extends RoundedRectangle { |
386 | /** |
387 | * @generated |
388 | */ |
389 | private WrappingLabel fFigureUsageLoopIterationsLabelFigure; |
390 | |
391 | /** |
392 | * @generated |
393 | */ |
394 | public UsageLoopFigure() { |
395 | |
396 | GridLayout layoutThis = new GridLayout(); |
397 | layoutThis.numColumns = 1; |
398 | layoutThis.makeColumnsEqualWidth = true; |
399 | layoutThis.horizontalSpacing = 0; |
400 | layoutThis.verticalSpacing = 0; |
401 | layoutThis.marginWidth = 0; |
402 | layoutThis.marginHeight = 0; |
403 | this.setLayoutManager(layoutThis); |
404 | |
405 | this.setCornerDimensions(new Dimension(getMapMode().DPtoLP(8), |
406 | getMapMode().DPtoLP(8))); |
407 | this.setLineWidth(1); |
408 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
409 | getMapMode().DPtoLP(0))); |
410 | createContents(); |
411 | } |
412 | |
413 | /** |
414 | * @generated |
415 | */ |
416 | private void createContents() { |
417 | |
418 | WrappingLabel usageLoopStereotypeLabelFigure0 = new WrappingLabel(); |
419 | usageLoopStereotypeLabelFigure0.setText("<<Loop>>"); |
420 | usageLoopStereotypeLabelFigure0.setBorder(new MarginBorder( |
421 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
422 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
423 | |
424 | GridData constraintUsageLoopStereotypeLabelFigure0 = new GridData(); |
425 | constraintUsageLoopStereotypeLabelFigure0.verticalAlignment = GridData.BEGINNING; |
426 | constraintUsageLoopStereotypeLabelFigure0.horizontalAlignment = GridData.CENTER; |
427 | constraintUsageLoopStereotypeLabelFigure0.horizontalIndent = 0; |
428 | constraintUsageLoopStereotypeLabelFigure0.horizontalSpan = 1; |
429 | constraintUsageLoopStereotypeLabelFigure0.verticalSpan = 1; |
430 | constraintUsageLoopStereotypeLabelFigure0.grabExcessHorizontalSpace = true; |
431 | constraintUsageLoopStereotypeLabelFigure0.grabExcessVerticalSpace = false; |
432 | this.add(usageLoopStereotypeLabelFigure0, |
433 | constraintUsageLoopStereotypeLabelFigure0); |
434 | |
435 | fFigureUsageLoopIterationsLabelFigure = new WrappingLabel(); |
436 | fFigureUsageLoopIterationsLabelFigure.setText(""); |
437 | fFigureUsageLoopIterationsLabelFigure.setBorder(new MarginBorder( |
438 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
439 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
440 | |
441 | GridData constraintFFigureUsageLoopIterationsLabelFigure = new GridData(); |
442 | constraintFFigureUsageLoopIterationsLabelFigure.verticalAlignment = GridData.CENTER; |
443 | constraintFFigureUsageLoopIterationsLabelFigure.horizontalAlignment = GridData.CENTER; |
444 | constraintFFigureUsageLoopIterationsLabelFigure.horizontalIndent = 0; |
445 | constraintFFigureUsageLoopIterationsLabelFigure.horizontalSpan = 1; |
446 | constraintFFigureUsageLoopIterationsLabelFigure.verticalSpan = 1; |
447 | constraintFFigureUsageLoopIterationsLabelFigure.grabExcessHorizontalSpace = false; |
448 | constraintFFigureUsageLoopIterationsLabelFigure.grabExcessVerticalSpace = false; |
449 | this.add(fFigureUsageLoopIterationsLabelFigure, |
450 | constraintFFigureUsageLoopIterationsLabelFigure); |
451 | |
452 | } |
453 | |
454 | /** |
455 | * @generated |
456 | */ |
457 | public WrappingLabel getFigureUsageLoopIterationsLabelFigure() { |
458 | return fFigureUsageLoopIterationsLabelFigure; |
459 | } |
460 | |
461 | /** |
462 | * @generated |
463 | */ |
464 | private boolean myUseLocalCoordinates = false; |
465 | |
466 | /** |
467 | * @generated |
468 | */ |
469 | protected boolean useLocalCoordinates() { |
470 | return myUseLocalCoordinates; |
471 | } |
472 | |
473 | /** |
474 | * @generated |
475 | */ |
476 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
477 | myUseLocalCoordinates = useLocalCoordinates; |
478 | } |
479 | |
480 | @Override |
481 | public void add(IFigure figure, Object constraint, int index) { |
482 | Object newConstraint = constraint; |
483 | if (newConstraint == null) { |
484 | GridData layout = new GridData(); |
485 | layout.grabExcessHorizontalSpace = true; |
486 | layout.grabExcessVerticalSpace = true; |
487 | layout.horizontalAlignment = SWT.FILL; |
488 | layout.verticalAlignment = SWT.FILL; |
489 | layout.horizontalSpan = 1; |
490 | layout.verticalSpan = 1; |
491 | |
492 | newConstraint = layout; |
493 | } |
494 | super.add(figure, newConstraint, index); |
495 | } |
496 | |
497 | } |
498 | |
499 | } |