| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.parts; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.Collections; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import org.eclipse.draw2d.IFigure; |
| 11 | import org.eclipse.draw2d.PositionConstants; |
| 12 | import org.eclipse.draw2d.RectangleFigure; |
| 13 | import org.eclipse.draw2d.Shape; |
| 14 | import org.eclipse.draw2d.StackLayout; |
| 15 | import org.eclipse.draw2d.geometry.Dimension; |
| 16 | import org.eclipse.draw2d.geometry.Point; |
| 17 | import org.eclipse.gef.EditPart; |
| 18 | import org.eclipse.gef.EditPolicy; |
| 19 | import org.eclipse.gef.GraphicalEditPart; |
| 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.editpolicies.ResizableEditPolicy; |
| 25 | import org.eclipse.gef.handles.MoveHandle; |
| 26 | import org.eclipse.gef.requests.CreateRequest; |
| 27 | import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart; |
| 28 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; |
| 29 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; |
| 30 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
| 31 | import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; |
| 32 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
| 33 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
| 34 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
| 35 | import org.eclipse.gmf.runtime.notation.View; |
| 36 | import org.eclipse.swt.graphics.Color; |
| 37 | |
| 38 | import de.uka.ipd.sdq.pcm.gmf.composite.InfrastructureProvidedRoleManualFigure; |
| 39 | import de.uka.ipd.sdq.pcm.gmf.composite.AbstractBorderFigure.POSITION_TYPE; |
| 40 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.InfrastructureProvidedRoleItemSemanticEditPolicy; |
| 41 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
| 42 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | public class InfrastructureProvidedRoleEditPart extends |
| 48 | BorderedBorderItemEditPart { |
| 49 | |
| 50 | /** |
| 51 | * size of the figure in LP |
| 52 | * |
| 53 | * @generated not |
| 54 | */ |
| 55 | private static final int FIGURE_LOGICAL_SIZE = 30; |
| 56 | |
| 57 | /** |
| 58 | * @generated |
| 59 | */ |
| 60 | public static final int VISUAL_ID = 3015; |
| 61 | |
| 62 | /** |
| 63 | * @generated |
| 64 | */ |
| 65 | protected IFigure contentPane; |
| 66 | |
| 67 | /** |
| 68 | * @generated |
| 69 | */ |
| 70 | protected IFigure primaryShape; |
| 71 | |
| 72 | /** |
| 73 | * @generated |
| 74 | */ |
| 75 | public InfrastructureProvidedRoleEditPart(View view) { |
| 76 | super(view); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @generated |
| 81 | */ |
| 82 | protected void createDefaultEditPolicies() { |
| 83 | super.createDefaultEditPolicies(); |
| 84 | installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, |
| 85 | getPrimaryDragEditPolicy()); |
| 86 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
| 87 | new InfrastructureProvidedRoleItemSemanticEditPolicy()); |
| 88 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
| 89 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
| 90 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @generated |
| 95 | */ |
| 96 | protected LayoutEditPolicy createLayoutEditPolicy() { |
| 97 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
| 98 | |
| 99 | protected EditPolicy createChildEditPolicy(EditPart child) { |
| 100 | View childView = (View) child.getModel(); |
| 101 | switch (PalladioComponentModelVisualIDRegistry |
| 102 | .getVisualID(childView)) { |
| 103 | case InfrastructureProvidedRoleEntityNameEditPart.VISUAL_ID: |
| 104 | return new BorderItemSelectionEditPolicy() { |
| 105 | |
| 106 | protected List createSelectionHandles() { |
| 107 | MoveHandle mh = new MoveHandle( |
| 108 | (GraphicalEditPart) getHost()); |
| 109 | mh.setBorder(null); |
| 110 | return Collections.singletonList(mh); |
| 111 | } |
| 112 | }; |
| 113 | } |
| 114 | EditPolicy result = child |
| 115 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
| 116 | if (result == null) { |
| 117 | result = new NonResizableEditPolicy(); |
| 118 | } |
| 119 | return result; |
| 120 | } |
| 121 | |
| 122 | protected Command getMoveChildrenCommand(Request request) { |
| 123 | return null; |
| 124 | } |
| 125 | |
| 126 | protected Command getCreateCommand(CreateRequest request) { |
| 127 | return null; |
| 128 | } |
| 129 | }; |
| 130 | return lep; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @generated |
| 135 | */ |
| 136 | protected IFigure createNodeShape() { |
| 137 | InfrastructureProvidedRoleFigure figure = new InfrastructureProvidedRoleFigure(); |
| 138 | return primaryShape = figure; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @generated |
| 143 | */ |
| 144 | public InfrastructureProvidedRoleFigure getPrimaryShape() { |
| 145 | return (InfrastructureProvidedRoleFigure) primaryShape; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @generated |
| 150 | */ |
| 151 | protected void addBorderItem(IFigure borderItemContainer, |
| 152 | IBorderItemEditPart borderItemEditPart) { |
| 153 | if (borderItemEditPart instanceof InfrastructureProvidedRoleEntityNameEditPart) { |
| 154 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
| 155 | PositionConstants.SOUTH); |
| 156 | locator.setBorderItemOffset(new Dimension(-20, -20)); |
| 157 | borderItemContainer.add(borderItemEditPart.getFigure(), locator); |
| 158 | } else { |
| 159 | super.addBorderItem(borderItemContainer, borderItemEditPart); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @generated |
| 165 | */ |
| 166 | protected NodeFigure createNodePlate() { |
| 167 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(20, 20); |
| 168 | |
| 169 | //FIXME: workaround for #154536 |
| 170 | result.getBounds().setSize(result.getPreferredSize()); |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @generated |
| 176 | */ |
| 177 | public EditPolicy getPrimaryDragEditPolicy() { |
| 178 | EditPolicy result = super.getPrimaryDragEditPolicy(); |
| 179 | if (result instanceof ResizableEditPolicy) { |
| 180 | ResizableEditPolicy ep = (ResizableEditPolicy) result; |
| 181 | ep.setResizeDirections(PositionConstants.NONE); |
| 182 | } |
| 183 | return result; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Creates figure for this edit part. |
| 188 | * |
| 189 | * Body of this method does not depend on settings in generation model |
| 190 | * so you may safely remove <i>generated</i> tag and modify it. |
| 191 | * |
| 192 | * Manually modified to generate a specific source figure |
| 193 | * instead of the standard shape configured in the map model. |
| 194 | * |
| 195 | * @generated not |
| 196 | */ |
| 197 | protected NodeFigure createMainFigure() { |
| 198 | InfrastructureProvidedRoleManualFigure figure = new InfrastructureProvidedRoleManualFigure(getMapMode().DPtoLP( |
| 199 | FIGURE_LOGICAL_SIZE), POSITION_TYPE.POS_INTERNAL); |
| 200 | figure.getBounds().setSize(figure.getPreferredSize()); |
| 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 | return nodeShape; // use nodeShape itself as contentPane |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @generated |
| 216 | */ |
| 217 | public IFigure getContentPane() { |
| 218 | if (contentPane != null) { |
| 219 | return contentPane; |
| 220 | } |
| 221 | return super.getContentPane(); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * @generated |
| 226 | */ |
| 227 | protected void setForegroundColor(Color color) { |
| 228 | if (primaryShape != null) { |
| 229 | primaryShape.setForegroundColor(color); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @generated |
| 235 | */ |
| 236 | protected void setBackgroundColor(Color color) { |
| 237 | if (primaryShape != null) { |
| 238 | primaryShape.setBackgroundColor(color); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * @generated |
| 244 | */ |
| 245 | protected void setLineWidth(int width) { |
| 246 | if (primaryShape instanceof Shape) { |
| 247 | ((Shape) primaryShape).setLineWidth(width); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * @generated |
| 253 | */ |
| 254 | protected void setLineType(int style) { |
| 255 | if (primaryShape instanceof Shape) { |
| 256 | ((Shape) primaryShape).setLineStyle(style); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * @generated |
| 262 | */ |
| 263 | public EditPart getPrimaryChildEditPart() { |
| 264 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
| 265 | .getType(InfrastructureProvidedRoleEntityNameEditPart.VISUAL_ID)); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @generated |
| 270 | */ |
| 271 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
| 272 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 273 | types |
| 274 | .add(PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008); |
| 275 | return types; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * @generated |
| 280 | */ |
| 281 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
| 282 | IElementType relationshipType) { |
| 283 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
| 284 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008) { |
| 285 | types |
| 286 | .add(PalladioComponentModelElementTypes.InfrastructureRequiredRole_3016); |
| 287 | } |
| 288 | return types; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * @generated |
| 293 | */ |
| 294 | public class InfrastructureProvidedRoleFigure extends RectangleFigure { |
| 295 | |
| 296 | /** |
| 297 | * @generated |
| 298 | */ |
| 299 | public InfrastructureProvidedRoleFigure() { |
| 300 | this.setLineWidth(1); |
| 301 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(20), |
| 302 | getMapMode().DPtoLP(20))); |
| 303 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
| 304 | getMapMode().DPtoLP(0))); |
| 305 | this.setLocation(new Point(getMapMode().DPtoLP(40), getMapMode() |
| 306 | .DPtoLP(40))); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * @generated |
| 311 | */ |
| 312 | private boolean myUseLocalCoordinates = false; |
| 313 | |
| 314 | /** |
| 315 | * @generated |
| 316 | */ |
| 317 | protected boolean useLocalCoordinates() { |
| 318 | return myUseLocalCoordinates; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * @generated |
| 323 | */ |
| 324 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| 325 | myUseLocalCoordinates = useLocalCoordinates; |
| 326 | } |
| 327 | |
| 328 | } |
| 329 | |
| 330 | } |