1 | /* |
2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.edit.parts; |
5 | |
6 | import org.eclipse.draw2d.GridData; |
7 | import org.eclipse.draw2d.GridLayout; |
8 | import org.eclipse.draw2d.IFigure; |
9 | import org.eclipse.draw2d.MarginBorder; |
10 | import org.eclipse.draw2d.RectangleFigure; |
11 | import org.eclipse.draw2d.Shape; |
12 | import org.eclipse.draw2d.StackLayout; |
13 | import org.eclipse.draw2d.geometry.Dimension; |
14 | import org.eclipse.gef.EditPart; |
15 | import org.eclipse.gef.EditPolicy; |
16 | import org.eclipse.gef.Request; |
17 | import org.eclipse.gef.commands.Command; |
18 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
19 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
20 | import org.eclipse.gef.requests.CreateRequest; |
21 | import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; |
22 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
23 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
24 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
26 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; |
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.seff.edit.policies.VariableUsage2ItemSemanticEditPolicy; |
36 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
37 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
38 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
39 | import de.uka.ipd.sdq.pcm.stochasticexpressions.PCMStoExPrettyPrintVisitor; |
40 | |
41 | /** |
42 | * @generated |
43 | */ |
44 | public class VariableUsage2EditPart extends ShapeNodeEditPart { |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public static final int VISUAL_ID = 3049; |
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 VariableUsage2EditPart(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 VariableUsage2ItemSemanticEditPolicy()); |
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 | ParametricParameterUsageFigure figure = new ParametricParameterUsageFigure(); |
113 | return primaryShape = figure; |
114 | } |
115 | |
116 | /** |
117 | * @generated |
118 | */ |
119 | public ParametricParameterUsageFigure getPrimaryShape() { |
120 | return (ParametricParameterUsageFigure) primaryShape; |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | protected boolean addFixedChild(EditPart childEditPart) { |
127 | if (childEditPart instanceof WrappingLabelEditPart) { |
128 | ((WrappingLabelEditPart) childEditPart).setLabel(getPrimaryShape() |
129 | .getFigureVariableUsageReferenceLabelFigure()); |
130 | return true; |
131 | } |
132 | if (childEditPart instanceof VariableUsageVariableCharacterisation2EditPart) { |
133 | IFigure pane = getPrimaryShape() |
134 | .getFigureParametricParameterUsageRectangleCompartment(); |
135 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
136 | pane |
137 | .add(((VariableUsageVariableCharacterisation2EditPart) 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 WrappingLabelEditPart) { |
149 | return true; |
150 | } |
151 | if (childEditPart instanceof VariableUsageVariableCharacterisation2EditPart) { |
152 | IFigure pane = getPrimaryShape() |
153 | .getFigureParametricParameterUsageRectangleCompartment(); |
154 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
155 | pane |
156 | .remove(((VariableUsageVariableCharacterisation2EditPart) childEditPart) |
157 | .getFigure()); |
158 | return true; |
159 | } |
160 | return false; |
161 | } |
162 | |
163 | /** |
164 | * @generated |
165 | */ |
166 | protected void addChildVisual(EditPart childEditPart, int index) { |
167 | if (addFixedChild(childEditPart)) { |
168 | return; |
169 | } |
170 | super.addChildVisual(childEditPart, -1); |
171 | } |
172 | |
173 | /** |
174 | * @generated |
175 | */ |
176 | protected void removeChildVisual(EditPart childEditPart) { |
177 | if (removeFixedChild(childEditPart)) { |
178 | return; |
179 | } |
180 | super.removeChildVisual(childEditPart); |
181 | } |
182 | |
183 | /** |
184 | * @generated |
185 | */ |
186 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
187 | if (editPart instanceof VariableUsageVariableCharacterisation2EditPart) { |
188 | return getPrimaryShape() |
189 | .getFigureParametricParameterUsageRectangleCompartment(); |
190 | } |
191 | return getContentPane(); |
192 | } |
193 | |
194 | /** |
195 | * @generated |
196 | */ |
197 | protected NodeFigure createNodePlate() { |
198 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
199 | return result; |
200 | } |
201 | |
202 | /** |
203 | * Creates figure for this edit part. |
204 | * |
205 | * Body of this method does not depend on settings in generation model |
206 | * so you may safely remove <i>generated</i> tag and modify it. |
207 | * |
208 | * @generated |
209 | */ |
210 | protected NodeFigure createNodeFigure() { |
211 | NodeFigure figure = createNodePlate(); |
212 | figure.setLayoutManager(new StackLayout()); |
213 | IFigure shape = createNodeShape(); |
214 | figure.add(shape); |
215 | contentPane = setupContentPane(shape); |
216 | return figure; |
217 | } |
218 | |
219 | /** |
220 | * Default implementation treats passed figure as content pane. |
221 | * Respects layout one may have set for generated figure. |
222 | * @param nodeShape instance of generated figure class |
223 | * @generated |
224 | */ |
225 | protected IFigure setupContentPane(IFigure nodeShape) { |
226 | if (nodeShape.getLayoutManager() == null) { |
227 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
228 | layout.setSpacing(5); |
229 | nodeShape.setLayoutManager(layout); |
230 | } |
231 | return nodeShape; // use nodeShape itself as contentPane |
232 | } |
233 | |
234 | /** |
235 | * @generated |
236 | */ |
237 | public IFigure getContentPane() { |
238 | if (contentPane != null) { |
239 | return contentPane; |
240 | } |
241 | return super.getContentPane(); |
242 | } |
243 | |
244 | /** |
245 | * @generated |
246 | */ |
247 | protected void setForegroundColor(Color color) { |
248 | if (primaryShape != null) { |
249 | primaryShape.setForegroundColor(color); |
250 | } |
251 | } |
252 | |
253 | /** |
254 | * @generated |
255 | */ |
256 | protected void setBackgroundColor(Color color) { |
257 | if (primaryShape != null) { |
258 | primaryShape.setBackgroundColor(color); |
259 | } |
260 | } |
261 | |
262 | /** |
263 | * @generated |
264 | */ |
265 | protected void setLineWidth(int width) { |
266 | if (primaryShape instanceof Shape) { |
267 | ((Shape) primaryShape).setLineWidth(width); |
268 | } |
269 | } |
270 | |
271 | /** |
272 | * @generated |
273 | */ |
274 | protected void setLineType(int style) { |
275 | if (primaryShape instanceof Shape) { |
276 | ((Shape) primaryShape).setLineStyle(style); |
277 | } |
278 | } |
279 | |
280 | /** |
281 | * @generated |
282 | */ |
283 | public EditPart getPrimaryChildEditPart() { |
284 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
285 | .getType(WrappingLabelEditPart.VISUAL_ID)); |
286 | } |
287 | |
288 | /** |
289 | * @generated |
290 | */ |
291 | public EditPart getTargetEditPart(Request request) { |
292 | if (request instanceof CreateViewAndElementRequest) { |
293 | CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request) |
294 | .getViewAndElementDescriptor() |
295 | .getCreateElementRequestAdapter(); |
296 | IElementType type = (IElementType) adapter |
297 | .getAdapter(IElementType.class); |
298 | if (type == PalladioComponentModelElementTypes.VariableCharacterisation_3035) { |
299 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
300 | .getType(VariableUsageVariableCharacterisation2EditPart.VISUAL_ID)); |
301 | } |
302 | } |
303 | return super.getTargetEditPart(request); |
304 | } |
305 | |
306 | /** |
307 | * @generated |
308 | */ |
309 | public class ParametricParameterUsageFigure extends RectangleFigure { |
310 | /** |
311 | * @generated |
312 | */ |
313 | private WrappingLabel fFigureVariableUsageReferenceLabelFigure; |
314 | |
315 | /** |
316 | * @generated |
317 | */ |
318 | private RectangleFigure fFigureParametricParameterUsageRectangleCompartment; |
319 | |
320 | /** |
321 | * @generated |
322 | */ |
323 | public ParametricParameterUsageFigure() { |
324 | |
325 | GridLayout layoutThis = new GridLayout(); |
326 | layoutThis.numColumns = 1; |
327 | layoutThis.makeColumnsEqualWidth = true; |
328 | layoutThis.horizontalSpacing = 0; |
329 | layoutThis.verticalSpacing = 0; |
330 | layoutThis.marginWidth = 0; |
331 | layoutThis.marginHeight = 0; |
332 | this.setLayoutManager(layoutThis); |
333 | |
334 | this.setLineWidth(1); |
335 | this.setBackgroundColor(THIS_BACK); |
336 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
337 | getMapMode().DPtoLP(0))); |
338 | createContents(); |
339 | } |
340 | |
341 | /** |
342 | * @generated not |
343 | */ |
344 | private void createContents() { |
345 | |
346 | fFigureVariableUsageReferenceLabelFigure = new WrappingLabel(); |
347 | fFigureVariableUsageReferenceLabelFigure |
348 | .setText(new PCMStoExPrettyPrintVisitor() |
349 | .prettyPrint(((VariableUsage) resolveSemanticElement()) |
350 | .getNamedReference__VariableUsage())); |
351 | fFigureVariableUsageReferenceLabelFigure |
352 | .setBorder(new MarginBorder(getMapMode().DPtoLP(2), |
353 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(2), |
354 | getMapMode().DPtoLP(0))); |
355 | |
356 | GridData constraintFFigureVariableUsageReferenceLabelFigure = new GridData(); |
357 | constraintFFigureVariableUsageReferenceLabelFigure.verticalAlignment = GridData.CENTER; |
358 | constraintFFigureVariableUsageReferenceLabelFigure.horizontalAlignment = GridData.CENTER; |
359 | constraintFFigureVariableUsageReferenceLabelFigure.horizontalIndent = 0; |
360 | constraintFFigureVariableUsageReferenceLabelFigure.horizontalSpan = 1; |
361 | constraintFFigureVariableUsageReferenceLabelFigure.verticalSpan = 1; |
362 | constraintFFigureVariableUsageReferenceLabelFigure.grabExcessHorizontalSpace = false; |
363 | constraintFFigureVariableUsageReferenceLabelFigure.grabExcessVerticalSpace = false; |
364 | this.add(fFigureVariableUsageReferenceLabelFigure, |
365 | constraintFFigureVariableUsageReferenceLabelFigure); |
366 | |
367 | fFigureParametricParameterUsageRectangleCompartment = new RectangleFigure(); |
368 | fFigureParametricParameterUsageRectangleCompartment.setFill(false); |
369 | fFigureParametricParameterUsageRectangleCompartment |
370 | .setOutline(false); |
371 | |
372 | GridData constraintFFigureParametricParameterUsageRectangleCompartment = new GridData(); |
373 | constraintFFigureParametricParameterUsageRectangleCompartment.verticalAlignment = GridData.FILL; |
374 | constraintFFigureParametricParameterUsageRectangleCompartment.horizontalAlignment = GridData.FILL; |
375 | constraintFFigureParametricParameterUsageRectangleCompartment.horizontalIndent = 0; |
376 | constraintFFigureParametricParameterUsageRectangleCompartment.horizontalSpan = 1; |
377 | constraintFFigureParametricParameterUsageRectangleCompartment.verticalSpan = 1; |
378 | constraintFFigureParametricParameterUsageRectangleCompartment.grabExcessHorizontalSpace = true; |
379 | constraintFFigureParametricParameterUsageRectangleCompartment.grabExcessVerticalSpace = true; |
380 | this |
381 | .add(fFigureParametricParameterUsageRectangleCompartment, |
382 | constraintFFigureParametricParameterUsageRectangleCompartment); |
383 | |
384 | } |
385 | |
386 | /** |
387 | * @generated |
388 | */ |
389 | public WrappingLabel getFigureVariableUsageReferenceLabelFigure() { |
390 | return fFigureVariableUsageReferenceLabelFigure; |
391 | } |
392 | |
393 | /** |
394 | * @generated |
395 | */ |
396 | public RectangleFigure getFigureParametricParameterUsageRectangleCompartment() { |
397 | return fFigureParametricParameterUsageRectangleCompartment; |
398 | } |
399 | |
400 | /** |
401 | * @generated |
402 | */ |
403 | private boolean myUseLocalCoordinates = false; |
404 | |
405 | /** |
406 | * @generated |
407 | */ |
408 | protected boolean useLocalCoordinates() { |
409 | return myUseLocalCoordinates; |
410 | } |
411 | |
412 | /** |
413 | * @generated |
414 | */ |
415 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
416 | myUseLocalCoordinates = useLocalCoordinates; |
417 | } |
418 | |
419 | } |
420 | |
421 | /** |
422 | * @generated |
423 | */ |
424 | static final Color THIS_BACK = new Color(null, 220, 220, 220); |
425 | |
426 | } |