1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.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.WrapLabel; |
30 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
31 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
32 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
33 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
34 | import org.eclipse.gmf.runtime.notation.View; |
35 | import org.eclipse.swt.graphics.Color; |
36 | |
37 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.policies.VariableUsageItemSemanticEditPolicy; |
38 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry; |
39 | import de.uka.ipd.sdq.pcm.gmf.repository.providers.PalladioComponentModelElementTypes; |
40 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
41 | import de.uka.ipd.sdq.pcm.stochasticexpressions.PCMStoExPrettyPrintVisitor; |
42 | |
43 | /** |
44 | * @generated |
45 | */ |
46 | public class VariableUsageEditPart extends ShapeNodeEditPart { |
47 | |
48 | /** |
49 | * @generated |
50 | */ |
51 | public static final int VISUAL_ID = 3104; |
52 | |
53 | /** |
54 | * @generated |
55 | */ |
56 | protected IFigure contentPane; |
57 | |
58 | /** |
59 | * @generated |
60 | */ |
61 | protected IFigure primaryShape; |
62 | |
63 | /** |
64 | * @generated |
65 | */ |
66 | public VariableUsageEditPart(View view) { |
67 | super(view); |
68 | } |
69 | |
70 | /** |
71 | * @generated |
72 | */ |
73 | protected void createDefaultEditPolicies() { |
74 | installEditPolicy(EditPolicyRoles.CREATION_ROLE, |
75 | new CreationEditPolicy()); |
76 | super.createDefaultEditPolicies(); |
77 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
78 | new VariableUsageItemSemanticEditPolicy()); |
79 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
80 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
81 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
82 | } |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | protected LayoutEditPolicy createLayoutEditPolicy() { |
88 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
89 | |
90 | protected EditPolicy createChildEditPolicy(EditPart child) { |
91 | EditPolicy result = child |
92 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
93 | if (result == null) { |
94 | result = new NonResizableEditPolicy(); |
95 | } |
96 | return result; |
97 | } |
98 | |
99 | protected Command getMoveChildrenCommand(Request request) { |
100 | return null; |
101 | } |
102 | |
103 | protected Command getCreateCommand(CreateRequest request) { |
104 | return null; |
105 | } |
106 | }; |
107 | return lep; |
108 | } |
109 | |
110 | /** |
111 | * @generated |
112 | */ |
113 | protected IFigure createNodeShape() { |
114 | ParametricParameterUsageFigure figure = new ParametricParameterUsageFigure(); |
115 | return primaryShape = figure; |
116 | } |
117 | |
118 | /** |
119 | * @generated |
120 | */ |
121 | public ParametricParameterUsageFigure getPrimaryShape() { |
122 | return (ParametricParameterUsageFigure) primaryShape; |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | protected boolean addFixedChild(EditPart childEditPart) { |
129 | if (childEditPart instanceof VariableUsageLabelEditPart) { |
130 | ((VariableUsageLabelEditPart) childEditPart) |
131 | .setLabel(getPrimaryShape() |
132 | .getFigureVariableUsageReferenceLabelFigure()); |
133 | return true; |
134 | } |
135 | return false; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected boolean removeFixedChild(EditPart childEditPart) { |
142 | if (childEditPart instanceof VariableUsageLabelEditPart) { |
143 | return true; |
144 | } |
145 | return false; |
146 | } |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | protected void addChildVisual(EditPart childEditPart, int index) { |
152 | if (addFixedChild(childEditPart)) { |
153 | return; |
154 | } |
155 | super.addChildVisual(childEditPart, -1); |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected void removeChildVisual(EditPart childEditPart) { |
162 | if (removeFixedChild(childEditPart)) { |
163 | return; |
164 | } |
165 | super.removeChildVisual(childEditPart); |
166 | } |
167 | |
168 | /** |
169 | * @generated |
170 | */ |
171 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
172 | return getContentPane(); |
173 | } |
174 | |
175 | /** |
176 | * @generated |
177 | */ |
178 | protected NodeFigure createNodePlate() { |
179 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
180 | return result; |
181 | } |
182 | |
183 | /** |
184 | * Creates figure for this edit part. |
185 | * |
186 | * Body of this method does not depend on settings in generation model so |
187 | * you may safely remove <i>generated</i> tag and modify it. |
188 | * |
189 | * @generated |
190 | */ |
191 | protected NodeFigure createNodeFigure() { |
192 | NodeFigure figure = createNodePlate(); |
193 | figure.setLayoutManager(new StackLayout()); |
194 | IFigure shape = createNodeShape(); |
195 | figure.add(shape); |
196 | contentPane = setupContentPane(shape); |
197 | return figure; |
198 | } |
199 | |
200 | /** |
201 | * Default implementation treats passed figure as content pane. Respects |
202 | * layout one may have set for generated figure. |
203 | * |
204 | * @param nodeShape |
205 | * instance of generated figure class |
206 | * @generated |
207 | */ |
208 | protected IFigure setupContentPane(IFigure nodeShape) { |
209 | if (nodeShape.getLayoutManager() == null) { |
210 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
211 | layout.setSpacing(5); |
212 | nodeShape.setLayoutManager(layout); |
213 | } |
214 | return nodeShape; // use nodeShape itself as contentPane |
215 | } |
216 | |
217 | /** |
218 | * @generated |
219 | */ |
220 | public IFigure getContentPane() { |
221 | if (contentPane != null) { |
222 | return contentPane; |
223 | } |
224 | return super.getContentPane(); |
225 | } |
226 | |
227 | /** |
228 | * @generated |
229 | */ |
230 | protected void setForegroundColor(Color color) { |
231 | if (primaryShape != null) { |
232 | primaryShape.setForegroundColor(color); |
233 | } |
234 | } |
235 | |
236 | /** |
237 | * @generated |
238 | */ |
239 | protected void setBackgroundColor(Color color) { |
240 | if (primaryShape != null) { |
241 | primaryShape.setBackgroundColor(color); |
242 | } |
243 | } |
244 | |
245 | /** |
246 | * @generated |
247 | */ |
248 | protected void setLineWidth(int width) { |
249 | if (primaryShape instanceof Shape) { |
250 | ((Shape) primaryShape).setLineWidth(width); |
251 | } |
252 | } |
253 | |
254 | /** |
255 | * @generated |
256 | */ |
257 | protected void setLineType(int style) { |
258 | if (primaryShape instanceof Shape) { |
259 | ((Shape) primaryShape).setLineStyle(style); |
260 | } |
261 | } |
262 | |
263 | /** |
264 | * @generated |
265 | */ |
266 | public EditPart getPrimaryChildEditPart() { |
267 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
268 | .getType(VariableUsageLabelEditPart.VISUAL_ID)); |
269 | } |
270 | |
271 | /** |
272 | * @generated |
273 | */ |
274 | public EditPart getTargetEditPart(Request request) { |
275 | if (request instanceof CreateViewAndElementRequest) { |
276 | CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request) |
277 | .getViewAndElementDescriptor() |
278 | .getCreateElementRequestAdapter(); |
279 | IElementType type = (IElementType) adapter |
280 | .getAdapter(IElementType.class); |
281 | if (type == PalladioComponentModelElementTypes.VariableCharacterisation_3105) { |
282 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
283 | .getType(VariableUsageComponentParameterVariableCharacterisationCompartmentEditPart.VISUAL_ID)); |
284 | } |
285 | } |
286 | return super.getTargetEditPart(request); |
287 | } |
288 | |
289 | /** |
290 | * @generated |
291 | */ |
292 | public class ParametricParameterUsageFigure extends RectangleFigure { |
293 | |
294 | /** |
295 | * @generated |
296 | */ |
297 | private WrappingLabel fFigureVariableUsageReferenceLabelFigure; |
298 | |
299 | /** |
300 | * @generated |
301 | */ |
302 | private RectangleFigure fFigureParametricParameterUsageRectangleCompartment; |
303 | |
304 | /** |
305 | * @generated |
306 | */ |
307 | public ParametricParameterUsageFigure() { |
308 | |
309 | GridLayout layoutThis = new GridLayout(); |
310 | layoutThis.numColumns = 1; |
311 | layoutThis.makeColumnsEqualWidth = true; |
312 | layoutThis.horizontalSpacing = 0; |
313 | layoutThis.verticalSpacing = 0; |
314 | layoutThis.marginWidth = 0; |
315 | layoutThis.marginHeight = 0; |
316 | this.setLayoutManager(layoutThis); |
317 | |
318 | this.setLineWidth(1); |
319 | this.setBackgroundColor(THIS_BACK); |
320 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
321 | getMapMode().DPtoLP(0))); |
322 | createContents(); |
323 | } |
324 | |
325 | /** |
326 | * @generated not |
327 | */ |
328 | private void createContents() { |
329 | |
330 | fFigureVariableUsageReferenceLabelFigure = new WrapLabel(); |
331 | if (resolveSemanticElement() != null) { |
332 | fFigureVariableUsageReferenceLabelFigure |
333 | .setText(new PCMStoExPrettyPrintVisitor() |
334 | .prettyPrint(((VariableUsage) resolveSemanticElement()) |
335 | .getNamedReference__VariableUsage())); |
336 | } else { |
337 | fFigureVariableUsageReferenceLabelFigure.setText("<null>"); |
338 | } |
339 | |
340 | this.add(fFigureVariableUsageReferenceLabelFigure); |
341 | |
342 | } |
343 | |
344 | /** |
345 | * @generated |
346 | */ |
347 | private boolean myUseLocalCoordinates = false; |
348 | |
349 | /** |
350 | * @generated |
351 | */ |
352 | protected boolean useLocalCoordinates() { |
353 | return myUseLocalCoordinates; |
354 | } |
355 | |
356 | /** |
357 | * @generated |
358 | */ |
359 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
360 | myUseLocalCoordinates = useLocalCoordinates; |
361 | } |
362 | |
363 | /** |
364 | * @generated |
365 | */ |
366 | public WrappingLabel getFigureVariableUsageReferenceLabelFigure() { |
367 | return fFigureVariableUsageReferenceLabelFigure; |
368 | } |
369 | |
370 | /** |
371 | * @generated |
372 | */ |
373 | public RectangleFigure getFigureParametricParameterUsageRectangleCompartment() { |
374 | return fFigureParametricParameterUsageRectangleCompartment; |
375 | } |
376 | |
377 | } |
378 | |
379 | /** |
380 | * @generated |
381 | */ |
382 | static final Color THIS_BACK = new Color(null, 220, 220, 220); |
383 | |
384 | } |