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