Go to the documentation of this file.00001 package org.ros.model.ros.diagram.edit.parts;
00002
00003 import java.util.ArrayList;
00004 import java.util.HashMap;
00005 import java.util.LinkedList;
00006 import java.util.List;
00007
00008 import org.eclipse.draw2d.ColorConstants;
00009 import org.eclipse.draw2d.FlowLayout;
00010 import org.eclipse.draw2d.Graphics;
00011 import org.eclipse.draw2d.IFigure;
00012 import org.eclipse.draw2d.MarginBorder;
00013 import org.eclipse.draw2d.RectangleFigure;
00014 import org.eclipse.draw2d.ScalablePolygonShape;
00015 import org.eclipse.draw2d.Shape;
00016 import org.eclipse.draw2d.StackLayout;
00017 import org.eclipse.draw2d.geometry.Dimension;
00018 import org.eclipse.draw2d.geometry.Point;
00019 import org.eclipse.draw2d.geometry.PrecisionPoint;
00020 import org.eclipse.draw2d.geometry.Rectangle;
00021 import org.eclipse.gef.EditPart;
00022 import org.eclipse.gef.EditPolicy;
00023 import org.eclipse.gef.commands.Command;
00024 import org.eclipse.gef.editpolicies.LayoutEditPolicy;
00025 import org.eclipse.gef.requests.CreateRequest;
00026 import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
00027 import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
00028 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
00029 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.FlowLayoutEditPolicy;
00030 import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
00031 import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
00032 import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
00033 import org.eclipse.gmf.runtime.emf.type.core.IElementType;
00034 import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
00035 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
00036 import org.eclipse.gmf.runtime.notation.View;
00037 import org.eclipse.swt.graphics.Color;
00038 import org.ros.model.ros.diagram.DefaultSizeNodeFigureWithFixedAnchors;
00039 import org.ros.model.ros.diagram.edit.policies.ActionServerItemSemanticEditPolicy;
00040 import org.ros.model.ros.diagram.part.RosVisualIDRegistry;
00041 import org.ros.model.ros.diagram.providers.RosElementTypes;
00042
00046 public class ActionServerEditPart extends AbstractBorderItemEditPart {
00047
00051 public static final int VISUAL_ID = 3005;
00052
00056 protected IFigure contentPane;
00057
00061 protected IFigure primaryShape;
00062
00066 public ActionServerEditPart(View view) {
00067 super(view);
00068 }
00069
00073 protected void createDefaultEditPolicies() {
00074 super.createDefaultEditPolicies();
00075 installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
00076 getPrimaryDragEditPolicy());
00077 installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
00078 new ActionServerItemSemanticEditPolicy());
00079 installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
00080
00081
00082 }
00083
00087 protected LayoutEditPolicy createLayoutEditPolicy() {
00088
00089 FlowLayoutEditPolicy lep = new FlowLayoutEditPolicy() {
00090
00091 protected Command createAddCommand(EditPart child, EditPart after) {
00092 return null;
00093 }
00094
00095 protected Command createMoveChildCommand(EditPart child,
00096 EditPart after) {
00097 return null;
00098 }
00099
00100 protected Command getCreateCommand(CreateRequest request) {
00101 return null;
00102 }
00103 };
00104 return lep;
00105 }
00106
00110 protected IFigure createNodeShape() {
00111 return primaryShape = new ActionServerFigure();
00112 }
00113
00117 public ActionServerFigure getPrimaryShape() {
00118 return (ActionServerFigure) primaryShape;
00119 }
00120
00124 protected boolean addFixedChild(EditPart childEditPart) {
00125 if (childEditPart instanceof ActionServerNameEditPart) {
00126 ((ActionServerNameEditPart) childEditPart)
00127 .setLabel(getPrimaryShape()
00128 .getFigureActionServerNameFigure());
00129 return true;
00130 }
00131 return false;
00132 }
00133
00137 protected boolean removeFixedChild(EditPart childEditPart) {
00138 if (childEditPart instanceof ActionServerNameEditPart) {
00139 return true;
00140 }
00141 return false;
00142 }
00143
00147 protected void addChildVisual(EditPart childEditPart, int index) {
00148 if (addFixedChild(childEditPart)) {
00149 return;
00150 }
00151 super.addChildVisual(childEditPart, -1);
00152 }
00153
00157 protected void removeChildVisual(EditPart childEditPart) {
00158 if (removeFixedChild(childEditPart)) {
00159 return;
00160 }
00161 super.removeChildVisual(childEditPart);
00162 }
00163
00167 protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
00168 return getContentPane();
00169 }
00170
00174 protected NodeFigure createNodePlate() {
00175 HashMap<String, PrecisionPoint> anchorLocations = new HashMap<String, PrecisionPoint>();
00176
00177 anchorLocations.put("EAST", new PrecisionPoint(1d, 0.5d));
00178
00179
00180 DefaultSizeNodeFigureWithFixedAnchors result = new DefaultSizeNodeFigureWithFixedAnchors(
00181 60, 20, anchorLocations);
00182
00183 result.getBounds().setSize(result.getPreferredSize());
00184 return result;
00185 }
00186
00195 protected NodeFigure createNodeFigure() {
00196 NodeFigure figure = createNodePlate();
00197 figure.setLayoutManager(new StackLayout());
00198 IFigure shape = createNodeShape();
00199 figure.add(shape);
00200 contentPane = setupContentPane(shape);
00201 return figure;
00202 }
00203
00210 protected IFigure setupContentPane(IFigure nodeShape) {
00211 if (nodeShape.getLayoutManager() == null) {
00212 ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
00213 layout.setSpacing(5);
00214 nodeShape.setLayoutManager(layout);
00215 }
00216 return nodeShape;
00217 }
00218
00222 public IFigure getContentPane() {
00223 if (contentPane != null) {
00224 return contentPane;
00225 }
00226 return super.getContentPane();
00227 }
00228
00232 protected void setForegroundColor(Color color) {
00233 if (primaryShape != null) {
00234 primaryShape.setForegroundColor(color);
00235 }
00236 }
00237
00241 protected void setBackgroundColor(Color color) {
00242 if (primaryShape != null) {
00243 primaryShape.setBackgroundColor(color);
00244 }
00245 }
00246
00250 protected void setLineWidth(int width) {
00251 if (primaryShape instanceof Shape) {
00252 ((Shape) primaryShape).setLineWidth(width);
00253 }
00254 }
00255
00259 protected void setLineType(int style) {
00260 if (primaryShape instanceof Shape) {
00261 ((Shape) primaryShape).setLineStyle(style);
00262 }
00263 }
00264
00268 public EditPart getPrimaryChildEditPart() {
00269 return getChildBySemanticHint(RosVisualIDRegistry
00270 .getType(ActionServerNameEditPart.VISUAL_ID));
00271 }
00272
00276 public List<IElementType> getMARelTypesOnSource() {
00277 ArrayList<IElementType> types = new ArrayList<IElementType>(1);
00278 types.add(RosElementTypes.Action_4003);
00279 return types;
00280 }
00281
00285 public List<IElementType> getMARelTypesOnSourceAndTarget(
00286 IGraphicalEditPart targetEditPart) {
00287 LinkedList<IElementType> types = new LinkedList<IElementType>();
00288 if (targetEditPart instanceof ActionClientEditPart) {
00289 types.add(RosElementTypes.Action_4003);
00290 }
00291 return types;
00292 }
00293
00297 public List<IElementType> getMATypesForTarget(IElementType relationshipType) {
00298 LinkedList<IElementType> types = new LinkedList<IElementType>();
00299 if (relationshipType == RosElementTypes.Action_4003) {
00300 types.add(RosElementTypes.ActionClient_3006);
00301 }
00302 return types;
00303 }
00304
00308 public class ActionServerFigure extends ScalablePolygonShape {
00309
00310 public static final int BLUR_SHADOW_WIDTH = 5;
00311
00312 @Override
00313 public void paintFigure(Graphics graphics) {
00314 drawBlurredShadow(graphics);
00315 super.paintFigure(graphics);
00316 }
00317
00318 private void drawBlurredShadow(Graphics graphics) {
00319
00320 graphics.pushState();
00321
00322 int size = MapModeUtil.getMapMode(this).DPtoLP(BLUR_SHADOW_WIDTH);
00323 int step = MapModeUtil.getMapMode(this).DPtoLP(-1);
00324
00325 graphics.setForegroundColor(ColorConstants.gray);
00326 graphics.setLineWidth(MapModeUtil.getMapMode(this).DPtoLP(2));
00327 graphics.translate(size, size);
00328 graphics.setClip(graphics.getClip(new Rectangle(getBounds()))
00329 .expand(size, size));
00330 graphics.setAlpha(20);
00331 outlineShape(graphics);
00332 graphics.translate(step, step);
00333 graphics.setAlpha(30);
00334 outlineShape(graphics);
00335 graphics.translate(step, step);
00336 graphics.setAlpha(60);
00337 outlineShape(graphics);
00338 graphics.translate(step, step);
00339 graphics.setAlpha(100);
00340 outlineShape(graphics);
00341 graphics.translate(step, step);
00342 graphics.setAlpha(150);
00343 outlineShape(graphics);
00344
00345 graphics.popState();
00346 }
00347
00351 private WrappingLabel fFigureActionServerNameFigure;
00352
00356 public ActionServerFigure() {
00357
00358 FlowLayout layoutThis = new FlowLayout();
00359 layoutThis.setStretchMinorAxis(false);
00360 layoutThis.setMinorAlignment(FlowLayout.ALIGN_CENTER);
00361
00362 layoutThis.setMajorAlignment(FlowLayout.ALIGN_CENTER);
00363 layoutThis.setMajorSpacing(5);
00364 layoutThis.setMinorSpacing(5);
00365 layoutThis.setHorizontal(false);
00366
00367 this.setLayoutManager(layoutThis);
00368
00369 this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
00370 .DPtoLP(0)));
00371 this.addPoint(new Point(getMapMode().DPtoLP(30), getMapMode()
00372 .DPtoLP(0)));
00373 this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode()
00374 .DPtoLP(20)));
00375 this.addPoint(new Point(getMapMode().DPtoLP(30), getMapMode()
00376 .DPtoLP(40)));
00377 this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
00378 .DPtoLP(40)));
00379 this.setFill(true);
00380 this.setBackgroundColor(THIS_BACK);
00381 this.setPreferredSize(new Dimension(getMapMode().DPtoLP(80),
00382 getMapMode().DPtoLP(20)));
00383
00384 this.setBorder(new MarginBorder(getMapMode().DPtoLP(2),
00385 getMapMode().DPtoLP(2), getMapMode().DPtoLP(2),
00386 getMapMode().DPtoLP(2)));
00387 createContents();
00388 }
00389
00393 private void createContents() {
00394
00395 fFigureActionServerNameFigure = new WrappingLabel();
00396
00397 fFigureActionServerNameFigure.setText("<...>");
00398
00399 this.add(fFigureActionServerNameFigure);
00400
00401 }
00402
00406 public WrappingLabel getFigureActionServerNameFigure() {
00407 return fFigureActionServerNameFigure;
00408 }
00409
00410 }
00411
00415 static final Color THIS_BACK = new Color(null, 22, 166, 30);
00416
00417 }