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