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