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