1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.edit.parts; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.List; |
8 | import org.eclipse.draw2d.GridData; |
9 | import org.eclipse.draw2d.GridLayout; |
10 | import org.eclipse.draw2d.IFigure; |
11 | import org.eclipse.draw2d.MarginBorder; |
12 | import org.eclipse.draw2d.RectangleFigure; |
13 | import org.eclipse.draw2d.Shape; |
14 | import org.eclipse.draw2d.StackLayout; |
15 | import org.eclipse.draw2d.geometry.Dimension; |
16 | import org.eclipse.gef.EditPart; |
17 | import org.eclipse.gef.EditPolicy; |
18 | import org.eclipse.gef.Request; |
19 | import org.eclipse.gef.commands.Command; |
20 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
21 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
22 | import org.eclipse.gef.requests.CreateRequest; |
23 | import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; |
24 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
25 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
28 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; |
29 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
30 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
31 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
32 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
33 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
34 | import org.eclipse.gmf.runtime.notation.View; |
35 | import org.eclipse.swt.graphics.Color; |
36 | |
37 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.policies.EventGroupItemSemanticEditPolicy; |
38 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry; |
39 | import de.uka.ipd.sdq.pcm.gmf.repository.providers.PalladioComponentModelElementTypes; |
40 | |
41 | /** |
42 | * @generated |
43 | */ |
44 | public class EventGroupEditPart extends ShapeNodeEditPart { |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public static final int VISUAL_ID = 2108; |
50 | |
51 | /** |
52 | * @generated |
53 | */ |
54 | protected IFigure contentPane; |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | protected IFigure primaryShape; |
60 | |
61 | /** |
62 | * @generated |
63 | */ |
64 | public EventGroupEditPart(View view) { |
65 | super(view); |
66 | } |
67 | |
68 | /** |
69 | * @generated |
70 | */ |
71 | protected void createDefaultEditPolicies() { |
72 | installEditPolicy(EditPolicyRoles.CREATION_ROLE, |
73 | new CreationEditPolicy()); |
74 | super.createDefaultEditPolicies(); |
75 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
76 | new EventGroupItemSemanticEditPolicy()); |
77 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
78 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
79 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
80 | } |
81 | |
82 | /** |
83 | * @generated |
84 | */ |
85 | protected LayoutEditPolicy createLayoutEditPolicy() { |
86 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
87 | |
88 | protected EditPolicy createChildEditPolicy(EditPart child) { |
89 | EditPolicy result = child |
90 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
91 | if (result == null) { |
92 | result = new NonResizableEditPolicy(); |
93 | } |
94 | return result; |
95 | } |
96 | |
97 | protected Command getMoveChildrenCommand(Request request) { |
98 | return null; |
99 | } |
100 | |
101 | protected Command getCreateCommand(CreateRequest request) { |
102 | return null; |
103 | } |
104 | }; |
105 | return lep; |
106 | } |
107 | |
108 | /** |
109 | * @generated |
110 | */ |
111 | protected IFigure createNodeShape() { |
112 | EventGroupFigure figure = new EventGroupFigure(); |
113 | return primaryShape = figure; |
114 | } |
115 | |
116 | /** |
117 | * @generated |
118 | */ |
119 | public EventGroupFigure getPrimaryShape() { |
120 | return (EventGroupFigure) primaryShape; |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | protected boolean addFixedChild(EditPart childEditPart) { |
127 | if (childEditPart instanceof EventGroupEntityNameEditPart) { |
128 | ((EventGroupEntityNameEditPart) childEditPart) |
129 | .setLabel(getPrimaryShape() |
130 | .getFigureEventGroup_Name_LabelFigure()); |
131 | return true; |
132 | } |
133 | if (childEditPart instanceof EventGroupEventTypeListEditPart) { |
134 | IFigure pane = getPrimaryShape().getFigureEventGroupCompartment(); |
135 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
136 | pane.add(((EventGroupEventTypeListEditPart) childEditPart) |
137 | .getFigure()); |
138 | return true; |
139 | } |
140 | return false; |
141 | } |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | protected boolean removeFixedChild(EditPart childEditPart) { |
147 | if (childEditPart instanceof EventGroupEntityNameEditPart) { |
148 | return true; |
149 | } |
150 | if (childEditPart instanceof EventGroupEventTypeListEditPart) { |
151 | IFigure pane = getPrimaryShape().getFigureEventGroupCompartment(); |
152 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
153 | pane.remove(((EventGroupEventTypeListEditPart) childEditPart) |
154 | .getFigure()); |
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 | if (editPart instanceof EventGroupEventTypeListEditPart) { |
185 | return getPrimaryShape().getFigureEventGroupCompartment(); |
186 | } |
187 | return getContentPane(); |
188 | } |
189 | |
190 | /** |
191 | * @generated |
192 | */ |
193 | protected NodeFigure createNodePlate() { |
194 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
195 | return result; |
196 | } |
197 | |
198 | /** |
199 | * Creates figure for this edit part. |
200 | * |
201 | * Body of this method does not depend on settings in generation model |
202 | * so you may safely remove <i>generated</i> tag and modify it. |
203 | * |
204 | * @generated |
205 | */ |
206 | protected NodeFigure createNodeFigure() { |
207 | NodeFigure figure = createNodePlate(); |
208 | figure.setLayoutManager(new StackLayout()); |
209 | IFigure shape = createNodeShape(); |
210 | figure.add(shape); |
211 | contentPane = setupContentPane(shape); |
212 | return figure; |
213 | } |
214 | |
215 | /** |
216 | * Default implementation treats passed figure as content pane. |
217 | * Respects layout one may have set for generated figure. |
218 | * @param nodeShape instance of generated figure class |
219 | * @generated |
220 | */ |
221 | protected IFigure setupContentPane(IFigure nodeShape) { |
222 | if (nodeShape.getLayoutManager() == null) { |
223 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
224 | layout.setSpacing(5); |
225 | nodeShape.setLayoutManager(layout); |
226 | } |
227 | return nodeShape; // use nodeShape itself as contentPane |
228 | } |
229 | |
230 | /** |
231 | * @generated |
232 | */ |
233 | public IFigure getContentPane() { |
234 | if (contentPane != null) { |
235 | return contentPane; |
236 | } |
237 | return super.getContentPane(); |
238 | } |
239 | |
240 | /** |
241 | * @generated |
242 | */ |
243 | protected void setForegroundColor(Color color) { |
244 | if (primaryShape != null) { |
245 | primaryShape.setForegroundColor(color); |
246 | } |
247 | } |
248 | |
249 | /** |
250 | * @generated |
251 | */ |
252 | protected void setBackgroundColor(Color color) { |
253 | if (primaryShape != null) { |
254 | primaryShape.setBackgroundColor(color); |
255 | } |
256 | } |
257 | |
258 | /** |
259 | * @generated |
260 | */ |
261 | protected void setLineWidth(int width) { |
262 | if (primaryShape instanceof Shape) { |
263 | ((Shape) primaryShape).setLineWidth(width); |
264 | } |
265 | } |
266 | |
267 | /** |
268 | * @generated |
269 | */ |
270 | protected void setLineType(int style) { |
271 | if (primaryShape instanceof Shape) { |
272 | ((Shape) primaryShape).setLineStyle(style); |
273 | } |
274 | } |
275 | |
276 | /** |
277 | * @generated |
278 | */ |
279 | public EditPart getPrimaryChildEditPart() { |
280 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
281 | .getType(EventGroupEntityNameEditPart.VISUAL_ID)); |
282 | } |
283 | |
284 | /** |
285 | * @generated |
286 | */ |
287 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
288 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
289 | types.add(PalladioComponentModelElementTypes.SinkRole_4109); |
290 | types.add(PalladioComponentModelElementTypes.SourceRole_4110); |
291 | return types; |
292 | } |
293 | |
294 | /** |
295 | * @generated |
296 | */ |
297 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
298 | IElementType relationshipType) { |
299 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
300 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
301 | types.add(PalladioComponentModelElementTypes.BasicComponent_2102); |
302 | } |
303 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
304 | types |
305 | .add(PalladioComponentModelElementTypes.CompositeComponent_2103); |
306 | } |
307 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
308 | types |
309 | .add(PalladioComponentModelElementTypes.CompleteComponentType_2104); |
310 | } |
311 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
312 | types |
313 | .add(PalladioComponentModelElementTypes.ProvidesComponentType_2105); |
314 | } |
315 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
316 | types.add(PalladioComponentModelElementTypes.SubSystem_2106); |
317 | } |
318 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
319 | types.add(PalladioComponentModelElementTypes.BasicComponent_2102); |
320 | } |
321 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
322 | types |
323 | .add(PalladioComponentModelElementTypes.CompositeComponent_2103); |
324 | } |
325 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
326 | types |
327 | .add(PalladioComponentModelElementTypes.CompleteComponentType_2104); |
328 | } |
329 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
330 | types |
331 | .add(PalladioComponentModelElementTypes.ProvidesComponentType_2105); |
332 | } |
333 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
334 | types.add(PalladioComponentModelElementTypes.SubSystem_2106); |
335 | } |
336 | return types; |
337 | } |
338 | |
339 | /** |
340 | * @generated |
341 | */ |
342 | public EditPart getTargetEditPart(Request request) { |
343 | if (request instanceof CreateViewAndElementRequest) { |
344 | CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request) |
345 | .getViewAndElementDescriptor() |
346 | .getCreateElementRequestAdapter(); |
347 | IElementType type = (IElementType) adapter |
348 | .getAdapter(IElementType.class); |
349 | if (type == PalladioComponentModelElementTypes.EventType_3107) { |
350 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
351 | .getType(EventGroupEventTypeListEditPart.VISUAL_ID)); |
352 | } |
353 | } |
354 | return super.getTargetEditPart(request); |
355 | } |
356 | |
357 | /** |
358 | * @generated |
359 | */ |
360 | public class EventGroupFigure extends RectangleFigure { |
361 | |
362 | /** |
363 | * @generated |
364 | */ |
365 | private WrappingLabel fFigureEventGroup_Name_LabelFigure; |
366 | /** |
367 | * @generated |
368 | */ |
369 | private RectangleFigure fFigureEventGroupCompartment; |
370 | |
371 | /** |
372 | * @generated |
373 | */ |
374 | public EventGroupFigure() { |
375 | |
376 | GridLayout layoutThis = new GridLayout(); |
377 | layoutThis.numColumns = 1; |
378 | layoutThis.makeColumnsEqualWidth = true; |
379 | layoutThis.horizontalSpacing = 0; |
380 | layoutThis.verticalSpacing = 0; |
381 | layoutThis.marginWidth = 0; |
382 | layoutThis.marginHeight = 0; |
383 | this.setLayoutManager(layoutThis); |
384 | |
385 | this.setLineWidth(1); |
386 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
387 | getMapMode().DPtoLP(0))); |
388 | createContents(); |
389 | } |
390 | |
391 | /** |
392 | * @generated |
393 | */ |
394 | private void createContents() { |
395 | |
396 | fFigureEventGroup_Name_LabelFigure = new WrappingLabel(); |
397 | fFigureEventGroup_Name_LabelFigure.setText("<...>"); |
398 | fFigureEventGroup_Name_LabelFigure.setBorder(new MarginBorder( |
399 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
400 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
401 | |
402 | GridData constraintFFigureEventGroup_Name_LabelFigure = new GridData(); |
403 | constraintFFigureEventGroup_Name_LabelFigure.verticalAlignment = GridData.CENTER; |
404 | constraintFFigureEventGroup_Name_LabelFigure.horizontalAlignment = GridData.CENTER; |
405 | constraintFFigureEventGroup_Name_LabelFigure.horizontalIndent = 0; |
406 | constraintFFigureEventGroup_Name_LabelFigure.horizontalSpan = 1; |
407 | constraintFFigureEventGroup_Name_LabelFigure.verticalSpan = 1; |
408 | constraintFFigureEventGroup_Name_LabelFigure.grabExcessHorizontalSpace = false; |
409 | constraintFFigureEventGroup_Name_LabelFigure.grabExcessVerticalSpace = false; |
410 | this.add(fFigureEventGroup_Name_LabelFigure, |
411 | constraintFFigureEventGroup_Name_LabelFigure); |
412 | |
413 | fFigureEventGroupCompartment = new RectangleFigure(); |
414 | fFigureEventGroupCompartment.setFill(false); |
415 | fFigureEventGroupCompartment.setOutline(false); |
416 | fFigureEventGroupCompartment.setLineWidth(1); |
417 | fFigureEventGroupCompartment.setMinimumSize(new Dimension( |
418 | getMapMode().DPtoLP(0), getMapMode().DPtoLP(0))); |
419 | |
420 | this.add(fFigureEventGroupCompartment); |
421 | |
422 | } |
423 | |
424 | /** |
425 | * @generated |
426 | */ |
427 | private boolean myUseLocalCoordinates = false; |
428 | |
429 | /** |
430 | * @generated |
431 | */ |
432 | protected boolean useLocalCoordinates() { |
433 | return myUseLocalCoordinates; |
434 | } |
435 | |
436 | /** |
437 | * @generated |
438 | */ |
439 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
440 | myUseLocalCoordinates = useLocalCoordinates; |
441 | } |
442 | |
443 | /** |
444 | * @generated |
445 | */ |
446 | public WrappingLabel getFigureEventGroup_Name_LabelFigure() { |
447 | return fFigureEventGroup_Name_LabelFigure; |
448 | } |
449 | |
450 | /** |
451 | * @generated |
452 | */ |
453 | public RectangleFigure getFigureEventGroupCompartment() { |
454 | return fFigureEventGroupCompartment; |
455 | } |
456 | |
457 | } |
458 | |
459 | } |