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