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