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.ProvidesComponentTypeItemSemanticEditPolicy; |
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 ProvidesComponentTypeEditPart extends ShapeNodeEditPart { |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | public static final int VISUAL_ID = 2105; |
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 ProvidesComponentTypeEditPart(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 ProvidesComponentTypeItemSemanticEditPolicy()); |
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 | ProvidesComponentTypeFigure figure = new ProvidesComponentTypeFigure(); |
109 | return primaryShape = figure; |
110 | } |
111 | |
112 | /** |
113 | * @generated |
114 | */ |
115 | public ProvidesComponentTypeFigure getPrimaryShape() { |
116 | return (ProvidesComponentTypeFigure) primaryShape; |
117 | } |
118 | |
119 | /** |
120 | * @generated |
121 | */ |
122 | protected boolean addFixedChild(EditPart childEditPart) { |
123 | if (childEditPart instanceof ProvidesComponentTypeEntityNameEditPart) { |
124 | ((ProvidesComponentTypeEntityNameEditPart) childEditPart) |
125 | .setLabel(getPrimaryShape() |
126 | .getFigureProvidesComponentTypeLabelFigure()); |
127 | return true; |
128 | } |
129 | return false; |
130 | } |
131 | |
132 | /** |
133 | * @generated |
134 | */ |
135 | protected boolean removeFixedChild(EditPart childEditPart) { |
136 | if (childEditPart instanceof ProvidesComponentTypeEntityNameEditPart) { |
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(ProvidesComponentTypeEntityNameEditPart.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.add(PalladioComponentModelElementTypes.SourceRole_4110); |
278 | return types; |
279 | } |
280 | |
281 | /** |
282 | * @generated |
283 | */ |
284 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
285 | IGraphicalEditPart targetEditPart) { |
286 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
287 | if (targetEditPart instanceof OperationInterfaceEditPart) { |
288 | types |
289 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_4105); |
290 | } |
291 | if (targetEditPart instanceof InfrastructureInterfaceEditPart) { |
292 | types |
293 | .add(PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111); |
294 | } |
295 | if (targetEditPart instanceof InfrastructureInterfaceEditPart) { |
296 | types |
297 | .add(PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112); |
298 | } |
299 | if (targetEditPart instanceof EventGroupEditPart) { |
300 | types.add(PalladioComponentModelElementTypes.SinkRole_4109); |
301 | } |
302 | if (targetEditPart instanceof OperationInterfaceEditPart) { |
303 | types |
304 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_4106); |
305 | } |
306 | if (targetEditPart instanceof EventGroupEditPart) { |
307 | types.add(PalladioComponentModelElementTypes.SourceRole_4110); |
308 | } |
309 | return types; |
310 | } |
311 | |
312 | /** |
313 | * @generated |
314 | */ |
315 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
316 | IElementType relationshipType) { |
317 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
318 | if (relationshipType == PalladioComponentModelElementTypes.OperationProvidedRole_4105) { |
319 | types |
320 | .add(PalladioComponentModelElementTypes.OperationInterface_2107); |
321 | } |
322 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
323 | types |
324 | .add(PalladioComponentModelElementTypes.InfrastructureInterface_2109); |
325 | } |
326 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
327 | types |
328 | .add(PalladioComponentModelElementTypes.InfrastructureInterface_2109); |
329 | } |
330 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
331 | types.add(PalladioComponentModelElementTypes.EventGroup_2108); |
332 | } |
333 | if (relationshipType == PalladioComponentModelElementTypes.OperationRequiredRole_4106) { |
334 | types |
335 | .add(PalladioComponentModelElementTypes.OperationInterface_2107); |
336 | } |
337 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
338 | types.add(PalladioComponentModelElementTypes.EventGroup_2108); |
339 | } |
340 | return types; |
341 | } |
342 | |
343 | /** |
344 | * @generated |
345 | */ |
346 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
347 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
348 | types |
349 | .add(PalladioComponentModelElementTypes.CompleteComponentTypeParentProvidesComponentTypes_4104); |
350 | return types; |
351 | } |
352 | |
353 | /** |
354 | * @generated |
355 | */ |
356 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
357 | IElementType relationshipType) { |
358 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
359 | if (relationshipType == PalladioComponentModelElementTypes.CompleteComponentTypeParentProvidesComponentTypes_4104) { |
360 | types |
361 | .add(PalladioComponentModelElementTypes.CompleteComponentType_2104); |
362 | } |
363 | return types; |
364 | } |
365 | |
366 | /** |
367 | * @generated |
368 | */ |
369 | public class ProvidesComponentTypeFigure extends RectangleFigure { |
370 | /** |
371 | * @generated |
372 | */ |
373 | private WrappingLabel fFigureProvidesComponentTypeLabelFigure; |
374 | |
375 | /** |
376 | * @generated |
377 | */ |
378 | public ProvidesComponentTypeFigure() { |
379 | |
380 | GridLayout layoutThis = new GridLayout(); |
381 | layoutThis.numColumns = 1; |
382 | layoutThis.makeColumnsEqualWidth = true; |
383 | layoutThis.horizontalSpacing = 0; |
384 | layoutThis.verticalSpacing = 0; |
385 | layoutThis.marginWidth = 0; |
386 | layoutThis.marginHeight = 0; |
387 | this.setLayoutManager(layoutThis); |
388 | |
389 | this.setLineWidth(1); |
390 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
391 | getMapMode().DPtoLP(0))); |
392 | createContents(); |
393 | } |
394 | |
395 | /** |
396 | * @generated |
397 | */ |
398 | private void createContents() { |
399 | |
400 | fFigureProvidesComponentTypeLabelFigure = new WrappingLabel(); |
401 | fFigureProvidesComponentTypeLabelFigure.setText("<...>"); |
402 | fFigureProvidesComponentTypeLabelFigure.setBorder(new MarginBorder( |
403 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
404 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
405 | |
406 | GridData constraintFFigureProvidesComponentTypeLabelFigure = new GridData(); |
407 | constraintFFigureProvidesComponentTypeLabelFigure.verticalAlignment = GridData.CENTER; |
408 | constraintFFigureProvidesComponentTypeLabelFigure.horizontalAlignment = GridData.CENTER; |
409 | constraintFFigureProvidesComponentTypeLabelFigure.horizontalIndent = 0; |
410 | constraintFFigureProvidesComponentTypeLabelFigure.horizontalSpan = 1; |
411 | constraintFFigureProvidesComponentTypeLabelFigure.verticalSpan = 1; |
412 | constraintFFigureProvidesComponentTypeLabelFigure.grabExcessHorizontalSpace = false; |
413 | constraintFFigureProvidesComponentTypeLabelFigure.grabExcessVerticalSpace = false; |
414 | this.add(fFigureProvidesComponentTypeLabelFigure, |
415 | constraintFFigureProvidesComponentTypeLabelFigure); |
416 | |
417 | } |
418 | |
419 | /** |
420 | * @generated |
421 | */ |
422 | public WrappingLabel getFigureProvidesComponentTypeLabelFigure() { |
423 | return fFigureProvidesComponentTypeLabelFigure; |
424 | } |
425 | |
426 | /** |
427 | * @generated |
428 | */ |
429 | private boolean myUseLocalCoordinates = false; |
430 | |
431 | /** |
432 | * @generated |
433 | */ |
434 | protected boolean useLocalCoordinates() { |
435 | return myUseLocalCoordinates; |
436 | } |
437 | |
438 | /** |
439 | * @generated |
440 | */ |
441 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
442 | myUseLocalCoordinates = useLocalCoordinates; |
443 | } |
444 | |
445 | } |
446 | |
447 | } |