| 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.AllocationContextItemSemanticEditPolicy; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelVisualIDRegistry; |
| 28 | |
| 29 | /** |
| 30 | * @generated |
| 31 | */ |
| 32 | public class AllocationContextEditPart extends ShapeNodeEditPart { |
| 33 | |
| 34 | /** |
| 35 | * @generated |
| 36 | */ |
| 37 | public static final int VISUAL_ID = 3001; |
| 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 AllocationContextEditPart(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 AllocationContextItemSemanticEditPolicy()); |
| 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 | AllocationContextFigure figure = new AllocationContextFigure(); |
| 99 | return primaryShape = figure; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @generated |
| 104 | */ |
| 105 | public AllocationContextFigure getPrimaryShape() { |
| 106 | return (AllocationContextFigure) primaryShape; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @generated |
| 111 | */ |
| 112 | protected boolean addFixedChild(EditPart childEditPart) { |
| 113 | if (childEditPart instanceof AllocationContextEntityNameEditPart) { |
| 114 | ((AllocationContextEntityNameEditPart) childEditPart) |
| 115 | .setLabel(getPrimaryShape().getFigureAllocationNameFigure()); |
| 116 | return true; |
| 117 | } |
| 118 | if (childEditPart instanceof AllocationComponentLabelEditPart) { |
| 119 | ((AllocationComponentLabelEditPart) childEditPart) |
| 120 | .setLabel(getPrimaryShape() |
| 121 | .getFigureAllocationComponentLabelFigure()); |
| 122 | return true; |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @generated |
| 129 | */ |
| 130 | protected boolean removeFixedChild(EditPart childEditPart) { |
| 131 | |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @generated |
| 137 | */ |
| 138 | protected void addChildVisual(EditPart childEditPart, int index) { |
| 139 | if (addFixedChild(childEditPart)) { |
| 140 | return; |
| 141 | } |
| 142 | super.addChildVisual(childEditPart, -1); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @generated |
| 147 | */ |
| 148 | protected void removeChildVisual(EditPart childEditPart) { |
| 149 | if (removeFixedChild(childEditPart)) { |
| 150 | return; |
| 151 | } |
| 152 | super.removeChildVisual(childEditPart); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @generated |
| 157 | */ |
| 158 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
| 159 | |
| 160 | return super.getContentPaneFor(editPart); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @generated |
| 165 | */ |
| 166 | protected NodeFigure createNodePlate() { |
| 167 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode() |
| 168 | .DPtoLP(40), getMapMode().DPtoLP(40)); |
| 169 | return result; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Creates figure for this edit part. |
| 174 | * |
| 175 | * Body of this method does not depend on settings in generation model |
| 176 | * so you may safely remove <i>generated</i> tag and modify it. |
| 177 | * |
| 178 | * @generated |
| 179 | */ |
| 180 | protected NodeFigure createNodeFigure() { |
| 181 | NodeFigure figure = createNodePlate(); |
| 182 | figure.setLayoutManager(new StackLayout()); |
| 183 | IFigure shape = createNodeShape(); |
| 184 | figure.add(shape); |
| 185 | contentPane = setupContentPane(shape); |
| 186 | return figure; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Default implementation treats passed figure as content pane. |
| 191 | * Respects layout one may have set for generated figure. |
| 192 | * @param nodeShape instance of generated figure class |
| 193 | * @generated |
| 194 | */ |
| 195 | protected IFigure setupContentPane(IFigure nodeShape) { |
| 196 | if (nodeShape.getLayoutManager() == null) { |
| 197 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
| 198 | layout.setSpacing(getMapMode().DPtoLP(5)); |
| 199 | nodeShape.setLayoutManager(layout); |
| 200 | } |
| 201 | return nodeShape; // use nodeShape itself as contentPane |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @generated |
| 206 | */ |
| 207 | public IFigure getContentPane() { |
| 208 | if (contentPane != null) { |
| 209 | return contentPane; |
| 210 | } |
| 211 | return super.getContentPane(); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @generated |
| 216 | */ |
| 217 | public EditPart getPrimaryChildEditPart() { |
| 218 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
| 219 | .getType(AllocationContextEntityNameEditPart.VISUAL_ID)); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * @generated |
| 224 | */ |
| 225 | public class AllocationContextFigure extends RectangleFigure { |
| 226 | /** |
| 227 | * @generated |
| 228 | */ |
| 229 | public AllocationContextFigure() { |
| 230 | this.setFill(true); |
| 231 | this.setFillXOR(false); |
| 232 | this.setOutline(true); |
| 233 | this.setOutlineXOR(false); |
| 234 | this.setLineWidth(1); |
| 235 | this.setLineStyle(Graphics.LINE_SOLID); |
| 236 | createContents(); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @generated |
| 241 | */ |
| 242 | private void createContents() { |
| 243 | |
| 244 | WrapLabel allocationNameFigure0 = new PcmWrapLabel(); |
| 245 | allocationNameFigure0.setText("<...>"); |
| 246 | |
| 247 | this.add(allocationNameFigure0); |
| 248 | setFigureAllocationNameFigure(allocationNameFigure0); |
| 249 | |
| 250 | WrapLabel allocationComponentLabelFigure0 = new PcmWrapLabel(); |
| 251 | allocationComponentLabelFigure0.setText(""); |
| 252 | |
| 253 | this.add(allocationComponentLabelFigure0); |
| 254 | setFigureAllocationComponentLabelFigure(allocationComponentLabelFigure0); |
| 255 | |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * @generated |
| 260 | */ |
| 261 | private WrapLabel fAllocationNameFigure; |
| 262 | |
| 263 | /** |
| 264 | * @generated |
| 265 | */ |
| 266 | public WrapLabel getFigureAllocationNameFigure() { |
| 267 | return fAllocationNameFigure; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * @generated |
| 272 | */ |
| 273 | private void setFigureAllocationNameFigure(WrapLabel fig) { |
| 274 | fAllocationNameFigure = fig; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @generated |
| 279 | */ |
| 280 | private WrapLabel fAllocationComponentLabelFigure; |
| 281 | |
| 282 | /** |
| 283 | * @generated |
| 284 | */ |
| 285 | public WrapLabel getFigureAllocationComponentLabelFigure() { |
| 286 | return fAllocationComponentLabelFigure; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * @generated |
| 291 | */ |
| 292 | private void setFigureAllocationComponentLabelFigure(WrapLabel fig) { |
| 293 | fAllocationComponentLabelFigure = fig; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * @generated |
| 298 | */ |
| 299 | private boolean myUseLocalCoordinates = false; |
| 300 | |
| 301 | /** |
| 302 | * @generated |
| 303 | */ |
| 304 | protected boolean useLocalCoordinates() { |
| 305 | return myUseLocalCoordinates; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * @generated |
| 310 | */ |
| 311 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| 312 | myUseLocalCoordinates = useLocalCoordinates; |
| 313 | } |
| 314 | |
| 315 | } |
| 316 | |
| 317 | } |