1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.parts; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.Collections; |
8 | import java.util.List; |
9 | |
10 | import org.eclipse.draw2d.Ellipse; |
11 | import org.eclipse.draw2d.IFigure; |
12 | import org.eclipse.draw2d.PositionConstants; |
13 | import org.eclipse.draw2d.Shape; |
14 | import org.eclipse.draw2d.StackLayout; |
15 | import org.eclipse.draw2d.geometry.Dimension; |
16 | import org.eclipse.draw2d.geometry.Point; |
17 | import org.eclipse.gef.EditPart; |
18 | import org.eclipse.gef.EditPolicy; |
19 | import org.eclipse.gef.GraphicalEditPart; |
20 | import org.eclipse.gef.Request; |
21 | import org.eclipse.gef.commands.Command; |
22 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
23 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
24 | import org.eclipse.gef.editpolicies.ResizableEditPolicy; |
25 | import org.eclipse.gef.handles.MoveHandle; |
26 | import org.eclipse.gef.requests.CreateRequest; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart; |
28 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; |
29 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
30 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; |
31 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
32 | import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; |
33 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
34 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
35 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
36 | import org.eclipse.gmf.runtime.notation.View; |
37 | import org.eclipse.swt.graphics.Color; |
38 | |
39 | import de.uka.ipd.sdq.pcm.gmf.composite.SocketFigure; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.AbstractBorderFigure.POSITION_TYPE; |
41 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.OperationRequiredRole2ItemSemanticEditPolicy; |
42 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
43 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
44 | |
45 | /** |
46 | * Operation Required Role Edit Part for outer system operation required roles. |
47 | * |
48 | * For assembly context operation required roles |
49 | * @see OperationRequiredRoleEditPart |
50 | * |
51 | * @generated |
52 | */ |
53 | public class OperationRequiredRole2EditPart extends BorderedBorderItemEditPart { |
54 | |
55 | /** |
56 | * size of the figure in LP |
57 | * |
58 | * @generated not |
59 | */ |
60 | private static final int FIGURE_LOGICAL_SIZE = 60; |
61 | |
62 | /** |
63 | * @generated |
64 | */ |
65 | public static final int VISUAL_ID = 3012; |
66 | |
67 | /** |
68 | * @generated |
69 | */ |
70 | protected IFigure contentPane; |
71 | |
72 | /** |
73 | * @generated |
74 | */ |
75 | protected IFigure primaryShape; |
76 | |
77 | /** |
78 | * @generated |
79 | */ |
80 | public OperationRequiredRole2EditPart(View view) { |
81 | super(view); |
82 | } |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | protected void createDefaultEditPolicies() { |
88 | super.createDefaultEditPolicies(); |
89 | installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, |
90 | getPrimaryDragEditPolicy()); |
91 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
92 | new OperationRequiredRole2ItemSemanticEditPolicy()); |
93 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
94 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
95 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
96 | } |
97 | |
98 | /** |
99 | * @generated |
100 | */ |
101 | protected LayoutEditPolicy createLayoutEditPolicy() { |
102 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
103 | |
104 | protected EditPolicy createChildEditPolicy(EditPart child) { |
105 | View childView = (View) child.getModel(); |
106 | switch (PalladioComponentModelVisualIDRegistry |
107 | .getVisualID(childView)) { |
108 | case OperationRequiredRoleEntityName2EditPart.VISUAL_ID: |
109 | return new BorderItemSelectionEditPolicy() { |
110 | |
111 | protected List createSelectionHandles() { |
112 | MoveHandle mh = new MoveHandle( |
113 | (GraphicalEditPart) getHost()); |
114 | mh.setBorder(null); |
115 | return Collections.singletonList(mh); |
116 | } |
117 | }; |
118 | } |
119 | EditPolicy result = child |
120 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
121 | if (result == null) { |
122 | result = new NonResizableEditPolicy(); |
123 | } |
124 | return result; |
125 | } |
126 | |
127 | protected Command getMoveChildrenCommand(Request request) { |
128 | return null; |
129 | } |
130 | |
131 | protected Command getCreateCommand(CreateRequest request) { |
132 | return null; |
133 | } |
134 | }; |
135 | return lep; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected IFigure createNodeShape() { |
142 | OperationRequiredRoleFigure figure = new OperationRequiredRoleFigure(); |
143 | return primaryShape = figure; |
144 | } |
145 | |
146 | /** |
147 | * @generated |
148 | */ |
149 | public OperationRequiredRoleFigure getPrimaryShape() { |
150 | return (OperationRequiredRoleFigure) primaryShape; |
151 | } |
152 | |
153 | /** |
154 | * @generated |
155 | */ |
156 | protected void addBorderItem(IFigure borderItemContainer, |
157 | IBorderItemEditPart borderItemEditPart) { |
158 | if (borderItemEditPart instanceof OperationRequiredRoleEntityName2EditPart) { |
159 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
160 | PositionConstants.SOUTH); |
161 | locator.setBorderItemOffset(new Dimension(-20, -20)); |
162 | borderItemContainer.add(borderItemEditPart.getFigure(), locator); |
163 | } else { |
164 | super.addBorderItem(borderItemContainer, borderItemEditPart); |
165 | } |
166 | } |
167 | |
168 | /** |
169 | * @generated not |
170 | */ |
171 | protected NodeFigure createNodePlate() { |
172 | //DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode() |
173 | // .DPtoLP(20), getMapMode().DPtoLP(20)); |
174 | |
175 | SocketFigure result = new SocketFigure(getMapMode().DPtoLP( |
176 | FIGURE_LOGICAL_SIZE), POSITION_TYPE.POS_EXTERNAL); |
177 | |
178 | //FIXME: workaround for #154536 |
179 | result.getBounds().setSize(result.getPreferredSize()); |
180 | return result; |
181 | } |
182 | |
183 | /** |
184 | * @generated |
185 | */ |
186 | public EditPolicy getPrimaryDragEditPolicy() { |
187 | EditPolicy result = super.getPrimaryDragEditPolicy(); |
188 | if (result instanceof ResizableEditPolicy) { |
189 | ResizableEditPolicy ep = (ResizableEditPolicy) result; |
190 | ep.setResizeDirections(PositionConstants.NONE); |
191 | } |
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 not |
202 | */ |
203 | protected NodeFigure createMainFigure() { |
204 | NodeFigure figure = createNodePlate(); |
205 | //figure.setLayoutManager(new StackLayout()); |
206 | //IFigure shape = createNodeShape(); |
207 | //figure.add(shape); |
208 | //contentPane = setupContentPane(shape); |
209 | |
210 | return figure; |
211 | } |
212 | |
213 | /** |
214 | * Default implementation treats passed figure as content pane. |
215 | * Respects layout one may have set for generated figure. |
216 | * @param nodeShape instance of generated figure class |
217 | * @generated |
218 | */ |
219 | protected IFigure setupContentPane(IFigure nodeShape) { |
220 | return nodeShape; // use nodeShape itself as contentPane |
221 | } |
222 | |
223 | /** |
224 | * @generated |
225 | */ |
226 | public IFigure getContentPane() { |
227 | if (contentPane != null) { |
228 | return contentPane; |
229 | } |
230 | return super.getContentPane(); |
231 | } |
232 | |
233 | /** |
234 | * @generated |
235 | */ |
236 | protected void setForegroundColor(Color color) { |
237 | if (primaryShape != null) { |
238 | primaryShape.setForegroundColor(color); |
239 | } |
240 | } |
241 | |
242 | /** |
243 | * @generated |
244 | */ |
245 | protected void setBackgroundColor(Color color) { |
246 | if (primaryShape != null) { |
247 | primaryShape.setBackgroundColor(color); |
248 | } |
249 | } |
250 | |
251 | /** |
252 | * @generated |
253 | */ |
254 | protected void setLineWidth(int width) { |
255 | if (primaryShape instanceof Shape) { |
256 | ((Shape) primaryShape).setLineWidth(width); |
257 | } |
258 | } |
259 | |
260 | /** |
261 | * @generated |
262 | */ |
263 | protected void setLineType(int style) { |
264 | if (primaryShape instanceof Shape) { |
265 | ((Shape) primaryShape).setLineStyle(style); |
266 | } |
267 | } |
268 | |
269 | /** |
270 | * @generated |
271 | */ |
272 | public EditPart getPrimaryChildEditPart() { |
273 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
274 | .getType(OperationRequiredRoleEntityName2EditPart.VISUAL_ID)); |
275 | } |
276 | |
277 | /** |
278 | * @generated |
279 | */ |
280 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
281 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
282 | types.add(PalladioComponentModelElementTypes.AssemblyConnector_4004); |
283 | types |
284 | .add(PalladioComponentModelElementTypes.RequiredDelegationConnector_4005); |
285 | return types; |
286 | } |
287 | |
288 | /** |
289 | * @generated |
290 | */ |
291 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
292 | IGraphicalEditPart targetEditPart) { |
293 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
294 | if (targetEditPart instanceof OperationProvidedRoleEditPart) { |
295 | types |
296 | .add(PalladioComponentModelElementTypes.AssemblyConnector_4004); |
297 | } |
298 | if (targetEditPart instanceof OperationProvidedRole2EditPart) { |
299 | types |
300 | .add(PalladioComponentModelElementTypes.AssemblyConnector_4004); |
301 | } |
302 | if (targetEditPart instanceof OperationRequiredRoleEditPart) { |
303 | types |
304 | .add(PalladioComponentModelElementTypes.RequiredDelegationConnector_4005); |
305 | } |
306 | if (targetEditPart instanceof de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationRequiredRole2EditPart) { |
307 | types |
308 | .add(PalladioComponentModelElementTypes.RequiredDelegationConnector_4005); |
309 | } |
310 | return types; |
311 | } |
312 | |
313 | /** |
314 | * @generated |
315 | */ |
316 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
317 | IElementType relationshipType) { |
318 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
319 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyConnector_4004) { |
320 | types |
321 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_3007); |
322 | } |
323 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyConnector_4004) { |
324 | types |
325 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_3011); |
326 | } |
327 | if (relationshipType == PalladioComponentModelElementTypes.RequiredDelegationConnector_4005) { |
328 | types |
329 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_3008); |
330 | } |
331 | if (relationshipType == PalladioComponentModelElementTypes.RequiredDelegationConnector_4005) { |
332 | types |
333 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_3012); |
334 | } |
335 | return types; |
336 | } |
337 | |
338 | /** |
339 | * @generated |
340 | */ |
341 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
342 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
343 | types |
344 | .add(PalladioComponentModelElementTypes.RequiredDelegationConnector_4005); |
345 | return types; |
346 | } |
347 | |
348 | /** |
349 | * @generated |
350 | */ |
351 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
352 | IElementType relationshipType) { |
353 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
354 | if (relationshipType == PalladioComponentModelElementTypes.RequiredDelegationConnector_4005) { |
355 | types |
356 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_3008); |
357 | } |
358 | if (relationshipType == PalladioComponentModelElementTypes.RequiredDelegationConnector_4005) { |
359 | types |
360 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_3012); |
361 | } |
362 | return types; |
363 | } |
364 | |
365 | /** |
366 | * @generated |
367 | */ |
368 | public class OperationRequiredRoleFigure extends Ellipse { |
369 | |
370 | /** |
371 | * @generated |
372 | */ |
373 | public OperationRequiredRoleFigure() { |
374 | this.setLineWidth(1); |
375 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(20), |
376 | getMapMode().DPtoLP(20))); |
377 | this.setLocation(new Point(getMapMode().DPtoLP(50), getMapMode() |
378 | .DPtoLP(50))); |
379 | } |
380 | |
381 | /** |
382 | * @generated |
383 | */ |
384 | private boolean myUseLocalCoordinates = false; |
385 | |
386 | /** |
387 | * @generated |
388 | */ |
389 | protected boolean useLocalCoordinates() { |
390 | return myUseLocalCoordinates; |
391 | } |
392 | |
393 | /** |
394 | * @generated |
395 | */ |
396 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
397 | myUseLocalCoordinates = useLocalCoordinates; |
398 | } |
399 | |
400 | } |
401 | |
402 | } |