| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.usage.edit.parts; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.List; |
| 8 | |
| 9 | import org.eclipse.draw2d.GridData; |
| 10 | import org.eclipse.draw2d.GridLayout; |
| 11 | import org.eclipse.draw2d.IFigure; |
| 12 | import org.eclipse.draw2d.MarginBorder; |
| 13 | import org.eclipse.draw2d.RectangleFigure; |
| 14 | import org.eclipse.draw2d.RoundedRectangle; |
| 15 | import org.eclipse.draw2d.Shape; |
| 16 | import org.eclipse.draw2d.StackLayout; |
| 17 | import org.eclipse.draw2d.geometry.Dimension; |
| 18 | import org.eclipse.gef.EditPart; |
| 19 | import org.eclipse.gef.EditPolicy; |
| 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.requests.CreateRequest; |
| 25 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
| 26 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
| 27 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
| 28 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
| 29 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
| 30 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
| 31 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
| 32 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
| 33 | import org.eclipse.gmf.runtime.notation.View; |
| 34 | import org.eclipse.swt.graphics.Color; |
| 35 | |
| 36 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.BranchItemSemanticEditPolicy; |
| 37 | import de.uka.ipd.sdq.pcm.gmf.usage.providers.PalladioComponentModelElementTypes; |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | public class BranchEditPart extends ShapeNodeEditPart { |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | public static final int VISUAL_ID = 3008; |
| 48 | |
| 49 | /** |
| 50 | * @generated |
| 51 | */ |
| 52 | protected IFigure contentPane; |
| 53 | |
| 54 | /** |
| 55 | * @generated |
| 56 | */ |
| 57 | protected IFigure primaryShape; |
| 58 | |
| 59 | /** |
| 60 | * @generated |
| 61 | */ |
| 62 | public BranchEditPart(View view) { |
| 63 | super(view); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @generated |
| 68 | */ |
| 69 | protected void createDefaultEditPolicies() { |
| 70 | super.createDefaultEditPolicies(); |
| 71 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
| 72 | new BranchItemSemanticEditPolicy()); |
| 73 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
| 74 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
| 75 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @generated |
| 80 | */ |
| 81 | protected LayoutEditPolicy createLayoutEditPolicy() { |
| 82 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
| 83 | |
| 84 | protected EditPolicy createChildEditPolicy(EditPart child) { |
| 85 | EditPolicy result = child |
| 86 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
| 87 | if (result == null) { |
| 88 | result = new NonResizableEditPolicy(); |
| 89 | } |
| 90 | return result; |
| 91 | } |
| 92 | |
| 93 | protected Command getMoveChildrenCommand(Request request) { |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | protected Command getCreateCommand(CreateRequest request) { |
| 98 | return null; |
| 99 | } |
| 100 | }; |
| 101 | return lep; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @generated |
| 106 | */ |
| 107 | protected IFigure createNodeShape() { |
| 108 | UsageBranchFigure figure = new UsageBranchFigure(); |
| 109 | return primaryShape = figure; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @generated |
| 114 | */ |
| 115 | public UsageBranchFigure getPrimaryShape() { |
| 116 | return (UsageBranchFigure) primaryShape; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @generated |
| 121 | */ |
| 122 | protected boolean addFixedChild(EditPart childEditPart) { |
| 123 | if (childEditPart instanceof BranchUsageBranchTransitionsCompartmentEditPart) { |
| 124 | IFigure pane = getPrimaryShape().getFigureBranchCompartment(); |
| 125 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
| 126 | pane |
| 127 | .add(((BranchUsageBranchTransitionsCompartmentEditPart) childEditPart) |
| 128 | .getFigure()); |
| 129 | return true; |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @generated |
| 136 | */ |
| 137 | protected boolean removeFixedChild(EditPart childEditPart) { |
| 138 | if (childEditPart instanceof BranchUsageBranchTransitionsCompartmentEditPart) { |
| 139 | IFigure pane = getPrimaryShape().getFigureBranchCompartment(); |
| 140 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
| 141 | pane |
| 142 | .remove(((BranchUsageBranchTransitionsCompartmentEditPart) childEditPart) |
| 143 | .getFigure()); |
| 144 | return true; |
| 145 | } |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * @generated |
| 151 | */ |
| 152 | protected void addChildVisual(EditPart childEditPart, int index) { |
| 153 | if (addFixedChild(childEditPart)) { |
| 154 | return; |
| 155 | } |
| 156 | super.addChildVisual(childEditPart, -1); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @generated |
| 161 | */ |
| 162 | protected void removeChildVisual(EditPart childEditPart) { |
| 163 | if (removeFixedChild(childEditPart)) { |
| 164 | return; |
| 165 | } |
| 166 | super.removeChildVisual(childEditPart); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @generated |
| 171 | */ |
| 172 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
| 173 | if (editPart instanceof BranchUsageBranchTransitionsCompartmentEditPart) { |
| 174 | return getPrimaryShape().getFigureBranchCompartment(); |
| 175 | } |
| 176 | return getContentPane(); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @generated |
| 181 | */ |
| 182 | protected NodeFigure createNodePlate() { |
| 183 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
| 184 | return result; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Creates figure for this edit part. |
| 189 | * |
| 190 | * Body of this method does not depend on settings in generation model |
| 191 | * so you may safely remove <i>generated</i> tag and modify it. |
| 192 | * |
| 193 | * @generated |
| 194 | */ |
| 195 | protected NodeFigure createNodeFigure() { |
| 196 | NodeFigure figure = createNodePlate(); |
| 197 | figure.setLayoutManager(new StackLayout()); |
| 198 | IFigure shape = createNodeShape(); |
| 199 | figure.add(shape); |
| 200 | contentPane = setupContentPane(shape); |
| 201 | return figure; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Default implementation treats passed figure as content pane. |
| 206 | * Respects layout one may have set for generated figure. |
| 207 | * @param nodeShape instance of generated figure class |
| 208 | * @generated |
| 209 | */ |
| 210 | protected IFigure setupContentPane(IFigure nodeShape) { |
| 211 | if (nodeShape.getLayoutManager() == null) { |
| 212 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
| 213 | layout.setSpacing(5); |
| 214 | nodeShape.setLayoutManager(layout); |
| 215 | } |
| 216 | return nodeShape; // use nodeShape itself as contentPane |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @generated |
| 221 | */ |
| 222 | public IFigure getContentPane() { |
| 223 | if (contentPane != null) { |
| 224 | return contentPane; |
| 225 | } |
| 226 | return super.getContentPane(); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * @generated |
| 231 | */ |
| 232 | protected void setForegroundColor(Color color) { |
| 233 | if (primaryShape != null) { |
| 234 | primaryShape.setForegroundColor(color); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * @generated |
| 240 | */ |
| 241 | protected void setBackgroundColor(Color color) { |
| 242 | if (primaryShape != null) { |
| 243 | primaryShape.setBackgroundColor(color); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @generated |
| 249 | */ |
| 250 | protected void setLineWidth(int width) { |
| 251 | if (primaryShape instanceof Shape) { |
| 252 | ((Shape) primaryShape).setLineWidth(width); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @generated |
| 258 | */ |
| 259 | protected void setLineType(int style) { |
| 260 | if (primaryShape instanceof Shape) { |
| 261 | ((Shape) primaryShape).setLineStyle(style); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * @generated |
| 267 | */ |
| 268 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
| 269 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 270 | types |
| 271 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 272 | return types; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * @generated |
| 277 | */ |
| 278 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
| 279 | IGraphicalEditPart targetEditPart) { |
| 280 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 281 | if (targetEditPart instanceof StartEditPart) { |
| 282 | types |
| 283 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 284 | } |
| 285 | if (targetEditPart instanceof StopEditPart) { |
| 286 | types |
| 287 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 288 | } |
| 289 | if (targetEditPart instanceof EntryLevelSystemCallEditPart) { |
| 290 | types |
| 291 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 292 | } |
| 293 | if (targetEditPart instanceof LoopEditPart) { |
| 294 | types |
| 295 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 296 | } |
| 297 | if (targetEditPart instanceof de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.BranchEditPart) { |
| 298 | types |
| 299 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 300 | } |
| 301 | if (targetEditPart instanceof DelayEditPart) { |
| 302 | types |
| 303 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 304 | } |
| 305 | return types; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * @generated |
| 310 | */ |
| 311 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
| 312 | IElementType relationshipType) { |
| 313 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 314 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 315 | types.add(PalladioComponentModelElementTypes.Start_3001); |
| 316 | } |
| 317 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 318 | types.add(PalladioComponentModelElementTypes.Stop_3002); |
| 319 | } |
| 320 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 321 | types |
| 322 | .add(PalladioComponentModelElementTypes.EntryLevelSystemCall_3003); |
| 323 | } |
| 324 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 325 | types.add(PalladioComponentModelElementTypes.Loop_3005); |
| 326 | } |
| 327 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 328 | types.add(PalladioComponentModelElementTypes.Branch_3008); |
| 329 | } |
| 330 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 331 | types.add(PalladioComponentModelElementTypes.Delay_3017); |
| 332 | } |
| 333 | return types; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * @generated |
| 338 | */ |
| 339 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
| 340 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 341 | types |
| 342 | .add(PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002); |
| 343 | return types; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * @generated |
| 348 | */ |
| 349 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
| 350 | IElementType relationshipType) { |
| 351 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 352 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 353 | types.add(PalladioComponentModelElementTypes.Start_3001); |
| 354 | } |
| 355 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 356 | types.add(PalladioComponentModelElementTypes.Stop_3002); |
| 357 | } |
| 358 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 359 | types |
| 360 | .add(PalladioComponentModelElementTypes.EntryLevelSystemCall_3003); |
| 361 | } |
| 362 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 363 | types.add(PalladioComponentModelElementTypes.Loop_3005); |
| 364 | } |
| 365 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 366 | types.add(PalladioComponentModelElementTypes.Branch_3008); |
| 367 | } |
| 368 | if (relationshipType == PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002) { |
| 369 | types.add(PalladioComponentModelElementTypes.Delay_3017); |
| 370 | } |
| 371 | return types; |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * @generated |
| 376 | */ |
| 377 | public class UsageBranchFigure extends RoundedRectangle { |
| 378 | /** |
| 379 | * @generated |
| 380 | */ |
| 381 | private WrappingLabel fFigureUsageBranchStereotypeLabelFigure; |
| 382 | |
| 383 | /** |
| 384 | * @generated |
| 385 | */ |
| 386 | private RectangleFigure fFigureBranchCompartment; |
| 387 | |
| 388 | /** |
| 389 | * @generated |
| 390 | */ |
| 391 | public UsageBranchFigure() { |
| 392 | |
| 393 | GridLayout layoutThis = new GridLayout(); |
| 394 | layoutThis.numColumns = 1; |
| 395 | layoutThis.makeColumnsEqualWidth = true; |
| 396 | layoutThis.horizontalSpacing = 0; |
| 397 | layoutThis.verticalSpacing = 0; |
| 398 | layoutThis.marginWidth = 0; |
| 399 | layoutThis.marginHeight = 0; |
| 400 | this.setLayoutManager(layoutThis); |
| 401 | |
| 402 | this.setCornerDimensions(new Dimension(getMapMode().DPtoLP(8), |
| 403 | getMapMode().DPtoLP(8))); |
| 404 | this.setLineWidth(1); |
| 405 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
| 406 | getMapMode().DPtoLP(0))); |
| 407 | createContents(); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * @generated |
| 412 | */ |
| 413 | private void createContents() { |
| 414 | |
| 415 | fFigureUsageBranchStereotypeLabelFigure = new WrappingLabel(); |
| 416 | fFigureUsageBranchStereotypeLabelFigure.setText("<<Branch>>"); |
| 417 | fFigureUsageBranchStereotypeLabelFigure.setBorder(new MarginBorder( |
| 418 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
| 419 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
| 420 | |
| 421 | GridData constraintFFigureUsageBranchStereotypeLabelFigure = new GridData(); |
| 422 | constraintFFigureUsageBranchStereotypeLabelFigure.verticalAlignment = GridData.BEGINNING; |
| 423 | constraintFFigureUsageBranchStereotypeLabelFigure.horizontalAlignment = GridData.CENTER; |
| 424 | constraintFFigureUsageBranchStereotypeLabelFigure.horizontalIndent = 0; |
| 425 | constraintFFigureUsageBranchStereotypeLabelFigure.horizontalSpan = 1; |
| 426 | constraintFFigureUsageBranchStereotypeLabelFigure.verticalSpan = 1; |
| 427 | constraintFFigureUsageBranchStereotypeLabelFigure.grabExcessHorizontalSpace = true; |
| 428 | constraintFFigureUsageBranchStereotypeLabelFigure.grabExcessVerticalSpace = false; |
| 429 | this.add(fFigureUsageBranchStereotypeLabelFigure, |
| 430 | constraintFFigureUsageBranchStereotypeLabelFigure); |
| 431 | |
| 432 | fFigureBranchCompartment = new RectangleFigure(); |
| 433 | fFigureBranchCompartment.setFill(false); |
| 434 | fFigureBranchCompartment.setOutline(false); |
| 435 | fFigureBranchCompartment.setLineWidth(1); |
| 436 | fFigureBranchCompartment.setMinimumSize(new Dimension(getMapMode() |
| 437 | .DPtoLP(0), getMapMode().DPtoLP(0))); |
| 438 | |
| 439 | GridData constraintFFigureBranchCompartment = new GridData(); |
| 440 | constraintFFigureBranchCompartment.verticalAlignment = GridData.FILL; |
| 441 | constraintFFigureBranchCompartment.horizontalAlignment = GridData.FILL; |
| 442 | constraintFFigureBranchCompartment.horizontalIndent = 0; |
| 443 | constraintFFigureBranchCompartment.horizontalSpan = 1; |
| 444 | constraintFFigureBranchCompartment.verticalSpan = 1; |
| 445 | constraintFFigureBranchCompartment.grabExcessHorizontalSpace = true; |
| 446 | constraintFFigureBranchCompartment.grabExcessVerticalSpace = true; |
| 447 | this.add(fFigureBranchCompartment, |
| 448 | constraintFFigureBranchCompartment); |
| 449 | |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * @generated |
| 454 | */ |
| 455 | public WrappingLabel getFigureUsageBranchStereotypeLabelFigure() { |
| 456 | return fFigureUsageBranchStereotypeLabelFigure; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * @generated |
| 461 | */ |
| 462 | public RectangleFigure getFigureBranchCompartment() { |
| 463 | return fFigureBranchCompartment; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * @generated |
| 468 | */ |
| 469 | private boolean myUseLocalCoordinates = false; |
| 470 | |
| 471 | /** |
| 472 | * @generated |
| 473 | */ |
| 474 | protected boolean useLocalCoordinates() { |
| 475 | return myUseLocalCoordinates; |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * @generated |
| 480 | */ |
| 481 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| 482 | myUseLocalCoordinates = useLocalCoordinates; |
| 483 | } |
| 484 | |
| 485 | } |
| 486 | |
| 487 | } |