| 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.IFigure; |
| 7 | import org.eclipse.draw2d.RoundedRectangle; |
| 8 | import org.eclipse.draw2d.Shape; |
| 9 | import org.eclipse.draw2d.StackLayout; |
| 10 | import org.eclipse.draw2d.geometry.Dimension; |
| 11 | import org.eclipse.gef.EditPart; |
| 12 | import org.eclipse.gef.EditPolicy; |
| 13 | import org.eclipse.gef.Request; |
| 14 | import org.eclipse.gef.commands.Command; |
| 15 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
| 16 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
| 17 | import org.eclipse.gef.requests.CreateRequest; |
| 18 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
| 19 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
| 20 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
| 21 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
| 22 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
| 23 | import org.eclipse.gmf.runtime.notation.View; |
| 24 | import org.eclipse.swt.graphics.Color; |
| 25 | |
| 26 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.policies.ResourceDemandingBehaviour4ItemSemanticEditPolicy; |
| 27 | |
| 28 | /** |
| 29 | * @generated |
| 30 | */ |
| 31 | public class ResourceDemandingBehaviour4EditPart extends ShapeNodeEditPart { |
| 32 | |
| 33 | /** |
| 34 | * @generated |
| 35 | */ |
| 36 | public static final int VISUAL_ID = 3018; |
| 37 | |
| 38 | /** |
| 39 | * @generated |
| 40 | */ |
| 41 | protected IFigure contentPane; |
| 42 | |
| 43 | /** |
| 44 | * @generated |
| 45 | */ |
| 46 | protected IFigure primaryShape; |
| 47 | |
| 48 | /** |
| 49 | * @generated |
| 50 | */ |
| 51 | public ResourceDemandingBehaviour4EditPart(View view) { |
| 52 | super(view); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @generated |
| 57 | */ |
| 58 | protected void createDefaultEditPolicies() { |
| 59 | super.createDefaultEditPolicies(); |
| 60 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
| 61 | new ResourceDemandingBehaviour4ItemSemanticEditPolicy()); |
| 62 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
| 63 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
| 64 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @generated |
| 69 | */ |
| 70 | protected LayoutEditPolicy createLayoutEditPolicy() { |
| 71 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
| 72 | |
| 73 | protected EditPolicy createChildEditPolicy(EditPart child) { |
| 74 | EditPolicy result = child |
| 75 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
| 76 | if (result == null) { |
| 77 | result = new NonResizableEditPolicy(); |
| 78 | } |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | protected Command getMoveChildrenCommand(Request request) { |
| 83 | return null; |
| 84 | } |
| 85 | |
| 86 | protected Command getCreateCommand(CreateRequest request) { |
| 87 | return null; |
| 88 | } |
| 89 | }; |
| 90 | return lep; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @generated |
| 95 | */ |
| 96 | protected IFigure createNodeShape() { |
| 97 | BehaviourFigure figure = new BehaviourFigure(); |
| 98 | return primaryShape = figure; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @generated |
| 103 | */ |
| 104 | public BehaviourFigure getPrimaryShape() { |
| 105 | return (BehaviourFigure) primaryShape; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @generated |
| 110 | */ |
| 111 | protected NodeFigure createNodePlate() { |
| 112 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
| 113 | return result; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Creates figure for this edit part. |
| 118 | * |
| 119 | * Body of this method does not depend on settings in generation model |
| 120 | * so you may safely remove <i>generated</i> tag and modify it. |
| 121 | * |
| 122 | * @generated |
| 123 | */ |
| 124 | protected NodeFigure createNodeFigure() { |
| 125 | NodeFigure figure = createNodePlate(); |
| 126 | figure.setLayoutManager(new StackLayout()); |
| 127 | IFigure shape = createNodeShape(); |
| 128 | figure.add(shape); |
| 129 | contentPane = setupContentPane(shape); |
| 130 | return figure; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Default implementation treats passed figure as content pane. |
| 135 | * Respects layout one may have set for generated figure. |
| 136 | * @param nodeShape instance of generated figure class |
| 137 | * @generated |
| 138 | */ |
| 139 | protected IFigure setupContentPane(IFigure nodeShape) { |
| 140 | if (nodeShape.getLayoutManager() == null) { |
| 141 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
| 142 | layout.setSpacing(5); |
| 143 | nodeShape.setLayoutManager(layout); |
| 144 | } |
| 145 | return nodeShape; // use nodeShape itself as contentPane |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @generated |
| 150 | */ |
| 151 | public IFigure getContentPane() { |
| 152 | if (contentPane != null) { |
| 153 | return contentPane; |
| 154 | } |
| 155 | return super.getContentPane(); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @generated |
| 160 | */ |
| 161 | protected void setForegroundColor(Color color) { |
| 162 | if (primaryShape != null) { |
| 163 | primaryShape.setForegroundColor(color); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @generated |
| 169 | */ |
| 170 | protected void setBackgroundColor(Color color) { |
| 171 | if (primaryShape != null) { |
| 172 | primaryShape.setBackgroundColor(color); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @generated |
| 178 | */ |
| 179 | protected void setLineWidth(int width) { |
| 180 | if (primaryShape instanceof Shape) { |
| 181 | ((Shape) primaryShape).setLineWidth(width); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @generated |
| 187 | */ |
| 188 | protected void setLineType(int style) { |
| 189 | if (primaryShape instanceof Shape) { |
| 190 | ((Shape) primaryShape).setLineStyle(style); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * @generated |
| 196 | */ |
| 197 | public class BehaviourFigure extends RoundedRectangle { |
| 198 | |
| 199 | /** |
| 200 | * @generated |
| 201 | */ |
| 202 | public BehaviourFigure() { |
| 203 | this.setCornerDimensions(new Dimension(getMapMode().DPtoLP(8), |
| 204 | getMapMode().DPtoLP(8))); |
| 205 | this.setLineWidth(1); |
| 206 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
| 207 | getMapMode().DPtoLP(0))); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * @generated |
| 212 | */ |
| 213 | private boolean myUseLocalCoordinates = false; |
| 214 | |
| 215 | /** |
| 216 | * @generated |
| 217 | */ |
| 218 | protected boolean useLocalCoordinates() { |
| 219 | return myUseLocalCoordinates; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * @generated |
| 224 | */ |
| 225 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| 226 | myUseLocalCoordinates = useLocalCoordinates; |
| 227 | } |
| 228 | |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | protected void refreshBounds() { |
| 233 | } |
| 234 | } |