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.Graphics; |
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.CreationEditPolicy; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
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.gef.ui.figures.DefaultSizeNodeFigure; |
30 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
31 | import org.eclipse.gmf.runtime.notation.View; |
32 | import org.eclipse.swt.SWT; |
33 | import org.eclipse.swt.graphics.Color; |
34 | |
35 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.BranchTransitionCanonicalEditPolicy; |
36 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.BranchTransitionItemSemanticEditPolicy; |
37 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
38 | |
39 | /** |
40 | * @generated |
41 | */ |
42 | public class BranchTransitionEditPart extends ShapeNodeEditPart { |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | public static final int VISUAL_ID = 3009; |
48 | |
49 | /** |
50 | * @generated |
51 | */ |
52 | protected IFigure contentPane; |
53 | |
54 | /** |
55 | * @generated |
56 | */ |
57 | protected IFigure primaryShape; |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | public BranchTransitionEditPart(View view) { |
63 | super(view); |
64 | } |
65 | |
66 | /** |
67 | * @generated |
68 | */ |
69 | protected void createDefaultEditPolicies() { |
70 | installEditPolicy(EditPolicyRoles.CREATION_ROLE, |
71 | new CreationEditPolicy()); |
72 | super.createDefaultEditPolicies(); |
73 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
74 | new BranchTransitionItemSemanticEditPolicy()); |
75 | installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, |
76 | new DragDropEditPolicy()); |
77 | installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, |
78 | new BranchTransitionCanonicalEditPolicy()); |
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 | BranchTransitionFigure figure = new BranchTransitionFigure(); |
115 | return primaryShape = figure; |
116 | } |
117 | |
118 | /** |
119 | * @generated |
120 | */ |
121 | public BranchTransitionFigure getPrimaryShape() { |
122 | return (BranchTransitionFigure) primaryShape; |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | protected boolean addFixedChild(EditPart childEditPart) { |
129 | if (childEditPart instanceof BranchTransitionBranchProbabilityEditPart) { |
130 | ((BranchTransitionBranchProbabilityEditPart) childEditPart) |
131 | .setLabel(getPrimaryShape() |
132 | .getFigureBranchTransitionProbabilityLabel()); |
133 | return true; |
134 | } |
135 | return false; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected boolean removeFixedChild(EditPart childEditPart) { |
142 | if (childEditPart instanceof BranchTransitionBranchProbabilityEditPart) { |
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 |
187 | * so 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. |
202 | * Respects layout one may have set for generated figure. |
203 | * @param nodeShape instance of generated figure class |
204 | * @generated |
205 | */ |
206 | protected IFigure setupContentPane(IFigure nodeShape) { |
207 | if (nodeShape.getLayoutManager() == null) { |
208 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
209 | layout.setSpacing(5); |
210 | nodeShape.setLayoutManager(layout); |
211 | } |
212 | return nodeShape; // use nodeShape itself as contentPane |
213 | } |
214 | |
215 | /** |
216 | * @generated |
217 | */ |
218 | public IFigure getContentPane() { |
219 | if (contentPane != null) { |
220 | return contentPane; |
221 | } |
222 | return super.getContentPane(); |
223 | } |
224 | |
225 | /** |
226 | * @generated |
227 | */ |
228 | protected void setForegroundColor(Color color) { |
229 | if (primaryShape != null) { |
230 | primaryShape.setForegroundColor(color); |
231 | } |
232 | } |
233 | |
234 | /** |
235 | * @generated |
236 | */ |
237 | protected void setBackgroundColor(Color color) { |
238 | if (primaryShape != null) { |
239 | primaryShape.setBackgroundColor(color); |
240 | } |
241 | } |
242 | |
243 | /** |
244 | * @generated |
245 | */ |
246 | protected void setLineWidth(int width) { |
247 | if (primaryShape instanceof Shape) { |
248 | ((Shape) primaryShape).setLineWidth(width); |
249 | } |
250 | } |
251 | |
252 | /** |
253 | * @generated |
254 | */ |
255 | protected void setLineType(int style) { |
256 | if (primaryShape instanceof Shape) { |
257 | ((Shape) primaryShape).setLineStyle(style); |
258 | } |
259 | } |
260 | |
261 | /** |
262 | * @generated |
263 | */ |
264 | public EditPart getPrimaryChildEditPart() { |
265 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
266 | .getType(BranchTransitionBranchProbabilityEditPart.VISUAL_ID)); |
267 | } |
268 | |
269 | /** |
270 | * @generated |
271 | */ |
272 | public class BranchTransitionFigure extends RectangleFigure { |
273 | /** |
274 | * @generated |
275 | */ |
276 | private WrappingLabel fFigureBranchTransitionNameLabel; |
277 | /** |
278 | * @generated |
279 | */ |
280 | private WrappingLabel fFigureBranchTransitionConditionLabel; |
281 | /** |
282 | * @generated |
283 | */ |
284 | private WrappingLabel fFigureBranchTransitionProbabilityLabel; |
285 | |
286 | /** |
287 | * @generated |
288 | */ |
289 | public BranchTransitionFigure() { |
290 | |
291 | GridLayout layoutThis = new GridLayout(); |
292 | layoutThis.numColumns = 1; |
293 | layoutThis.makeColumnsEqualWidth = true; |
294 | layoutThis.horizontalSpacing = 0; |
295 | layoutThis.verticalSpacing = 0; |
296 | layoutThis.marginWidth = 0; |
297 | layoutThis.marginHeight = 0; |
298 | this.setLayoutManager(layoutThis); |
299 | |
300 | this.setLineWidth(2); |
301 | this.setLineStyle(Graphics.LINE_DASH); |
302 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
303 | getMapMode().DPtoLP(0))); |
304 | createContents(); |
305 | } |
306 | |
307 | /** |
308 | * @generated |
309 | */ |
310 | private void createContents() { |
311 | |
312 | fFigureBranchTransitionNameLabel = new WrappingLabel(); |
313 | fFigureBranchTransitionNameLabel.setText(""); |
314 | fFigureBranchTransitionNameLabel.setBorder(new MarginBorder( |
315 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
316 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
317 | |
318 | GridData constraintFFigureBranchTransitionNameLabel = new GridData(); |
319 | constraintFFigureBranchTransitionNameLabel.verticalAlignment = GridData.CENTER; |
320 | constraintFFigureBranchTransitionNameLabel.horizontalAlignment = GridData.CENTER; |
321 | constraintFFigureBranchTransitionNameLabel.horizontalIndent = 0; |
322 | constraintFFigureBranchTransitionNameLabel.horizontalSpan = 1; |
323 | constraintFFigureBranchTransitionNameLabel.verticalSpan = 1; |
324 | constraintFFigureBranchTransitionNameLabel.grabExcessHorizontalSpace = false; |
325 | constraintFFigureBranchTransitionNameLabel.grabExcessVerticalSpace = false; |
326 | this.add(fFigureBranchTransitionNameLabel, |
327 | constraintFFigureBranchTransitionNameLabel); |
328 | |
329 | fFigureBranchTransitionProbabilityLabel = new WrappingLabel(); |
330 | fFigureBranchTransitionProbabilityLabel.setText(""); |
331 | fFigureBranchTransitionProbabilityLabel.setBorder(new MarginBorder( |
332 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
333 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
334 | |
335 | GridData constraintFFigureBranchTransitionProbabilityLabel = new GridData(); |
336 | constraintFFigureBranchTransitionProbabilityLabel.verticalAlignment = GridData.CENTER; |
337 | constraintFFigureBranchTransitionProbabilityLabel.horizontalAlignment = GridData.CENTER; |
338 | constraintFFigureBranchTransitionProbabilityLabel.horizontalIndent = 0; |
339 | constraintFFigureBranchTransitionProbabilityLabel.horizontalSpan = 1; |
340 | constraintFFigureBranchTransitionProbabilityLabel.verticalSpan = 1; |
341 | constraintFFigureBranchTransitionProbabilityLabel.grabExcessHorizontalSpace = false; |
342 | constraintFFigureBranchTransitionProbabilityLabel.grabExcessVerticalSpace = false; |
343 | this.add(fFigureBranchTransitionProbabilityLabel, |
344 | constraintFFigureBranchTransitionProbabilityLabel); |
345 | |
346 | fFigureBranchTransitionConditionLabel = new WrappingLabel(); |
347 | fFigureBranchTransitionConditionLabel.setText(""); |
348 | fFigureBranchTransitionConditionLabel.setBorder(new MarginBorder( |
349 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
350 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
351 | |
352 | GridData constraintFFigureBranchTransitionConditionLabel = new GridData(); |
353 | constraintFFigureBranchTransitionConditionLabel.verticalAlignment = GridData.CENTER; |
354 | constraintFFigureBranchTransitionConditionLabel.horizontalAlignment = GridData.CENTER; |
355 | constraintFFigureBranchTransitionConditionLabel.horizontalIndent = 0; |
356 | constraintFFigureBranchTransitionConditionLabel.horizontalSpan = 1; |
357 | constraintFFigureBranchTransitionConditionLabel.verticalSpan = 1; |
358 | constraintFFigureBranchTransitionConditionLabel.grabExcessHorizontalSpace = false; |
359 | constraintFFigureBranchTransitionConditionLabel.grabExcessVerticalSpace = false; |
360 | this.add(fFigureBranchTransitionConditionLabel, |
361 | constraintFFigureBranchTransitionConditionLabel); |
362 | |
363 | } |
364 | |
365 | /** |
366 | * @generated |
367 | */ |
368 | public WrappingLabel getFigureBranchTransitionProbabilityLabel() { |
369 | return fFigureBranchTransitionProbabilityLabel; |
370 | } |
371 | |
372 | /** |
373 | * @generated |
374 | */ |
375 | private boolean myUseLocalCoordinates = false; |
376 | |
377 | /** |
378 | * @generated |
379 | */ |
380 | protected boolean useLocalCoordinates() { |
381 | return myUseLocalCoordinates; |
382 | } |
383 | |
384 | /** |
385 | * @generated |
386 | */ |
387 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
388 | myUseLocalCoordinates = useLocalCoordinates; |
389 | } |
390 | |
391 | /** |
392 | * @generated |
393 | */ |
394 | public WrappingLabel getFigureBranchTransitionNameLabel() { |
395 | return fFigureBranchTransitionNameLabel; |
396 | } |
397 | |
398 | /** |
399 | * @generated |
400 | */ |
401 | public WrappingLabel getFigureBranchTransitionConditionLabel() { |
402 | return fFigureBranchTransitionConditionLabel; |
403 | } |
404 | |
405 | @Override |
406 | public void add(IFigure figure, Object constraint, int index) { |
407 | Object newConstraint = constraint; |
408 | if (newConstraint == null) { |
409 | GridData layout = new GridData(); |
410 | layout.grabExcessHorizontalSpace = true; |
411 | layout.grabExcessVerticalSpace = true; |
412 | layout.horizontalAlignment = SWT.FILL; |
413 | layout.verticalAlignment = SWT.FILL; |
414 | layout.horizontalSpan = 1; |
415 | layout.verticalSpan = 1; |
416 | |
417 | newConstraint = layout; |
418 | } |
419 | super.add(figure, newConstraint, index); |
420 | } |
421 | |
422 | } |
423 | |
424 | } |