1 | /* |
2 | * Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts; |
5 | |
6 | import org.eclipse.draw2d.Graphics; |
7 | import org.eclipse.draw2d.IFigure; |
8 | import org.eclipse.draw2d.RectangleFigure; |
9 | import org.eclipse.draw2d.StackLayout; |
10 | import org.eclipse.gef.EditPart; |
11 | import org.eclipse.gef.EditPolicy; |
12 | import org.eclipse.gef.Request; |
13 | import org.eclipse.gef.commands.Command; |
14 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
15 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
16 | import org.eclipse.gef.requests.CreateRequest; |
17 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
18 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
19 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
20 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
21 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel; |
22 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
23 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
24 | import org.eclipse.gmf.runtime.notation.View; |
25 | |
26 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.policies.ResourceContainerItemSemanticEditPolicy; |
27 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelVisualIDRegistry; |
28 | |
29 | /** |
30 | * @generated |
31 | */ |
32 | public class ResourceContainerEditPart extends ShapeNodeEditPart { |
33 | |
34 | /** |
35 | * @generated |
36 | */ |
37 | public static final int VISUAL_ID = 2002; |
38 | |
39 | /** |
40 | * @generated |
41 | */ |
42 | protected IFigure contentPane; |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | protected IFigure primaryShape; |
48 | |
49 | /** |
50 | * @generated |
51 | */ |
52 | public ResourceContainerEditPart(View view) { |
53 | super(view); |
54 | } |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | protected void createDefaultEditPolicies() { |
60 | super.createDefaultEditPolicies(); |
61 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
62 | new ResourceContainerItemSemanticEditPolicy()); |
63 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
64 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
65 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
66 | } |
67 | |
68 | /** |
69 | * @generated |
70 | */ |
71 | protected LayoutEditPolicy createLayoutEditPolicy() { |
72 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
73 | |
74 | protected EditPolicy createChildEditPolicy(EditPart child) { |
75 | EditPolicy result = child |
76 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
77 | if (result == null) { |
78 | result = new NonResizableEditPolicy(); |
79 | } |
80 | return result; |
81 | } |
82 | |
83 | protected Command getMoveChildrenCommand(Request request) { |
84 | return null; |
85 | } |
86 | |
87 | protected Command getCreateCommand(CreateRequest request) { |
88 | return null; |
89 | } |
90 | }; |
91 | return lep; |
92 | } |
93 | |
94 | /** |
95 | * @generated |
96 | */ |
97 | protected IFigure createNodeShape() { |
98 | ResourceContainerFigure figure = new ResourceContainerFigure(); |
99 | return primaryShape = figure; |
100 | } |
101 | |
102 | /** |
103 | * @generated |
104 | */ |
105 | public ResourceContainerFigure getPrimaryShape() { |
106 | return (ResourceContainerFigure) primaryShape; |
107 | } |
108 | |
109 | /** |
110 | * @generated |
111 | */ |
112 | protected boolean addFixedChild(EditPart childEditPart) { |
113 | if (childEditPart instanceof ResourceContainerEntityNameEditPart) { |
114 | ((ResourceContainerEntityNameEditPart) childEditPart) |
115 | .setLabel(getPrimaryShape() |
116 | .getFigureResContainerNameFigure()); |
117 | return true; |
118 | } |
119 | return false; |
120 | } |
121 | |
122 | /** |
123 | * @generated |
124 | */ |
125 | protected boolean removeFixedChild(EditPart childEditPart) { |
126 | |
127 | return false; |
128 | } |
129 | |
130 | /** |
131 | * @generated |
132 | */ |
133 | protected void addChildVisual(EditPart childEditPart, int index) { |
134 | if (addFixedChild(childEditPart)) { |
135 | return; |
136 | } |
137 | super.addChildVisual(childEditPart, -1); |
138 | } |
139 | |
140 | /** |
141 | * @generated |
142 | */ |
143 | protected void removeChildVisual(EditPart childEditPart) { |
144 | if (removeFixedChild(childEditPart)) { |
145 | return; |
146 | } |
147 | super.removeChildVisual(childEditPart); |
148 | } |
149 | |
150 | /** |
151 | * @generated |
152 | */ |
153 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
154 | |
155 | return super.getContentPaneFor(editPart); |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected NodeFigure createNodePlate() { |
162 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode() |
163 | .DPtoLP(40), getMapMode().DPtoLP(40)); |
164 | return result; |
165 | } |
166 | |
167 | /** |
168 | * Creates figure for this edit part. |
169 | * |
170 | * Body of this method does not depend on settings in generation model |
171 | * so you may safely remove <i>generated</i> tag and modify it. |
172 | * |
173 | * @generated |
174 | */ |
175 | protected NodeFigure createNodeFigure() { |
176 | NodeFigure figure = createNodePlate(); |
177 | figure.setLayoutManager(new StackLayout()); |
178 | IFigure shape = createNodeShape(); |
179 | figure.add(shape); |
180 | contentPane = setupContentPane(shape); |
181 | return figure; |
182 | } |
183 | |
184 | /** |
185 | * Default implementation treats passed figure as content pane. |
186 | * Respects layout one may have set for generated figure. |
187 | * @param nodeShape instance of generated figure class |
188 | * @generated |
189 | */ |
190 | protected IFigure setupContentPane(IFigure nodeShape) { |
191 | if (nodeShape.getLayoutManager() == null) { |
192 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
193 | layout.setSpacing(getMapMode().DPtoLP(5)); |
194 | nodeShape.setLayoutManager(layout); |
195 | } |
196 | return nodeShape; // use nodeShape itself as contentPane |
197 | } |
198 | |
199 | /** |
200 | * @generated |
201 | */ |
202 | public IFigure getContentPane() { |
203 | if (contentPane != null) { |
204 | return contentPane; |
205 | } |
206 | return super.getContentPane(); |
207 | } |
208 | |
209 | /** |
210 | * @generated |
211 | */ |
212 | public EditPart getPrimaryChildEditPart() { |
213 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
214 | .getType(ResourceContainerEntityNameEditPart.VISUAL_ID)); |
215 | } |
216 | |
217 | /** |
218 | * @generated |
219 | */ |
220 | public class ResourceContainerFigure extends RectangleFigure { |
221 | /** |
222 | * @generated |
223 | */ |
224 | public ResourceContainerFigure() { |
225 | this.setFill(true); |
226 | this.setFillXOR(false); |
227 | this.setOutline(true); |
228 | this.setOutlineXOR(false); |
229 | this.setLineWidth(1); |
230 | this.setLineStyle(Graphics.LINE_SOLID); |
231 | createContents(); |
232 | } |
233 | |
234 | /** |
235 | * @generated |
236 | */ |
237 | private void createContents() { |
238 | |
239 | WrapLabel resContainerNameFigure0 = new PcmWrapLabel(); |
240 | resContainerNameFigure0.setText("<...>"); |
241 | |
242 | this.add(resContainerNameFigure0); |
243 | setFigureResContainerNameFigure(resContainerNameFigure0); |
244 | |
245 | } |
246 | |
247 | /** |
248 | * @generated |
249 | */ |
250 | private WrapLabel fResContainerNameFigure; |
251 | |
252 | /** |
253 | * @generated |
254 | */ |
255 | public WrapLabel getFigureResContainerNameFigure() { |
256 | return fResContainerNameFigure; |
257 | } |
258 | |
259 | /** |
260 | * @generated |
261 | */ |
262 | private void setFigureResContainerNameFigure(WrapLabel fig) { |
263 | fResContainerNameFigure = fig; |
264 | } |
265 | |
266 | /** |
267 | * @generated |
268 | */ |
269 | private boolean myUseLocalCoordinates = false; |
270 | |
271 | /** |
272 | * @generated |
273 | */ |
274 | protected boolean useLocalCoordinates() { |
275 | return myUseLocalCoordinates; |
276 | } |
277 | |
278 | /** |
279 | * @generated |
280 | */ |
281 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
282 | myUseLocalCoordinates = useLocalCoordinates; |
283 | } |
284 | |
285 | } |
286 | |
287 | } |