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