| 1 | /* |
| 2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.repository.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.repository.edit.policies.SubSystemItemSemanticEditPolicy; |
| 36 | import de.uka.ipd.sdq.pcm.gmf.repository.part.PalladioComponentModelVisualIDRegistry; |
| 37 | import de.uka.ipd.sdq.pcm.gmf.repository.providers.PalladioComponentModelElementTypes; |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | public class SubSystemEditPart extends ShapeNodeEditPart { |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | public static final int VISUAL_ID = 2106; |
| 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 SubSystemEditPart(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 SubSystemItemSemanticEditPolicy()); |
| 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 | SubSystemFigure figure = new SubSystemFigure(); |
| 109 | return primaryShape = figure; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @generated |
| 114 | */ |
| 115 | public SubSystemFigure getPrimaryShape() { |
| 116 | return (SubSystemFigure) primaryShape; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @generated |
| 121 | */ |
| 122 | protected boolean addFixedChild(EditPart childEditPart) { |
| 123 | if (childEditPart instanceof SubSystemEntityNameEditPart) { |
| 124 | ((SubSystemEntityNameEditPart) childEditPart) |
| 125 | .setLabel(getPrimaryShape() |
| 126 | .getFigureSubSystem_Name_LabelFigure()); |
| 127 | return true; |
| 128 | } |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @generated |
| 134 | */ |
| 135 | protected boolean removeFixedChild(EditPart childEditPart) { |
| 136 | if (childEditPart instanceof SubSystemEntityNameEditPart) { |
| 137 | return true; |
| 138 | } |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @generated |
| 144 | */ |
| 145 | protected void addChildVisual(EditPart childEditPart, int index) { |
| 146 | if (addFixedChild(childEditPart)) { |
| 147 | return; |
| 148 | } |
| 149 | super.addChildVisual(childEditPart, -1); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * @generated |
| 154 | */ |
| 155 | protected void removeChildVisual(EditPart childEditPart) { |
| 156 | if (removeFixedChild(childEditPart)) { |
| 157 | return; |
| 158 | } |
| 159 | super.removeChildVisual(childEditPart); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @generated |
| 164 | */ |
| 165 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
| 166 | return getContentPane(); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @generated |
| 171 | */ |
| 172 | protected NodeFigure createNodePlate() { |
| 173 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
| 174 | return result; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Creates figure for this edit part. |
| 179 | * |
| 180 | * Body of this method does not depend on settings in generation model |
| 181 | * so you may safely remove <i>generated</i> tag and modify it. |
| 182 | * |
| 183 | * @generated |
| 184 | */ |
| 185 | protected NodeFigure createNodeFigure() { |
| 186 | NodeFigure figure = createNodePlate(); |
| 187 | figure.setLayoutManager(new StackLayout()); |
| 188 | IFigure shape = createNodeShape(); |
| 189 | figure.add(shape); |
| 190 | contentPane = setupContentPane(shape); |
| 191 | return figure; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Default implementation treats passed figure as content pane. |
| 196 | * Respects layout one may have set for generated figure. |
| 197 | * @param nodeShape instance of generated figure class |
| 198 | * @generated |
| 199 | */ |
| 200 | protected IFigure setupContentPane(IFigure nodeShape) { |
| 201 | if (nodeShape.getLayoutManager() == null) { |
| 202 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
| 203 | layout.setSpacing(5); |
| 204 | nodeShape.setLayoutManager(layout); |
| 205 | } |
| 206 | return nodeShape; // use nodeShape itself as contentPane |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * @generated |
| 211 | */ |
| 212 | public IFigure getContentPane() { |
| 213 | if (contentPane != null) { |
| 214 | return contentPane; |
| 215 | } |
| 216 | return super.getContentPane(); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @generated |
| 221 | */ |
| 222 | protected void setForegroundColor(Color color) { |
| 223 | if (primaryShape != null) { |
| 224 | primaryShape.setForegroundColor(color); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * @generated |
| 230 | */ |
| 231 | protected void setBackgroundColor(Color color) { |
| 232 | if (primaryShape != null) { |
| 233 | primaryShape.setBackgroundColor(color); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * @generated |
| 239 | */ |
| 240 | protected void setLineWidth(int width) { |
| 241 | if (primaryShape instanceof Shape) { |
| 242 | ((Shape) primaryShape).setLineWidth(width); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * @generated |
| 248 | */ |
| 249 | protected void setLineType(int style) { |
| 250 | if (primaryShape instanceof Shape) { |
| 251 | ((Shape) primaryShape).setLineStyle(style); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @generated |
| 257 | */ |
| 258 | public EditPart getPrimaryChildEditPart() { |
| 259 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
| 260 | .getType(SubSystemEntityNameEditPart.VISUAL_ID)); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * @generated |
| 265 | */ |
| 266 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
| 267 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 268 | types |
| 269 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_4105); |
| 270 | types |
| 271 | .add(PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111); |
| 272 | types |
| 273 | .add(PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112); |
| 274 | types.add(PalladioComponentModelElementTypes.SinkRole_4109); |
| 275 | types |
| 276 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_4106); |
| 277 | types.add(PalladioComponentModelElementTypes.SourceRole_4110); |
| 278 | return types; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * @generated |
| 283 | */ |
| 284 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
| 285 | IGraphicalEditPart targetEditPart) { |
| 286 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 287 | if (targetEditPart instanceof OperationInterfaceEditPart) { |
| 288 | types |
| 289 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_4105); |
| 290 | } |
| 291 | if (targetEditPart instanceof InfrastructureInterfaceEditPart) { |
| 292 | types |
| 293 | .add(PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111); |
| 294 | } |
| 295 | if (targetEditPart instanceof InfrastructureInterfaceEditPart) { |
| 296 | types |
| 297 | .add(PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112); |
| 298 | } |
| 299 | if (targetEditPart instanceof EventGroupEditPart) { |
| 300 | types.add(PalladioComponentModelElementTypes.SinkRole_4109); |
| 301 | } |
| 302 | if (targetEditPart instanceof OperationInterfaceEditPart) { |
| 303 | types |
| 304 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_4106); |
| 305 | } |
| 306 | if (targetEditPart instanceof EventGroupEditPart) { |
| 307 | types.add(PalladioComponentModelElementTypes.SourceRole_4110); |
| 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.OperationProvidedRole_4105) { |
| 319 | types |
| 320 | .add(PalladioComponentModelElementTypes.OperationInterface_2107); |
| 321 | } |
| 322 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureProvidedRole_4111) { |
| 323 | types |
| 324 | .add(PalladioComponentModelElementTypes.InfrastructureInterface_2109); |
| 325 | } |
| 326 | if (relationshipType == PalladioComponentModelElementTypes.InfrastructureRequiredRole_4112) { |
| 327 | types |
| 328 | .add(PalladioComponentModelElementTypes.InfrastructureInterface_2109); |
| 329 | } |
| 330 | if (relationshipType == PalladioComponentModelElementTypes.SinkRole_4109) { |
| 331 | types.add(PalladioComponentModelElementTypes.EventGroup_2108); |
| 332 | } |
| 333 | if (relationshipType == PalladioComponentModelElementTypes.OperationRequiredRole_4106) { |
| 334 | types |
| 335 | .add(PalladioComponentModelElementTypes.OperationInterface_2107); |
| 336 | } |
| 337 | if (relationshipType == PalladioComponentModelElementTypes.SourceRole_4110) { |
| 338 | types.add(PalladioComponentModelElementTypes.EventGroup_2108); |
| 339 | } |
| 340 | return types; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @generated |
| 345 | */ |
| 346 | public class SubSystemFigure extends RectangleFigure { |
| 347 | |
| 348 | /** |
| 349 | * @generated |
| 350 | */ |
| 351 | private WrappingLabel fFigureSubSystem_Name_LabelFigure; |
| 352 | |
| 353 | /** |
| 354 | * @generated |
| 355 | */ |
| 356 | public SubSystemFigure() { |
| 357 | |
| 358 | GridLayout layoutThis = new GridLayout(); |
| 359 | layoutThis.numColumns = 1; |
| 360 | layoutThis.makeColumnsEqualWidth = true; |
| 361 | layoutThis.horizontalSpacing = 0; |
| 362 | layoutThis.verticalSpacing = 0; |
| 363 | layoutThis.marginWidth = 0; |
| 364 | layoutThis.marginHeight = 0; |
| 365 | this.setLayoutManager(layoutThis); |
| 366 | |
| 367 | this.setLineWidth(1); |
| 368 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
| 369 | getMapMode().DPtoLP(0))); |
| 370 | createContents(); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * @generated |
| 375 | */ |
| 376 | private void createContents() { |
| 377 | |
| 378 | fFigureSubSystem_Name_LabelFigure = new WrappingLabel(); |
| 379 | fFigureSubSystem_Name_LabelFigure.setText("<...>"); |
| 380 | fFigureSubSystem_Name_LabelFigure.setBorder(new MarginBorder( |
| 381 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0), |
| 382 | getMapMode().DPtoLP(2), getMapMode().DPtoLP(0))); |
| 383 | |
| 384 | GridData constraintFFigureSubSystem_Name_LabelFigure = new GridData(); |
| 385 | constraintFFigureSubSystem_Name_LabelFigure.verticalAlignment = GridData.BEGINNING; |
| 386 | constraintFFigureSubSystem_Name_LabelFigure.horizontalAlignment = GridData.CENTER; |
| 387 | constraintFFigureSubSystem_Name_LabelFigure.horizontalIndent = 0; |
| 388 | constraintFFigureSubSystem_Name_LabelFigure.horizontalSpan = 1; |
| 389 | constraintFFigureSubSystem_Name_LabelFigure.verticalSpan = 1; |
| 390 | constraintFFigureSubSystem_Name_LabelFigure.grabExcessHorizontalSpace = true; |
| 391 | constraintFFigureSubSystem_Name_LabelFigure.grabExcessVerticalSpace = true; |
| 392 | this.add(fFigureSubSystem_Name_LabelFigure, |
| 393 | constraintFFigureSubSystem_Name_LabelFigure); |
| 394 | |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * @generated |
| 399 | */ |
| 400 | private boolean myUseLocalCoordinates = false; |
| 401 | |
| 402 | /** |
| 403 | * @generated |
| 404 | */ |
| 405 | protected boolean useLocalCoordinates() { |
| 406 | return myUseLocalCoordinates; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * @generated |
| 411 | */ |
| 412 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| 413 | myUseLocalCoordinates = useLocalCoordinates; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * @generated |
| 418 | */ |
| 419 | public WrappingLabel getFigureSubSystem_Name_LabelFigure() { |
| 420 | return fFigureSubSystem_Name_LabelFigure; |
| 421 | } |
| 422 | |
| 423 | } |
| 424 | |
| 425 | } |