1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.edit.parts; |
5 | |
6 | import org.eclipse.draw2d.ColorConstants; |
7 | import org.eclipse.draw2d.GridData; |
8 | import org.eclipse.draw2d.GridLayout; |
9 | import org.eclipse.draw2d.IFigure; |
10 | import org.eclipse.draw2d.MarginBorder; |
11 | import org.eclipse.draw2d.RectangleFigure; |
12 | import org.eclipse.draw2d.Shape; |
13 | import org.eclipse.draw2d.StackLayout; |
14 | import org.eclipse.draw2d.geometry.Dimension; |
15 | import org.eclipse.gef.EditPart; |
16 | import org.eclipse.gef.EditPolicy; |
17 | import org.eclipse.gef.Request; |
18 | import org.eclipse.gef.commands.Command; |
19 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
20 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
21 | import org.eclipse.gef.requests.CreateRequest; |
22 | import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; |
23 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
24 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
27 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; |
28 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
29 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
30 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
31 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
32 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
33 | import org.eclipse.gmf.runtime.notation.View; |
34 | import org.eclipse.swt.graphics.Color; |
35 | |
36 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.VariableUsageItemSemanticEditPolicy; |
37 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
38 | import de.uka.ipd.sdq.pcm.gmf.usage.providers.PalladioComponentModelElementTypes; |
39 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
40 | import de.uka.ipd.sdq.pcm.stochasticexpressions.PCMStoExPrettyPrintVisitor; |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | public class VariableUsageEditPart extends ShapeNodeEditPart { |
46 | |
47 | /** |
48 | * @generated |
49 | */ |
50 | public static final int VISUAL_ID = 3012; |
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 VariableUsageEditPart(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 VariableUsageItemSemanticEditPolicy()); |
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 | ParametricParameterUsageFigure figure = new ParametricParameterUsageFigure(); |
114 | return primaryShape = figure; |
115 | } |
116 | |
117 | /** |
118 | * @generated |
119 | */ |
120 | public ParametricParameterUsageFigure getPrimaryShape() { |
121 | return (ParametricParameterUsageFigure) primaryShape; |
122 | } |
123 | |
124 | /** |
125 | * @generated |
126 | */ |
127 | protected boolean addFixedChild(EditPart childEditPart) { |
128 | if (childEditPart instanceof WrappingLabelEditPart) { |
129 | ((WrappingLabelEditPart) childEditPart).setLabel(getPrimaryShape() |
130 | .getFigureVariableUsageReferenceLabelFigure()); |
131 | return true; |
132 | } |
133 | if (childEditPart instanceof VariableUsageVariableCharacterisationEditPart) { |
134 | IFigure pane = getPrimaryShape() |
135 | .getFigureParametricParameterUsageRectangleCompartment(); |
136 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
137 | pane |
138 | .add(((VariableUsageVariableCharacterisationEditPart) 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 WrappingLabelEditPart) { |
150 | return true; |
151 | } |
152 | if (childEditPart instanceof VariableUsageVariableCharacterisationEditPart) { |
153 | IFigure pane = getPrimaryShape() |
154 | .getFigureParametricParameterUsageRectangleCompartment(); |
155 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
156 | pane |
157 | .remove(((VariableUsageVariableCharacterisationEditPart) 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 VariableUsageVariableCharacterisationEditPart) { |
189 | return getPrimaryShape() |
190 | .getFigureParametricParameterUsageRectangleCompartment(); |
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(WrappingLabelEditPart.VISUAL_ID)); |
287 | } |
288 | |
289 | /** |
290 | * @generated |
291 | */ |
292 | public EditPart getTargetEditPart(Request request) { |
293 | if (request instanceof CreateViewAndElementRequest) { |
294 | CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request) |
295 | .getViewAndElementDescriptor() |
296 | .getCreateElementRequestAdapter(); |
297 | IElementType type = (IElementType) adapter |
298 | .getAdapter(IElementType.class); |
299 | if (type == PalladioComponentModelElementTypes.VariableCharacterisation_3013) { |
300 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
301 | .getType(VariableUsageVariableCharacterisationEditPart.VISUAL_ID)); |
302 | } |
303 | } |
304 | return super.getTargetEditPart(request); |
305 | } |
306 | |
307 | /** |
308 | * @generated |
309 | */ |
310 | public class ParametricParameterUsageFigure extends RectangleFigure { |
311 | /** |
312 | * @generated |
313 | */ |
314 | private WrappingLabel fFigureVariableUsageReferenceLabelFigure; |
315 | |
316 | /** |
317 | * @generated |
318 | */ |
319 | private RectangleFigure fFigureParametricParameterUsageRectangleCompartment; |
320 | |
321 | /** |
322 | * @generated |
323 | */ |
324 | public ParametricParameterUsageFigure() { |
325 | |
326 | GridLayout layoutThis = new GridLayout(); |
327 | layoutThis.numColumns = 1; |
328 | layoutThis.makeColumnsEqualWidth = true; |
329 | layoutThis.horizontalSpacing = 0; |
330 | layoutThis.verticalSpacing = 0; |
331 | layoutThis.marginWidth = 0; |
332 | layoutThis.marginHeight = 0; |
333 | this.setLayoutManager(layoutThis); |
334 | |
335 | this.setLineWidth(1); |
336 | this.setBackgroundColor(THIS_BACK); |
337 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
338 | getMapMode().DPtoLP(0))); |
339 | createContents(); |
340 | } |
341 | |
342 | /** |
343 | * @generated not |
344 | */ |
345 | private void createContents() { |
346 | |
347 | fFigureVariableUsageReferenceLabelFigure = new WrappingLabel(); |
348 | fFigureVariableUsageReferenceLabelFigure |
349 | .setText(new PCMStoExPrettyPrintVisitor() |
350 | .prettyPrint(((VariableUsage) resolveSemanticElement()) |
351 | .getNamedReference__VariableUsage())); |
352 | fFigureVariableUsageReferenceLabelFigure |
353 | .setBorder(new MarginBorder(getMapMode().DPtoLP(2), |
354 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(2), |
355 | getMapMode().DPtoLP(0))); |
356 | |
357 | GridData constraintFFigureVariableUsageReferenceLabelFigure = new GridData(); |
358 | constraintFFigureVariableUsageReferenceLabelFigure.verticalAlignment = GridData.CENTER; |
359 | constraintFFigureVariableUsageReferenceLabelFigure.horizontalAlignment = GridData.CENTER; |
360 | constraintFFigureVariableUsageReferenceLabelFigure.horizontalIndent = 0; |
361 | constraintFFigureVariableUsageReferenceLabelFigure.horizontalSpan = 1; |
362 | constraintFFigureVariableUsageReferenceLabelFigure.verticalSpan = 1; |
363 | constraintFFigureVariableUsageReferenceLabelFigure.grabExcessHorizontalSpace = false; |
364 | constraintFFigureVariableUsageReferenceLabelFigure.grabExcessVerticalSpace = false; |
365 | this.add(fFigureVariableUsageReferenceLabelFigure, |
366 | constraintFFigureVariableUsageReferenceLabelFigure); |
367 | |
368 | fFigureParametricParameterUsageRectangleCompartment = new RectangleFigure(); |
369 | fFigureParametricParameterUsageRectangleCompartment.setFill(false); |
370 | fFigureParametricParameterUsageRectangleCompartment |
371 | .setOutline(false); |
372 | |
373 | GridData constraintFFigureParametricParameterUsageRectangleCompartment = new GridData(); |
374 | constraintFFigureParametricParameterUsageRectangleCompartment.verticalAlignment = GridData.FILL; |
375 | constraintFFigureParametricParameterUsageRectangleCompartment.horizontalAlignment = GridData.FILL; |
376 | constraintFFigureParametricParameterUsageRectangleCompartment.horizontalIndent = 0; |
377 | constraintFFigureParametricParameterUsageRectangleCompartment.horizontalSpan = 1; |
378 | constraintFFigureParametricParameterUsageRectangleCompartment.verticalSpan = 1; |
379 | constraintFFigureParametricParameterUsageRectangleCompartment.grabExcessHorizontalSpace = true; |
380 | constraintFFigureParametricParameterUsageRectangleCompartment.grabExcessVerticalSpace = true; |
381 | this |
382 | .add(fFigureParametricParameterUsageRectangleCompartment, |
383 | constraintFFigureParametricParameterUsageRectangleCompartment); |
384 | |
385 | } |
386 | |
387 | /** |
388 | * @generated |
389 | */ |
390 | public WrappingLabel getFigureVariableUsageReferenceLabelFigure() { |
391 | return fFigureVariableUsageReferenceLabelFigure; |
392 | } |
393 | |
394 | /** |
395 | * @generated |
396 | */ |
397 | public RectangleFigure getFigureParametricParameterUsageRectangleCompartment() { |
398 | return fFigureParametricParameterUsageRectangleCompartment; |
399 | } |
400 | |
401 | /** |
402 | * @generated |
403 | */ |
404 | private boolean myUseLocalCoordinates = false; |
405 | |
406 | /** |
407 | * @generated |
408 | */ |
409 | protected boolean useLocalCoordinates() { |
410 | return myUseLocalCoordinates; |
411 | } |
412 | |
413 | /** |
414 | * @generated |
415 | */ |
416 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
417 | myUseLocalCoordinates = useLocalCoordinates; |
418 | } |
419 | |
420 | } |
421 | |
422 | /** |
423 | * @generated |
424 | */ |
425 | static final Color THIS_BACK = new Color(null, 220, 220, 220); |
426 | |
427 | } |