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