1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.parts; |
5 | |
6 | import org.eclipse.draw2d.GridData; |
7 | import org.eclipse.draw2d.GridLayout; |
8 | import org.eclipse.draw2d.IFigure; |
9 | import org.eclipse.draw2d.MarginBorder; |
10 | import org.eclipse.draw2d.PositionConstants; |
11 | import org.eclipse.draw2d.RectangleFigure; |
12 | import org.eclipse.draw2d.Shape; |
13 | import org.eclipse.draw2d.StackLayout; |
14 | import org.eclipse.draw2d.geometry.Dimension; |
15 | import org.eclipse.draw2d.geometry.Point; |
16 | import org.eclipse.gef.EditPart; |
17 | import org.eclipse.gef.EditPolicy; |
18 | import org.eclipse.gef.Request; |
19 | import org.eclipse.gef.commands.Command; |
20 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
21 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
22 | import org.eclipse.gef.requests.CreateRequest; |
23 | import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart; |
24 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; |
28 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; |
29 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
30 | import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; |
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.gef.ui.figures.DefaultSizeNodeFigure; |
34 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
35 | import org.eclipse.gmf.runtime.notation.View; |
36 | import org.eclipse.swt.graphics.Color; |
37 | |
38 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.ComposedProvidingRequiringEntity2CanonicalEditPolicy; |
39 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.ComposedProvidingRequiringEntity2ItemSemanticEditPolicy; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
41 | |
42 | /** |
43 | * The edit part for the inner containment rectangle. |
44 | * It is mapped with the composed providing requiring entity as the outer |
45 | * part. For this, the index "2" has been added to the name. |
46 | * |
47 | * @generated |
48 | */ |
49 | public class ComposedProvidingRequiringEntity2EditPart extends |
50 | AbstractBorderedShapeEditPart { |
51 | |
52 | /** |
53 | * @generated |
54 | */ |
55 | public static final int VISUAL_ID = 2002; |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | protected IFigure contentPane; |
61 | |
62 | /** |
63 | * @generated |
64 | */ |
65 | protected IFigure primaryShape; |
66 | |
67 | /** |
68 | * @generated |
69 | */ |
70 | public ComposedProvidingRequiringEntity2EditPart(View view) { |
71 | super(view); |
72 | } |
73 | |
74 | /** |
75 | * @generated |
76 | */ |
77 | protected void createDefaultEditPolicies() { |
78 | installEditPolicy(EditPolicyRoles.CREATION_ROLE, |
79 | new CreationEditPolicy()); |
80 | super.createDefaultEditPolicies(); |
81 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
82 | new ComposedProvidingRequiringEntity2ItemSemanticEditPolicy()); |
83 | installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, |
84 | new DragDropEditPolicy()); |
85 | installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, |
86 | new ComposedProvidingRequiringEntity2CanonicalEditPolicy()); |
87 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
88 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
89 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
90 | } |
91 | |
92 | /** |
93 | * @generated |
94 | */ |
95 | protected LayoutEditPolicy createLayoutEditPolicy() { |
96 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
97 | |
98 | protected EditPolicy createChildEditPolicy(EditPart child) { |
99 | View childView = (View) child.getModel(); |
100 | switch (PalladioComponentModelVisualIDRegistry |
101 | .getVisualID(childView)) { |
102 | case OperationProvidedRole2EditPart.VISUAL_ID: |
103 | case OperationRequiredRole2EditPart.VISUAL_ID: |
104 | return new BorderItemSelectionEditPolicy(); |
105 | } |
106 | EditPolicy result = child |
107 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
108 | if (result == null) { |
109 | result = new NonResizableEditPolicy(); |
110 | } |
111 | return result; |
112 | } |
113 | |
114 | protected Command getMoveChildrenCommand(Request request) { |
115 | return null; |
116 | } |
117 | |
118 | protected Command getCreateCommand(CreateRequest request) { |
119 | return null; |
120 | } |
121 | }; |
122 | return lep; |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | protected IFigure createNodeShape() { |
129 | CompositeStructureFigure figure = new CompositeStructureFigure(); |
130 | return primaryShape = figure; |
131 | } |
132 | |
133 | /** |
134 | * @generated |
135 | */ |
136 | public CompositeStructureFigure getPrimaryShape() { |
137 | return (CompositeStructureFigure) primaryShape; |
138 | } |
139 | |
140 | /** |
141 | * @generated |
142 | */ |
143 | protected boolean addFixedChild(EditPart childEditPart) { |
144 | if (childEditPart instanceof ComposedProvidingRequiringEntityEntityNameEditPart) { |
145 | ((ComposedProvidingRequiringEntityEntityNameEditPart) childEditPart) |
146 | .setLabel(getPrimaryShape() |
147 | .getFigureCompositeStructureNameLabelFigure()); |
148 | return true; |
149 | } |
150 | if (childEditPart instanceof ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart) { |
151 | IFigure pane = getPrimaryShape() |
152 | .getFigureCompositeStructureInternals(); |
153 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
154 | pane |
155 | .add(((ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart) childEditPart) |
156 | .getFigure()); |
157 | return true; |
158 | } |
159 | if (childEditPart instanceof OperationProvidedRole2EditPart) { |
160 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
161 | PositionConstants.WEST); |
162 | getBorderedFigure().getBorderItemContainer().add( |
163 | ((OperationProvidedRole2EditPart) childEditPart) |
164 | .getFigure(), locator); |
165 | return true; |
166 | } |
167 | if (childEditPart instanceof OperationRequiredRole2EditPart) { |
168 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
169 | PositionConstants.EAST); |
170 | getBorderedFigure().getBorderItemContainer().add( |
171 | ((OperationRequiredRole2EditPart) childEditPart) |
172 | .getFigure(), locator); |
173 | return true; |
174 | } |
175 | return false; |
176 | } |
177 | |
178 | /** |
179 | * @generated |
180 | */ |
181 | protected boolean removeFixedChild(EditPart childEditPart) { |
182 | if (childEditPart instanceof ComposedProvidingRequiringEntityEntityNameEditPart) { |
183 | return true; |
184 | } |
185 | if (childEditPart instanceof ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart) { |
186 | IFigure pane = getPrimaryShape() |
187 | .getFigureCompositeStructureInternals(); |
188 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
189 | pane |
190 | .remove(((ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart) childEditPart) |
191 | .getFigure()); |
192 | return true; |
193 | } |
194 | if (childEditPart instanceof OperationProvidedRole2EditPart) { |
195 | getBorderedFigure().getBorderItemContainer().remove( |
196 | ((OperationProvidedRole2EditPart) childEditPart) |
197 | .getFigure()); |
198 | return true; |
199 | } |
200 | if (childEditPart instanceof OperationRequiredRole2EditPart) { |
201 | getBorderedFigure().getBorderItemContainer().remove( |
202 | ((OperationRequiredRole2EditPart) childEditPart) |
203 | .getFigure()); |
204 | return true; |
205 | } |
206 | return false; |
207 | } |
208 | |
209 | /** |
210 | * @generated |
211 | */ |
212 | protected void addChildVisual(EditPart childEditPart, int index) { |
213 | if (addFixedChild(childEditPart)) { |
214 | return; |
215 | } |
216 | super.addChildVisual(childEditPart, -1); |
217 | } |
218 | |
219 | /** |
220 | * @generated |
221 | */ |
222 | protected void removeChildVisual(EditPart childEditPart) { |
223 | if (removeFixedChild(childEditPart)) { |
224 | return; |
225 | } |
226 | super.removeChildVisual(childEditPart); |
227 | } |
228 | |
229 | /** |
230 | * @generated not |
231 | */ |
232 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
233 | |
234 | // TODO: Proof necessity of instance of type check |
235 | // We found out that "return editPart.getFigure().getParent();" is sufficient |
236 | // for the InnerCompartment. It might be sufficient for the roles to. |
237 | // This should be proven and instance of separation removed if possible |
238 | // (benjamin klatt) |
239 | |
240 | if (editPart instanceof OperationProvidedRoleEditPart) { |
241 | return getBorderedFigure().getBorderItemContainer(); |
242 | } |
243 | if (editPart instanceof OperationRequiredRoleEditPart) { |
244 | return getBorderedFigure().getBorderItemContainer(); |
245 | } |
246 | if (editPart instanceof ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart) { |
247 | // get the rectangle figure that should be resized |
248 | return editPart.getFigure().getParent(); |
249 | } |
250 | return super.getContentPaneFor(editPart); |
251 | } |
252 | |
253 | /** |
254 | * @generated |
255 | */ |
256 | protected NodeFigure createNodePlate() { |
257 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(500, 500); |
258 | return result; |
259 | } |
260 | |
261 | /** |
262 | * Creates figure for this edit part. |
263 | * |
264 | * Body of this method does not depend on settings in generation model |
265 | * so you may safely remove <i>generated</i> tag and modify it. |
266 | * |
267 | * @generated |
268 | */ |
269 | protected NodeFigure createMainFigure() { |
270 | NodeFigure figure = createNodePlate(); |
271 | figure.setLayoutManager(new StackLayout()); |
272 | IFigure shape = createNodeShape(); |
273 | figure.add(shape); |
274 | contentPane = setupContentPane(shape); |
275 | return figure; |
276 | } |
277 | |
278 | /** |
279 | * Default implementation treats passed figure as content pane. |
280 | * Respects layout one may have set for generated figure. |
281 | * @param nodeShape instance of generated figure class |
282 | * @generated |
283 | */ |
284 | protected IFigure setupContentPane(IFigure nodeShape) { |
285 | if (nodeShape.getLayoutManager() == null) { |
286 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
287 | layout.setSpacing(5); |
288 | nodeShape.setLayoutManager(layout); |
289 | } |
290 | return nodeShape; // use nodeShape itself as contentPane |
291 | } |
292 | |
293 | /** |
294 | * @generated |
295 | */ |
296 | public IFigure getContentPane() { |
297 | if (contentPane != null) { |
298 | return contentPane; |
299 | } |
300 | return super.getContentPane(); |
301 | } |
302 | |
303 | /** |
304 | * @generated |
305 | */ |
306 | protected void setForegroundColor(Color color) { |
307 | if (primaryShape != null) { |
308 | primaryShape.setForegroundColor(color); |
309 | } |
310 | } |
311 | |
312 | /** |
313 | * @generated |
314 | */ |
315 | protected void setBackgroundColor(Color color) { |
316 | if (primaryShape != null) { |
317 | primaryShape.setBackgroundColor(color); |
318 | } |
319 | } |
320 | |
321 | /** |
322 | * @generated |
323 | */ |
324 | protected void setLineWidth(int width) { |
325 | if (primaryShape instanceof Shape) { |
326 | ((Shape) primaryShape).setLineWidth(width); |
327 | } |
328 | } |
329 | |
330 | /** |
331 | * @generated |
332 | */ |
333 | protected void setLineType(int style) { |
334 | if (primaryShape instanceof Shape) { |
335 | ((Shape) primaryShape).setLineStyle(style); |
336 | } |
337 | } |
338 | |
339 | /** |
340 | * @generated |
341 | */ |
342 | public EditPart getPrimaryChildEditPart() { |
343 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
344 | .getType(ComposedProvidingRequiringEntityEntityNameEditPart.VISUAL_ID)); |
345 | } |
346 | |
347 | /** |
348 | * @generated |
349 | */ |
350 | public class CompositeStructureFigure extends RectangleFigure { |
351 | /** |
352 | * @generated |
353 | */ |
354 | private WrappingLabel fFigureCompositeStructureNameLabelFigure; |
355 | |
356 | /** |
357 | * @generated |
358 | */ |
359 | private RectangleFigure fFigureCompositeStructureInternals; |
360 | |
361 | /** |
362 | * @generated |
363 | */ |
364 | public CompositeStructureFigure() { |
365 | |
366 | GridLayout layoutThis = new GridLayout(); |
367 | layoutThis.numColumns = 1; |
368 | layoutThis.makeColumnsEqualWidth = true; |
369 | layoutThis.horizontalSpacing = 0; |
370 | layoutThis.verticalSpacing = 0; |
371 | layoutThis.marginWidth = 0; |
372 | layoutThis.marginHeight = 0; |
373 | this.setLayoutManager(layoutThis); |
374 | |
375 | this.setLineWidth(1); |
376 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(500), |
377 | getMapMode().DPtoLP(500))); |
378 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
379 | getMapMode().DPtoLP(0))); |
380 | this.setLocation(new Point(getMapMode().DPtoLP(60), getMapMode() |
381 | .DPtoLP(60))); |
382 | createContents(); |
383 | } |
384 | |
385 | /** |
386 | * @generated |
387 | */ |
388 | private void createContents() { |
389 | |
390 | WrappingLabel compositeStructureStereotypeLabelFigure0 = new WrappingLabel(); |
391 | compositeStructureStereotypeLabelFigure0 |
392 | .setText("<<CompositeStructure>>"); |
393 | compositeStructureStereotypeLabelFigure0 |
394 | .setBorder(new MarginBorder(getMapMode().DPtoLP(2), |
395 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(2), |
396 | getMapMode().DPtoLP(0))); |
397 | |
398 | GridData constraintCompositeStructureStereotypeLabelFigure0 = new GridData(); |
399 | constraintCompositeStructureStereotypeLabelFigure0.verticalAlignment = GridData.CENTER; |
400 | constraintCompositeStructureStereotypeLabelFigure0.horizontalAlignment = GridData.CENTER; |
401 | constraintCompositeStructureStereotypeLabelFigure0.horizontalIndent = 0; |
402 | constraintCompositeStructureStereotypeLabelFigure0.horizontalSpan = 1; |
403 | constraintCompositeStructureStereotypeLabelFigure0.verticalSpan = 1; |
404 | constraintCompositeStructureStereotypeLabelFigure0.grabExcessHorizontalSpace = false; |
405 | constraintCompositeStructureStereotypeLabelFigure0.grabExcessVerticalSpace = false; |
406 | this.add(compositeStructureStereotypeLabelFigure0, |
407 | constraintCompositeStructureStereotypeLabelFigure0); |
408 | |
409 | fFigureCompositeStructureNameLabelFigure = new WrappingLabel(); |
410 | fFigureCompositeStructureNameLabelFigure.setText("<myComposite>"); |
411 | fFigureCompositeStructureNameLabelFigure |
412 | .setBorder(new MarginBorder(getMapMode().DPtoLP(2), |
413 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(2), |
414 | getMapMode().DPtoLP(0))); |
415 | |
416 | GridData constraintFFigureCompositeStructureNameLabelFigure = new GridData(); |
417 | constraintFFigureCompositeStructureNameLabelFigure.verticalAlignment = GridData.CENTER; |
418 | constraintFFigureCompositeStructureNameLabelFigure.horizontalAlignment = GridData.CENTER; |
419 | constraintFFigureCompositeStructureNameLabelFigure.horizontalIndent = 0; |
420 | constraintFFigureCompositeStructureNameLabelFigure.horizontalSpan = 1; |
421 | constraintFFigureCompositeStructureNameLabelFigure.verticalSpan = 1; |
422 | constraintFFigureCompositeStructureNameLabelFigure.grabExcessHorizontalSpace = false; |
423 | constraintFFigureCompositeStructureNameLabelFigure.grabExcessVerticalSpace = false; |
424 | this.add(fFigureCompositeStructureNameLabelFigure, |
425 | constraintFFigureCompositeStructureNameLabelFigure); |
426 | |
427 | fFigureCompositeStructureInternals = new RectangleFigure(); |
428 | fFigureCompositeStructureInternals.setFill(false); |
429 | fFigureCompositeStructureInternals.setOutline(false); |
430 | fFigureCompositeStructureInternals.setLineWidth(1); |
431 | fFigureCompositeStructureInternals.setMinimumSize(new Dimension( |
432 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(0))); |
433 | |
434 | GridData constraintFFigureCompositeStructureInternals = new GridData(); |
435 | constraintFFigureCompositeStructureInternals.verticalAlignment = GridData.FILL; |
436 | constraintFFigureCompositeStructureInternals.horizontalAlignment = GridData.FILL; |
437 | constraintFFigureCompositeStructureInternals.horizontalIndent = 0; |
438 | constraintFFigureCompositeStructureInternals.horizontalSpan = 1; |
439 | constraintFFigureCompositeStructureInternals.verticalSpan = 1; |
440 | constraintFFigureCompositeStructureInternals.grabExcessHorizontalSpace = true; |
441 | constraintFFigureCompositeStructureInternals.grabExcessVerticalSpace = true; |
442 | this.add(fFigureCompositeStructureInternals, |
443 | constraintFFigureCompositeStructureInternals); |
444 | |
445 | } |
446 | |
447 | /** |
448 | * @generated |
449 | */ |
450 | public WrappingLabel getFigureCompositeStructureNameLabelFigure() { |
451 | return fFigureCompositeStructureNameLabelFigure; |
452 | } |
453 | |
454 | /** |
455 | * @generated |
456 | */ |
457 | public RectangleFigure getFigureCompositeStructureInternals() { |
458 | return fFigureCompositeStructureInternals; |
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 | } |
481 | |
482 | } |