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