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.OpenWorkloadItemSemanticEditPolicy; |
33 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
34 | |
35 | /** |
36 | * @generated |
37 | */ |
38 | public class OpenWorkloadEditPart extends ShapeNodeEditPart { |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | public static final int VISUAL_ID = 3016; |
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 OpenWorkloadEditPart(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 OpenWorkloadItemSemanticEditPolicy()); |
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 | OpenWorkloadFigure figure = new OpenWorkloadFigure(); |
105 | return primaryShape = figure; |
106 | } |
107 | |
108 | /** |
109 | * @generated |
110 | */ |
111 | public OpenWorkloadFigure getPrimaryShape() { |
112 | return (OpenWorkloadFigure) primaryShape; |
113 | } |
114 | |
115 | /** |
116 | * @generated |
117 | */ |
118 | protected boolean addFixedChild(EditPart childEditPart) { |
119 | if (childEditPart instanceof OpenWorkloadSpecLabelEditPart) { |
120 | ((OpenWorkloadSpecLabelEditPart) childEditPart) |
121 | .setLabel(getPrimaryShape() |
122 | .getFigureOpenWorkloadSpecLabelFigure()); |
123 | return true; |
124 | } |
125 | return false; |
126 | } |
127 | |
128 | /** |
129 | * @generated |
130 | */ |
131 | protected boolean removeFixedChild(EditPart childEditPart) { |
132 | if (childEditPart instanceof OpenWorkloadSpecLabelEditPart) { |
133 | return true; |
134 | } |
135 | return false; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected void addChildVisual(EditPart childEditPart, int index) { |
142 | if (addFixedChild(childEditPart)) { |
143 | return; |
144 | } |
145 | super.addChildVisual(childEditPart, -1); |
146 | } |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | protected void removeChildVisual(EditPart childEditPart) { |
152 | if (removeFixedChild(childEditPart)) { |
153 | return; |
154 | } |
155 | super.removeChildVisual(childEditPart); |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
162 | return getContentPane(); |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | protected NodeFigure createNodePlate() { |
169 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
170 | return result; |
171 | } |
172 | |
173 | /** |
174 | * Creates figure for this edit part. |
175 | * |
176 | * Body of this method does not depend on settings in generation model |
177 | * so you may safely remove <i>generated</i> tag and modify it. |
178 | * |
179 | * @generated |
180 | */ |
181 | protected NodeFigure createNodeFigure() { |
182 | NodeFigure figure = createNodePlate(); |
183 | figure.setLayoutManager(new StackLayout()); |
184 | IFigure shape = createNodeShape(); |
185 | figure.add(shape); |
186 | contentPane = setupContentPane(shape); |
187 | return figure; |
188 | } |
189 | |
190 | /** |
191 | * Default implementation treats passed figure as content pane. |
192 | * Respects layout one may have set for generated figure. |
193 | * @param nodeShape instance of generated figure class |
194 | * @generated |
195 | */ |
196 | protected IFigure setupContentPane(IFigure nodeShape) { |
197 | if (nodeShape.getLayoutManager() == null) { |
198 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
199 | layout.setSpacing(5); |
200 | nodeShape.setLayoutManager(layout); |
201 | } |
202 | return nodeShape; // use nodeShape itself as contentPane |
203 | } |
204 | |
205 | /** |
206 | * @generated |
207 | */ |
208 | public IFigure getContentPane() { |
209 | if (contentPane != null) { |
210 | return contentPane; |
211 | } |
212 | return super.getContentPane(); |
213 | } |
214 | |
215 | /** |
216 | * @generated |
217 | */ |
218 | protected void setForegroundColor(Color color) { |
219 | if (primaryShape != null) { |
220 | primaryShape.setForegroundColor(color); |
221 | } |
222 | } |
223 | |
224 | /** |
225 | * @generated |
226 | */ |
227 | protected void setBackgroundColor(Color color) { |
228 | if (primaryShape != null) { |
229 | primaryShape.setBackgroundColor(color); |
230 | } |
231 | } |
232 | |
233 | /** |
234 | * @generated |
235 | */ |
236 | protected void setLineWidth(int width) { |
237 | if (primaryShape instanceof Shape) { |
238 | ((Shape) primaryShape).setLineWidth(width); |
239 | } |
240 | } |
241 | |
242 | /** |
243 | * @generated |
244 | */ |
245 | protected void setLineType(int style) { |
246 | if (primaryShape instanceof Shape) { |
247 | ((Shape) primaryShape).setLineStyle(style); |
248 | } |
249 | } |
250 | |
251 | /** |
252 | * @generated |
253 | */ |
254 | public EditPart getPrimaryChildEditPart() { |
255 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
256 | .getType(OpenWorkloadSpecLabelEditPart.VISUAL_ID)); |
257 | } |
258 | |
259 | /** |
260 | * @generated |
261 | */ |
262 | public class OpenWorkloadFigure extends RectangleFigure { |
263 | /** |
264 | * @generated |
265 | */ |
266 | private WrappingLabel fFigureOpenWorkloadSpecLabelFigure; |
267 | |
268 | /** |
269 | * @generated |
270 | */ |
271 | public OpenWorkloadFigure() { |
272 | |
273 | GridLayout layoutThis = new GridLayout(); |
274 | layoutThis.numColumns = 1; |
275 | layoutThis.makeColumnsEqualWidth = true; |
276 | layoutThis.horizontalSpacing = 0; |
277 | layoutThis.verticalSpacing = 0; |
278 | layoutThis.marginWidth = 0; |
279 | layoutThis.marginHeight = 0; |
280 | this.setLayoutManager(layoutThis); |
281 | |
282 | this.setLineWidth(1); |
283 | this.setBackgroundColor(ColorConstants.yellow); |
284 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
285 | getMapMode().DPtoLP(0))); |
286 | createContents(); |
287 | } |
288 | |
289 | /** |
290 | * @generated |
291 | */ |
292 | private void createContents() { |
293 | |
294 | WrappingLabel openWorkloadStereotypeLabelFigure0 = new WrappingLabel(); |
295 | openWorkloadStereotypeLabelFigure0.setText("<<Open Workload>>"); |
296 | openWorkloadStereotypeLabelFigure0.setBorder(new MarginBorder( |
297 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
298 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
299 | |
300 | GridData constraintOpenWorkloadStereotypeLabelFigure0 = new GridData(); |
301 | constraintOpenWorkloadStereotypeLabelFigure0.verticalAlignment = GridData.BEGINNING; |
302 | constraintOpenWorkloadStereotypeLabelFigure0.horizontalAlignment = GridData.CENTER; |
303 | constraintOpenWorkloadStereotypeLabelFigure0.horizontalIndent = 0; |
304 | constraintOpenWorkloadStereotypeLabelFigure0.horizontalSpan = 1; |
305 | constraintOpenWorkloadStereotypeLabelFigure0.verticalSpan = 1; |
306 | constraintOpenWorkloadStereotypeLabelFigure0.grabExcessHorizontalSpace = true; |
307 | constraintOpenWorkloadStereotypeLabelFigure0.grabExcessVerticalSpace = false; |
308 | this.add(openWorkloadStereotypeLabelFigure0, |
309 | constraintOpenWorkloadStereotypeLabelFigure0); |
310 | |
311 | fFigureOpenWorkloadSpecLabelFigure = new WrappingLabel(); |
312 | fFigureOpenWorkloadSpecLabelFigure.setText("<spec>"); |
313 | |
314 | GridData constraintFFigureOpenWorkloadSpecLabelFigure = new GridData(); |
315 | constraintFFigureOpenWorkloadSpecLabelFigure.verticalAlignment = GridData.END; |
316 | constraintFFigureOpenWorkloadSpecLabelFigure.horizontalAlignment = GridData.CENTER; |
317 | constraintFFigureOpenWorkloadSpecLabelFigure.horizontalIndent = 0; |
318 | constraintFFigureOpenWorkloadSpecLabelFigure.horizontalSpan = 1; |
319 | constraintFFigureOpenWorkloadSpecLabelFigure.verticalSpan = 1; |
320 | constraintFFigureOpenWorkloadSpecLabelFigure.grabExcessHorizontalSpace = true; |
321 | constraintFFigureOpenWorkloadSpecLabelFigure.grabExcessVerticalSpace = false; |
322 | this.add(fFigureOpenWorkloadSpecLabelFigure, |
323 | constraintFFigureOpenWorkloadSpecLabelFigure); |
324 | |
325 | } |
326 | |
327 | /** |
328 | * @generated |
329 | */ |
330 | public WrappingLabel getFigureOpenWorkloadSpecLabelFigure() { |
331 | return fFigureOpenWorkloadSpecLabelFigure; |
332 | } |
333 | |
334 | /** |
335 | * @generated |
336 | */ |
337 | private boolean myUseLocalCoordinates = false; |
338 | |
339 | /** |
340 | * @generated |
341 | */ |
342 | protected boolean useLocalCoordinates() { |
343 | return myUseLocalCoordinates; |
344 | } |
345 | |
346 | /** |
347 | * @generated |
348 | */ |
349 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
350 | myUseLocalCoordinates = useLocalCoordinates; |
351 | } |
352 | |
353 | } |
354 | |
355 | } |