| 1 | /* |
| 2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.seff.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.Shape; |
| 15 | import org.eclipse.draw2d.StackLayout; |
| 16 | import org.eclipse.draw2d.geometry.Dimension; |
| 17 | import org.eclipse.gef.EditPart; |
| 18 | import org.eclipse.gef.EditPolicy; |
| 19 | import org.eclipse.gef.Request; |
| 20 | import org.eclipse.gef.commands.Command; |
| 21 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
| 22 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
| 23 | import org.eclipse.gef.requests.CreateRequest; |
| 24 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
| 25 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
| 26 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
| 27 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
| 28 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
| 29 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
| 30 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
| 31 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
| 32 | import org.eclipse.gmf.runtime.notation.View; |
| 33 | import org.eclipse.swt.graphics.Color; |
| 34 | |
| 35 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.policies.RecoveryActionBehaviourItemSemanticEditPolicy; |
| 36 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
| 37 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | public class RecoveryActionBehaviourEditPart extends ShapeNodeEditPart { |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | public static final int VISUAL_ID = 3058; |
| 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 RecoveryActionBehaviourEditPart(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 RecoveryActionBehaviourItemSemanticEditPolicy()); |
| 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 | RecoveryActionBehaviourFigure figure = new RecoveryActionBehaviourFigure(); |
| 109 | return primaryShape = figure; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @generated |
| 114 | */ |
| 115 | public RecoveryActionBehaviourFigure getPrimaryShape() { |
| 116 | return (RecoveryActionBehaviourFigure) primaryShape; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @generated |
| 121 | */ |
| 122 | protected boolean addFixedChild(EditPart childEditPart) { |
| 123 | if (childEditPart instanceof RecoveryActionBehaviourEntityNameEditPart) { |
| 124 | ((RecoveryActionBehaviourEntityNameEditPart) childEditPart) |
| 125 | .setLabel(getPrimaryShape() |
| 126 | .getFigureRecoveryActionBehaviourNameLabel()); |
| 127 | return true; |
| 128 | } |
| 129 | if (childEditPart instanceof RecoveryActionBehaviourAlternativeBehaviourCompartmentEditPart) { |
| 130 | IFigure pane = getPrimaryShape() |
| 131 | .getFigureRecoveryActionBehaviourCompartment(); |
| 132 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
| 133 | pane |
| 134 | .add(((RecoveryActionBehaviourAlternativeBehaviourCompartmentEditPart) childEditPart) |
| 135 | .getFigure()); |
| 136 | return true; |
| 137 | } |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @generated |
| 143 | */ |
| 144 | protected boolean removeFixedChild(EditPart childEditPart) { |
| 145 | if (childEditPart instanceof RecoveryActionBehaviourEntityNameEditPart) { |
| 146 | return true; |
| 147 | } |
| 148 | if (childEditPart instanceof RecoveryActionBehaviourAlternativeBehaviourCompartmentEditPart) { |
| 149 | IFigure pane = getPrimaryShape() |
| 150 | .getFigureRecoveryActionBehaviourCompartment(); |
| 151 | setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
| 152 | pane |
| 153 | .remove(((RecoveryActionBehaviourAlternativeBehaviourCompartmentEditPart) childEditPart) |
| 154 | .getFigure()); |
| 155 | return true; |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @generated |
| 162 | */ |
| 163 | protected void addChildVisual(EditPart childEditPart, int index) { |
| 164 | if (addFixedChild(childEditPart)) { |
| 165 | return; |
| 166 | } |
| 167 | super.addChildVisual(childEditPart, -1); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @generated |
| 172 | */ |
| 173 | protected void removeChildVisual(EditPart childEditPart) { |
| 174 | if (removeFixedChild(childEditPart)) { |
| 175 | return; |
| 176 | } |
| 177 | super.removeChildVisual(childEditPart); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * @generated |
| 182 | */ |
| 183 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
| 184 | if (editPart instanceof RecoveryActionBehaviourAlternativeBehaviourCompartmentEditPart) { |
| 185 | return getPrimaryShape() |
| 186 | .getFigureRecoveryActionBehaviourCompartment(); |
| 187 | } |
| 188 | return getContentPane(); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @generated |
| 193 | */ |
| 194 | protected NodeFigure createNodePlate() { |
| 195 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
| 196 | return result; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Creates figure for this edit part. |
| 201 | * |
| 202 | * Body of this method does not depend on settings in generation model |
| 203 | * so you may safely remove <i>generated</i> tag and modify it. |
| 204 | * |
| 205 | * @generated |
| 206 | */ |
| 207 | protected NodeFigure createNodeFigure() { |
| 208 | NodeFigure figure = createNodePlate(); |
| 209 | figure.setLayoutManager(new StackLayout()); |
| 210 | IFigure shape = createNodeShape(); |
| 211 | figure.add(shape); |
| 212 | contentPane = setupContentPane(shape); |
| 213 | return figure; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Default implementation treats passed figure as content pane. |
| 218 | * Respects layout one may have set for generated figure. |
| 219 | * @param nodeShape instance of generated figure class |
| 220 | * @generated |
| 221 | */ |
| 222 | protected IFigure setupContentPane(IFigure nodeShape) { |
| 223 | if (nodeShape.getLayoutManager() == null) { |
| 224 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
| 225 | layout.setSpacing(5); |
| 226 | nodeShape.setLayoutManager(layout); |
| 227 | } |
| 228 | return nodeShape; // use nodeShape itself as contentPane |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @generated |
| 233 | */ |
| 234 | public IFigure getContentPane() { |
| 235 | if (contentPane != null) { |
| 236 | return contentPane; |
| 237 | } |
| 238 | return super.getContentPane(); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * @generated |
| 243 | */ |
| 244 | protected void setForegroundColor(Color color) { |
| 245 | if (primaryShape != null) { |
| 246 | primaryShape.setForegroundColor(color); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * @generated |
| 252 | */ |
| 253 | protected void setBackgroundColor(Color color) { |
| 254 | if (primaryShape != null) { |
| 255 | primaryShape.setBackgroundColor(color); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * @generated |
| 261 | */ |
| 262 | protected void setLineWidth(int width) { |
| 263 | if (primaryShape instanceof Shape) { |
| 264 | ((Shape) primaryShape).setLineWidth(width); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @generated |
| 270 | */ |
| 271 | protected void setLineType(int style) { |
| 272 | if (primaryShape instanceof Shape) { |
| 273 | ((Shape) primaryShape).setLineStyle(style); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @generated |
| 279 | */ |
| 280 | public EditPart getPrimaryChildEditPart() { |
| 281 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
| 282 | .getType(RecoveryActionBehaviourEntityNameEditPart.VISUAL_ID)); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * @generated |
| 287 | */ |
| 288 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
| 289 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 290 | types |
| 291 | .add(PalladioComponentModelElementTypes.RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004); |
| 292 | return types; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * @generated |
| 297 | */ |
| 298 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
| 299 | IGraphicalEditPart targetEditPart) { |
| 300 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 301 | if (targetEditPart instanceof de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.RecoveryActionBehaviourEditPart) { |
| 302 | types |
| 303 | .add(PalladioComponentModelElementTypes.RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004); |
| 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.RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004) { |
| 315 | types |
| 316 | .add(PalladioComponentModelElementTypes.RecoveryActionBehaviour_3058); |
| 317 | } |
| 318 | return types; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * @generated |
| 323 | */ |
| 324 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
| 325 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 326 | types |
| 327 | .add(PalladioComponentModelElementTypes.RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004); |
| 328 | return types; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * @generated |
| 333 | */ |
| 334 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
| 335 | IElementType relationshipType) { |
| 336 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 337 | if (relationshipType == PalladioComponentModelElementTypes.RecoveryActionBehaviourFailureHandlingAlternatives__RecoveryActionBehaviour_4004) { |
| 338 | types |
| 339 | .add(PalladioComponentModelElementTypes.RecoveryActionBehaviour_3058); |
| 340 | } |
| 341 | return types; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * @generated |
| 346 | */ |
| 347 | public class RecoveryActionBehaviourFigure extends RectangleFigure { |
| 348 | |
| 349 | /** |
| 350 | * @generated |
| 351 | */ |
| 352 | private WrappingLabel fFigureRecoveryActionBehaviourNameLabel; |
| 353 | /** |
| 354 | * @generated |
| 355 | */ |
| 356 | private RectangleFigure fFigureRecoveryActionBehaviourCompartment; |
| 357 | |
| 358 | /** |
| 359 | * @generated |
| 360 | */ |
| 361 | public RecoveryActionBehaviourFigure() { |
| 362 | |
| 363 | GridLayout layoutThis = new GridLayout(); |
| 364 | layoutThis.numColumns = 1; |
| 365 | layoutThis.makeColumnsEqualWidth = true; |
| 366 | layoutThis.horizontalSpacing = 0; |
| 367 | layoutThis.verticalSpacing = 0; |
| 368 | layoutThis.marginWidth = 0; |
| 369 | layoutThis.marginHeight = 0; |
| 370 | this.setLayoutManager(layoutThis); |
| 371 | |
| 372 | this.setLineWidth(1); |
| 373 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
| 374 | getMapMode().DPtoLP(0))); |
| 375 | createContents(); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * @generated |
| 380 | */ |
| 381 | private void createContents() { |
| 382 | |
| 383 | WrappingLabel recoveryActionBehaviourStereotype0 = new WrappingLabel(); |
| 384 | recoveryActionBehaviourStereotype0 |
| 385 | .setText("<<RecoveryActionBehaviour>>"); |
| 386 | recoveryActionBehaviourStereotype0.setBorder(new MarginBorder( |
| 387 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
| 388 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
| 389 | |
| 390 | GridData constraintRecoveryActionBehaviourStereotype0 = new GridData(); |
| 391 | constraintRecoveryActionBehaviourStereotype0.verticalAlignment = GridData.CENTER; |
| 392 | constraintRecoveryActionBehaviourStereotype0.horizontalAlignment = GridData.CENTER; |
| 393 | constraintRecoveryActionBehaviourStereotype0.horizontalIndent = 0; |
| 394 | constraintRecoveryActionBehaviourStereotype0.horizontalSpan = 1; |
| 395 | constraintRecoveryActionBehaviourStereotype0.verticalSpan = 1; |
| 396 | constraintRecoveryActionBehaviourStereotype0.grabExcessHorizontalSpace = false; |
| 397 | constraintRecoveryActionBehaviourStereotype0.grabExcessVerticalSpace = false; |
| 398 | this.add(recoveryActionBehaviourStereotype0, |
| 399 | constraintRecoveryActionBehaviourStereotype0); |
| 400 | |
| 401 | fFigureRecoveryActionBehaviourNameLabel = new WrappingLabel(); |
| 402 | fFigureRecoveryActionBehaviourNameLabel.setText(""); |
| 403 | fFigureRecoveryActionBehaviourNameLabel.setBorder(new MarginBorder( |
| 404 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
| 405 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
| 406 | |
| 407 | GridData constraintFFigureRecoveryActionBehaviourNameLabel = new GridData(); |
| 408 | constraintFFigureRecoveryActionBehaviourNameLabel.verticalAlignment = GridData.CENTER; |
| 409 | constraintFFigureRecoveryActionBehaviourNameLabel.horizontalAlignment = GridData.CENTER; |
| 410 | constraintFFigureRecoveryActionBehaviourNameLabel.horizontalIndent = 0; |
| 411 | constraintFFigureRecoveryActionBehaviourNameLabel.horizontalSpan = 1; |
| 412 | constraintFFigureRecoveryActionBehaviourNameLabel.verticalSpan = 1; |
| 413 | constraintFFigureRecoveryActionBehaviourNameLabel.grabExcessHorizontalSpace = false; |
| 414 | constraintFFigureRecoveryActionBehaviourNameLabel.grabExcessVerticalSpace = false; |
| 415 | this.add(fFigureRecoveryActionBehaviourNameLabel, |
| 416 | constraintFFigureRecoveryActionBehaviourNameLabel); |
| 417 | |
| 418 | fFigureRecoveryActionBehaviourCompartment = new RectangleFigure(); |
| 419 | fFigureRecoveryActionBehaviourCompartment.setFill(false); |
| 420 | fFigureRecoveryActionBehaviourCompartment.setOutline(false); |
| 421 | fFigureRecoveryActionBehaviourCompartment.setLineWidth(1); |
| 422 | fFigureRecoveryActionBehaviourCompartment |
| 423 | .setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
| 424 | getMapMode().DPtoLP(0))); |
| 425 | |
| 426 | GridData constraintFFigureRecoveryActionBehaviourCompartment = new GridData(); |
| 427 | constraintFFigureRecoveryActionBehaviourCompartment.verticalAlignment = GridData.FILL; |
| 428 | constraintFFigureRecoveryActionBehaviourCompartment.horizontalAlignment = GridData.FILL; |
| 429 | constraintFFigureRecoveryActionBehaviourCompartment.horizontalIndent = 0; |
| 430 | constraintFFigureRecoveryActionBehaviourCompartment.horizontalSpan = 1; |
| 431 | constraintFFigureRecoveryActionBehaviourCompartment.verticalSpan = 1; |
| 432 | constraintFFigureRecoveryActionBehaviourCompartment.grabExcessHorizontalSpace = true; |
| 433 | constraintFFigureRecoveryActionBehaviourCompartment.grabExcessVerticalSpace = true; |
| 434 | this.add(fFigureRecoveryActionBehaviourCompartment, |
| 435 | constraintFFigureRecoveryActionBehaviourCompartment); |
| 436 | |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * @generated |
| 441 | */ |
| 442 | private boolean myUseLocalCoordinates = false; |
| 443 | |
| 444 | /** |
| 445 | * @generated |
| 446 | */ |
| 447 | protected boolean useLocalCoordinates() { |
| 448 | return myUseLocalCoordinates; |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * @generated |
| 453 | */ |
| 454 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| 455 | myUseLocalCoordinates = useLocalCoordinates; |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * @generated |
| 460 | */ |
| 461 | public WrappingLabel getFigureRecoveryActionBehaviourNameLabel() { |
| 462 | return fFigureRecoveryActionBehaviourNameLabel; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * @generated |
| 467 | */ |
| 468 | public RectangleFigure getFigureRecoveryActionBehaviourCompartment() { |
| 469 | return fFigureRecoveryActionBehaviourCompartment; |
| 470 | } |
| 471 | |
| 472 | } |
| 473 | |
| 474 | } |