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.IFigure; |
11 | import org.eclipse.draw2d.PositionConstants; |
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.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.InfrastructureProvidedRoleManualFigure; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.InfrastructureRequiredRoleManualFigure; |
41 | import de.uka.ipd.sdq.pcm.gmf.composite.AbstractBorderFigure.POSITION_TYPE; |
42 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.InfrastructureRequiredRoleItemSemanticEditPolicy; |
43 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
44 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public class InfrastructureRequiredRoleEditPart extends |
50 | BorderedBorderItemEditPart { |
51 | |
52 | /** |
53 | * size of the figure in LP |
54 | * |
55 | * @generated not |
56 | */ |
57 | private static final int FIGURE_LOGICAL_SIZE = 30; |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | public static final int VISUAL_ID = 3016; |
63 | |
64 | /** |
65 | * @generated |
66 | */ |
67 | protected IFigure contentPane; |
68 | |
69 | /** |
70 | * @generated |
71 | */ |
72 | protected IFigure primaryShape; |
73 | |
74 | /** |
75 | * @generated |
76 | */ |
77 | public InfrastructureRequiredRoleEditPart(View view) { |
78 | super(view); |
79 | } |
80 | |
81 | /** |
82 | * @generated |
83 | */ |
84 | protected void createDefaultEditPolicies() { |
85 | super.createDefaultEditPolicies(); |
86 | installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, |
87 | getPrimaryDragEditPolicy()); |
88 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
89 | new InfrastructureRequiredRoleItemSemanticEditPolicy()); |
90 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
91 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
92 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
93 | } |
94 | |
95 | /** |
96 | * @generated |
97 | */ |
98 | protected LayoutEditPolicy createLayoutEditPolicy() { |
99 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
100 | |
101 | protected EditPolicy createChildEditPolicy(EditPart child) { |
102 | View childView = (View) child.getModel(); |
103 | switch (PalladioComponentModelVisualIDRegistry |
104 | .getVisualID(childView)) { |
105 | case InfrastructureRequiredRoleEntityNameEditPart.VISUAL_ID: |
106 | return new BorderItemSelectionEditPolicy() { |
107 | |
108 | protected List createSelectionHandles() { |
109 | MoveHandle mh = new MoveHandle( |
110 | (GraphicalEditPart) getHost()); |
111 | mh.setBorder(null); |
112 | return Collections.singletonList(mh); |
113 | } |
114 | }; |
115 | } |
116 | EditPolicy result = child |
117 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
118 | if (result == null) { |
119 | result = new NonResizableEditPolicy(); |
120 | } |
121 | return result; |
122 | } |
123 | |
124 | protected Command getMoveChildrenCommand(Request request) { |
125 | return null; |
126 | } |
127 | |
128 | protected Command getCreateCommand(CreateRequest request) { |
129 | return null; |
130 | } |
131 | }; |
132 | return lep; |
133 | } |
134 | |
135 | /** |
136 | * @generated |
137 | */ |
138 | protected IFigure createNodeShape() { |
139 | InfrastructureRequiredRoleFigure figure = new InfrastructureRequiredRoleFigure(); |
140 | return primaryShape = figure; |
141 | } |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | public InfrastructureRequiredRoleFigure getPrimaryShape() { |
147 | return (InfrastructureRequiredRoleFigure) primaryShape; |
148 | } |
149 | |
150 | /** |
151 | * @generated |
152 | */ |
153 | protected void addBorderItem(IFigure borderItemContainer, |
154 | IBorderItemEditPart borderItemEditPart) { |
155 | if (borderItemEditPart instanceof InfrastructureRequiredRoleEntityNameEditPart) { |
156 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
157 | PositionConstants.SOUTH); |
158 | locator.setBorderItemOffset(new Dimension(-20, -20)); |
159 | borderItemContainer.add(borderItemEditPart.getFigure(), locator); |
160 | } else { |
161 | super.addBorderItem(borderItemContainer, borderItemEditPart); |
162 | } |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | protected NodeFigure createNodePlate() { |
169 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(20, 20); |
170 | |
171 | //FIXME: workaround for #154536 |
172 | result.getBounds().setSize(result.getPreferredSize()); |
173 | return result; |
174 | } |
175 | |
176 | /** |
177 | * @generated |
178 | */ |
179 | public EditPolicy getPrimaryDragEditPolicy() { |
180 | EditPolicy result = super.getPrimaryDragEditPolicy(); |
181 | if (result instanceof ResizableEditPolicy) { |
182 | ResizableEditPolicy ep = (ResizableEditPolicy) result; |
183 | ep.setResizeDirections(PositionConstants.NONE); |
184 | } |
185 | return result; |
186 | } |
187 | |
188 | /** |
189 | * Creates figure for this edit part. |
190 | * |
191 | * Body of this method does not depend on settings in generation model |
192 | * so you may safely remove <i>generated</i> tag and modify it. |
193 | * |
194 | * Manually modified to generate a specific source figure |
195 | * instead of the standard shape configured in the map model. |
196 | * |
197 | * @generated not |
198 | */ |
199 | protected NodeFigure createMainFigure() { |
200 | InfrastructureRequiredRoleManualFigure figure = new InfrastructureRequiredRoleManualFigure(getMapMode().DPtoLP( |
201 | FIGURE_LOGICAL_SIZE), POSITION_TYPE.POS_INTERNAL); |
202 | figure.getBounds().setSize(figure.getPreferredSize()); |
203 | return figure; |
204 | } |
205 | |
206 | /** |
207 | * Default implementation treats passed figure as content pane. |
208 | * Respects layout one may have set for generated figure. |
209 | * @param nodeShape instance of generated figure class |
210 | * @generated |
211 | */ |
212 | protected IFigure setupContentPane(IFigure nodeShape) { |
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 EditPart getPrimaryChildEditPart() { |
266 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
267 | .getType(InfrastructureRequiredRoleEntityNameEditPart.VISUAL_ID)); |
268 | } |
269 | |
270 | /** |
271 | * @generated |
272 | */ |
273 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
274 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
275 | types |
276 | .add(PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008); |
277 | return types; |
278 | } |
279 | |
280 | /** |
281 | * @generated |
282 | */ |
283 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
284 | IGraphicalEditPart targetEditPart) { |
285 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
286 | if (targetEditPart instanceof InfrastructureProvidedRoleEditPart) { |
287 | types |
288 | .add(PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008); |
289 | } |
290 | return types; |
291 | } |
292 | |
293 | /** |
294 | * @generated |
295 | */ |
296 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
297 | IElementType relationshipType) { |
298 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
299 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008) { |
300 | types |
301 | .add(PalladioComponentModelElementTypes.InfrastructureProvidedRole_3015); |
302 | } |
303 | return types; |
304 | } |
305 | |
306 | /** |
307 | * @generated |
308 | */ |
309 | public class InfrastructureRequiredRoleFigure extends RectangleFigure { |
310 | |
311 | /** |
312 | * @generated |
313 | */ |
314 | public InfrastructureRequiredRoleFigure() { |
315 | this.setLineWidth(1); |
316 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(20), |
317 | getMapMode().DPtoLP(20))); |
318 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
319 | getMapMode().DPtoLP(0))); |
320 | this.setLocation(new Point(getMapMode().DPtoLP(40), getMapMode() |
321 | .DPtoLP(40))); |
322 | } |
323 | |
324 | /** |
325 | * @generated |
326 | */ |
327 | private boolean myUseLocalCoordinates = false; |
328 | |
329 | /** |
330 | * @generated |
331 | */ |
332 | protected boolean useLocalCoordinates() { |
333 | return myUseLocalCoordinates; |
334 | } |
335 | |
336 | /** |
337 | * @generated |
338 | */ |
339 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
340 | myUseLocalCoordinates = useLocalCoordinates; |
341 | } |
342 | |
343 | } |
344 | |
345 | } |