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