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 | import org.eclipse.draw2d.GridData; |
9 | import org.eclipse.draw2d.GridLayout; |
10 | import org.eclipse.draw2d.IFigure; |
11 | import org.eclipse.draw2d.MarginBorder; |
12 | import org.eclipse.draw2d.RectangleFigure; |
13 | import org.eclipse.draw2d.Shape; |
14 | import org.eclipse.draw2d.StackLayout; |
15 | import org.eclipse.draw2d.geometry.Dimension; |
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.core.edithelpers.CreateElementRequestAdapter; |
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.EditPolicyRoles; |
28 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; |
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.graphics.Color; |
36 | |
37 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.policies.InfrastructureInterfaceItemSemanticEditPolicy; |
38 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry; |
39 | import de.uka.ipd.sdq.pcm.gmf.repository.providers.PalladioComponentModelElementTypes; |
40 | |
41 | /** |
42 | * @generated |
43 | */ |
44 | public class InfrastructureInterfaceEditPart extends ShapeNodeEditPart { |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public static final int VISUAL_ID = 2109; |
50 | |
51 | /** |
52 | * @generated |
53 | */ |
54 | protected IFigure contentPane; |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | protected IFigure primaryShape; |
60 | |
61 | /** |
62 | * @generated |
63 | */ |
64 | public InfrastructureInterfaceEditPart(View view) { |
65 | super(view); |
66 | } |
67 | |
68 | /** |
69 | * @generated |
70 | */ |
71 | protected void createDefaultEditPolicies() { |
72 | installEditPolicy(EditPolicyRoles.CREATION_ROLE, |
73 | new CreationEditPolicy()); |
74 | super.createDefaultEditPolicies(); |
75 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
76 | new InfrastructureInterfaceItemSemanticEditPolicy()); |
77 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
78 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
79 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
80 | } |
81 | |
82 | /** |
83 | * @generated |
84 | */ |
85 | protected LayoutEditPolicy createLayoutEditPolicy() { |
86 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
87 | |
88 | protected EditPolicy createChildEditPolicy(EditPart child) { |
89 | EditPolicy result = child |
90 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
91 | if (result == null) { |
92 | result = new NonResizableEditPolicy(); |
93 | } |
94 | return result; |
95 | } |
96 | |
97 | protected Command getMoveChildrenCommand(Request request) { |
98 | return null; |
99 | } |
100 | |
101 | protected Command getCreateCommand(CreateRequest request) { |
102 | return null; |
103 | } |
104 | }; |
105 | return lep; |
106 | } |
107 | |
108 | /** |
109 | * @generated |
110 | */ |
111 | protected IFigure createNodeShape() { |
112 | InfrastructureInterfaceFigure figure = new InfrastructureInterfaceFigure(); |
113 | return primaryShape = figure; |
114 | } |
115 | |
116 | /** |
117 | * @generated |
118 | */ |
119 | public InfrastructureInterfaceFigure getPrimaryShape() { |
120 | return (InfrastructureInterfaceFigure) primaryShape; |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | protected boolean addFixedChild(EditPart childEditPart) { |
127 | if (childEditPart instanceof InfrastructureInterfaceEntityNameEditPart) { |
128 | ((InfrastructureInterfaceEntityNameEditPart) childEditPart) |
129 | .setLabel(getPrimaryShape() |
130 | .getFigureInfrastructureInterface_Name_LabelFigure()); |
131 | return true; |
132 | } |
133 | if (childEditPart instanceof InfrastructureInterfaceInfrastructureSignatureListEditPart) { |
134 | IFigure pane = getPrimaryShape() |
135 | .getFigureInfrastructureInterfaceCompartment(); |
136 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
137 | pane |
138 | .add(((InfrastructureInterfaceInfrastructureSignatureListEditPart) childEditPart) |
139 | .getFigure()); |
140 | return true; |
141 | } |
142 | return false; |
143 | } |
144 | |
145 | /** |
146 | * @generated |
147 | */ |
148 | protected boolean removeFixedChild(EditPart childEditPart) { |
149 | if (childEditPart instanceof InfrastructureInterfaceEntityNameEditPart) { |
150 | return true; |
151 | } |
152 | if (childEditPart instanceof InfrastructureInterfaceInfrastructureSignatureListEditPart) { |
153 | IFigure pane = getPrimaryShape() |
154 | .getFigureInfrastructureInterfaceCompartment(); |
155 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
156 | pane |
157 | .remove(((InfrastructureInterfaceInfrastructureSignatureListEditPart) 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 InfrastructureInterfaceInfrastructureSignatureListEditPart) { |
189 | return getPrimaryShape() |
190 | .getFigureInfrastructureInterfaceCompartment(); |
191 | } |
192 | return getContentPane(); |
193 | } |
194 | |
195 | /** |
196 | * @generated |
197 | */ |
198 | protected NodeFigure createNodePlate() { |
199 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
200 | return result; |
201 | } |
202 | |
203 | /** |
204 | * Creates figure for this edit part. |
205 | * |
206 | * Body of this method does not depend on settings in generation model |
207 | * so you may safely remove <i>generated</i> tag and modify it. |
208 | * |
209 | * @generated |
210 | */ |
211 | protected NodeFigure createNodeFigure() { |
212 | NodeFigure figure = createNodePlate(); |
213 | figure.setLayoutManager(new StackLayout()); |
214 | IFigure shape = createNodeShape(); |
215 | figure.add(shape); |
216 | contentPane = setupContentPane(shape); |
217 | return figure; |
218 | } |
219 | |
220 | /** |
221 | * Default implementation treats passed figure as content pane. |
222 | * Respects layout one may have set for generated figure. |
223 | * @param nodeShape instance of generated figure class |
224 | * @generated |
225 | */ |
226 | protected IFigure setupContentPane(IFigure nodeShape) { |
227 | if (nodeShape.getLayoutManager() == null) { |
228 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
229 | layout.setSpacing(5); |
230 | nodeShape.setLayoutManager(layout); |
231 | } |
232 | return nodeShape; // use nodeShape itself as contentPane |
233 | } |
234 | |
235 | /** |
236 | * @generated |
237 | */ |
238 | public IFigure getContentPane() { |
239 | if (contentPane != null) { |
240 | return contentPane; |
241 | } |
242 | return super.getContentPane(); |
243 | } |
244 | |
245 | /** |
246 | * @generated |
247 | */ |
248 | protected void setForegroundColor(Color color) { |
249 | if (primaryShape != null) { |
250 | primaryShape.setForegroundColor(color); |
251 | } |
252 | } |
253 | |
254 | /** |
255 | * @generated |
256 | */ |
257 | protected void setBackgroundColor(Color color) { |
258 | if (primaryShape != null) { |
259 | primaryShape.setBackgroundColor(color); |
260 | } |
261 | } |
262 | |
263 | /** |
264 | * @generated |
265 | */ |
266 | protected void setLineWidth(int width) { |
267 | if (primaryShape instanceof Shape) { |
268 | ((Shape) primaryShape).setLineWidth(width); |
269 | } |
270 | } |
271 | |
272 | /** |
273 | * @generated |
274 | */ |
275 | protected void setLineType(int style) { |
276 | if (primaryShape instanceof Shape) { |
277 | ((Shape) primaryShape).setLineStyle(style); |
278 | } |
279 | } |
280 | |
281 | /** |
282 | * @generated |
283 | */ |
284 | public EditPart getPrimaryChildEditPart() { |
285 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
286 | .getType(InfrastructureInterfaceEntityNameEditPart.VISUAL_ID)); |
287 | } |
288 | |
289 | /** |
290 | * @generated |
291 | */ |
292 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
293 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
294 | types |
295 | .add(PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111); |
296 | types |
297 | .add(PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112); |
298 | return types; |
299 | } |
300 | |
301 | /** |
302 | * @generated |
303 | */ |
304 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
305 | IElementType relationshipType) { |
306 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
307 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
308 | types.add(PalladioComponentModelElementTypes.BasicComponent_2102); |
309 | } |
310 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
311 | types |
312 | .add(PalladioComponentModelElementTypes.CompositeComponent_2103); |
313 | } |
314 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
315 | types |
316 | .add(PalladioComponentModelElementTypes.CompleteComponentType_2104); |
317 | } |
318 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
319 | types |
320 | .add(PalladioComponentModelElementTypes.ProvidesComponentType_2105); |
321 | } |
322 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
323 | types.add(PalladioComponentModelElementTypes.SubSystem_2106); |
324 | } |
325 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
326 | types.add(PalladioComponentModelElementTypes.BasicComponent_2102); |
327 | } |
328 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
329 | types |
330 | .add(PalladioComponentModelElementTypes.CompositeComponent_2103); |
331 | } |
332 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
333 | types |
334 | .add(PalladioComponentModelElementTypes.CompleteComponentType_2104); |
335 | } |
336 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
337 | types |
338 | .add(PalladioComponentModelElementTypes.ProvidesComponentType_2105); |
339 | } |
340 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
341 | types.add(PalladioComponentModelElementTypes.SubSystem_2106); |
342 | } |
343 | return types; |
344 | } |
345 | |
346 | /** |
347 | * @generated |
348 | */ |
349 | public EditPart getTargetEditPart(Request request) { |
350 | if (request instanceof CreateViewAndElementRequest) { |
351 | CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request) |
352 | .getViewAndElementDescriptor() |
353 | .getCreateElementRequestAdapter(); |
354 | IElementType type = (IElementType) adapter |
355 | .getAdapter(IElementType.class); |
356 | if (type == PalladioComponentModelElementTypes.InfrastructureSignature_3108) { |
357 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
358 | .getType(InfrastructureInterfaceInfrastructureSignatureListEditPart.VISUAL_ID)); |
359 | } |
360 | } |
361 | return super.getTargetEditPart(request); |
362 | } |
363 | |
364 | /** |
365 | * @generated |
366 | */ |
367 | public class InfrastructureInterfaceFigure extends RectangleFigure { |
368 | |
369 | /** |
370 | * @generated |
371 | */ |
372 | private WrappingLabel fFigureInfrastructureInterface_Name_LabelFigure; |
373 | /** |
374 | * @generated |
375 | */ |
376 | private RectangleFigure fFigureInfrastructureInterfaceCompartment; |
377 | |
378 | /** |
379 | * @generated |
380 | */ |
381 | public InfrastructureInterfaceFigure() { |
382 | |
383 | GridLayout layoutThis = new GridLayout(); |
384 | layoutThis.numColumns = 1; |
385 | layoutThis.makeColumnsEqualWidth = true; |
386 | layoutThis.horizontalSpacing = 0; |
387 | layoutThis.verticalSpacing = 0; |
388 | layoutThis.marginWidth = 0; |
389 | layoutThis.marginHeight = 0; |
390 | this.setLayoutManager(layoutThis); |
391 | |
392 | this.setLineWidth(1); |
393 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
394 | getMapMode().DPtoLP(0))); |
395 | createContents(); |
396 | } |
397 | |
398 | /** |
399 | * @generated |
400 | */ |
401 | private void createContents() { |
402 | |
403 | fFigureInfrastructureInterface_Name_LabelFigure = new WrappingLabel(); |
404 | fFigureInfrastructureInterface_Name_LabelFigure.setText("<...>"); |
405 | fFigureInfrastructureInterface_Name_LabelFigure |
406 | .setBorder(new MarginBorder(getMapMode().DPtoLP(2), |
407 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(2), |
408 | getMapMode().DPtoLP(0))); |
409 | |
410 | GridData constraintFFigureInfrastructureInterface_Name_LabelFigure = new GridData(); |
411 | constraintFFigureInfrastructureInterface_Name_LabelFigure.verticalAlignment = GridData.CENTER; |
412 | constraintFFigureInfrastructureInterface_Name_LabelFigure.horizontalAlignment = GridData.CENTER; |
413 | constraintFFigureInfrastructureInterface_Name_LabelFigure.horizontalIndent = 0; |
414 | constraintFFigureInfrastructureInterface_Name_LabelFigure.horizontalSpan = 1; |
415 | constraintFFigureInfrastructureInterface_Name_LabelFigure.verticalSpan = 1; |
416 | constraintFFigureInfrastructureInterface_Name_LabelFigure.grabExcessHorizontalSpace = false; |
417 | constraintFFigureInfrastructureInterface_Name_LabelFigure.grabExcessVerticalSpace = false; |
418 | this.add(fFigureInfrastructureInterface_Name_LabelFigure, |
419 | constraintFFigureInfrastructureInterface_Name_LabelFigure); |
420 | |
421 | fFigureInfrastructureInterfaceCompartment = new RectangleFigure(); |
422 | fFigureInfrastructureInterfaceCompartment.setFill(false); |
423 | fFigureInfrastructureInterfaceCompartment.setOutline(false); |
424 | fFigureInfrastructureInterfaceCompartment.setLineWidth(1); |
425 | fFigureInfrastructureInterfaceCompartment |
426 | .setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
427 | getMapMode().DPtoLP(0))); |
428 | |
429 | GridData constraintFFigureInfrastructureInterfaceCompartment = new GridData(); |
430 | constraintFFigureInfrastructureInterfaceCompartment.verticalAlignment = GridData.FILL; |
431 | constraintFFigureInfrastructureInterfaceCompartment.horizontalAlignment = GridData.FILL; |
432 | constraintFFigureInfrastructureInterfaceCompartment.horizontalIndent = 0; |
433 | constraintFFigureInfrastructureInterfaceCompartment.horizontalSpan = 1; |
434 | constraintFFigureInfrastructureInterfaceCompartment.verticalSpan = 1; |
435 | constraintFFigureInfrastructureInterfaceCompartment.grabExcessHorizontalSpace = true; |
436 | constraintFFigureInfrastructureInterfaceCompartment.grabExcessVerticalSpace = true; |
437 | this.add(fFigureInfrastructureInterfaceCompartment, |
438 | constraintFFigureInfrastructureInterfaceCompartment); |
439 | |
440 | } |
441 | |
442 | /** |
443 | * @generated |
444 | */ |
445 | private boolean myUseLocalCoordinates = false; |
446 | |
447 | /** |
448 | * @generated |
449 | */ |
450 | protected boolean useLocalCoordinates() { |
451 | return myUseLocalCoordinates; |
452 | } |
453 | |
454 | /** |
455 | * @generated |
456 | */ |
457 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
458 | myUseLocalCoordinates = useLocalCoordinates; |
459 | } |
460 | |
461 | /** |
462 | * @generated |
463 | */ |
464 | public WrappingLabel getFigureInfrastructureInterface_Name_LabelFigure() { |
465 | return fFigureInfrastructureInterface_Name_LabelFigure; |
466 | } |
467 | |
468 | /** |
469 | * @generated |
470 | */ |
471 | public RectangleFigure getFigureInfrastructureInterfaceCompartment() { |
472 | return fFigureInfrastructureInterfaceCompartment; |
473 | } |
474 | |
475 | } |
476 | |
477 | } |