ServiceClientEditPart.java
Go to the documentation of this file.
00001 package org.ros.model.ros_package.diagram.edit.parts;
00002 
00003 import org.eclipse.draw2d.ColorConstants;
00004 import org.eclipse.draw2d.FlowLayout;
00005 import org.eclipse.draw2d.Graphics;
00006 import org.eclipse.draw2d.IFigure;
00007 import org.eclipse.draw2d.MarginBorder;
00008 import org.eclipse.draw2d.RectangleFigure;
00009 import org.eclipse.draw2d.ScalablePolygonShape;
00010 import org.eclipse.draw2d.Shape;
00011 import org.eclipse.draw2d.StackLayout;
00012 import org.eclipse.draw2d.geometry.Dimension;
00013 import org.eclipse.draw2d.geometry.Point;
00014 import org.eclipse.draw2d.geometry.Rectangle;
00015 import org.eclipse.gef.EditPart;
00016 import org.eclipse.gef.EditPolicy;
00017 import org.eclipse.gef.commands.Command;
00018 import org.eclipse.gef.editpolicies.LayoutEditPolicy;
00019 import org.eclipse.gef.requests.CreateRequest;
00020 import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
00021 import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
00022 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
00023 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.FlowLayoutEditPolicy;
00024 import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
00025 import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
00026 import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
00027 import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
00028 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
00029 import org.eclipse.gmf.runtime.notation.View;
00030 import org.eclipse.swt.graphics.Color;
00031 
00035 public class ServiceClientEditPart extends AbstractBorderItemEditPart {
00036 
00040         public static final int VISUAL_ID = 3003;
00041 
00045         protected IFigure contentPane;
00046 
00050         protected IFigure primaryShape;
00051 
00055         public ServiceClientEditPart(View view) {
00056                 super(view);
00057         }
00058 
00062         protected void createDefaultEditPolicies() {
00063                 super.createDefaultEditPolicies();
00064                 installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
00065                                 getPrimaryDragEditPolicy());
00066                 installEditPolicy(
00067                                 EditPolicyRoles.SEMANTIC_ROLE,
00068                                 new org.ros.model.ros_package.diagram.edit.policies.ServiceClientItemSemanticEditPolicy());
00069                 installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
00070                 // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
00071                 // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
00072         }
00073 
00077         protected LayoutEditPolicy createLayoutEditPolicy() {
00078 
00079                 FlowLayoutEditPolicy lep = new FlowLayoutEditPolicy() {
00080 
00081                         protected Command createAddCommand(EditPart child, EditPart after) {
00082                                 return null;
00083                         }
00084 
00085                         protected Command createMoveChildCommand(EditPart child,
00086                                         EditPart after) {
00087                                 return null;
00088                         }
00089 
00090                         protected Command getCreateCommand(CreateRequest request) {
00091                                 return null;
00092                         }
00093                 };
00094                 return lep;
00095         }
00096 
00100         protected IFigure createNodeShape() {
00101                 return primaryShape = new ServiceClientFigure();
00102         }
00103 
00107         public ServiceClientFigure getPrimaryShape() {
00108                 return (ServiceClientFigure) primaryShape;
00109         }
00110 
00114         protected boolean addFixedChild(EditPart childEditPart) {
00115                 if (childEditPart instanceof org.ros.model.ros_package.diagram.edit.parts.ServiceClientNameEditPart) {
00116                         ((org.ros.model.ros_package.diagram.edit.parts.ServiceClientNameEditPart) childEditPart)
00117                                         .setLabel(getPrimaryShape()
00118                                                         .getFigureServiceClientNameFigure());
00119                         return true;
00120                 }
00121                 return false;
00122         }
00123 
00127         protected boolean removeFixedChild(EditPart childEditPart) {
00128                 if (childEditPart instanceof org.ros.model.ros_package.diagram.edit.parts.ServiceClientNameEditPart) {
00129                         return true;
00130                 }
00131                 return false;
00132         }
00133 
00137         protected void addChildVisual(EditPart childEditPart, int index) {
00138                 if (addFixedChild(childEditPart)) {
00139                         return;
00140                 }
00141                 super.addChildVisual(childEditPart, -1);
00142         }
00143 
00147         protected void removeChildVisual(EditPart childEditPart) {
00148                 if (removeFixedChild(childEditPart)) {
00149                         return;
00150                 }
00151                 super.removeChildVisual(childEditPart);
00152         }
00153 
00157         protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
00158                 return getContentPane();
00159         }
00160 
00164         protected NodeFigure createNodePlate() {
00165                 DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(80, 20);
00166 
00167                 //FIXME: workaround for #154536
00168                 result.getBounds().setSize(result.getPreferredSize());
00169                 return result;
00170         }
00171 
00180         protected NodeFigure createNodeFigure() {
00181                 NodeFigure figure = createNodePlate();
00182                 figure.setLayoutManager(new StackLayout());
00183                 IFigure shape = createNodeShape();
00184                 figure.add(shape);
00185                 contentPane = setupContentPane(shape);
00186                 return figure;
00187         }
00188 
00195         protected IFigure setupContentPane(IFigure nodeShape) {
00196                 if (nodeShape.getLayoutManager() == null) {
00197                         ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
00198                         layout.setSpacing(5);
00199                         nodeShape.setLayoutManager(layout);
00200                 }
00201                 return nodeShape; // use nodeShape itself as contentPane
00202         }
00203 
00207         public IFigure getContentPane() {
00208                 if (contentPane != null) {
00209                         return contentPane;
00210                 }
00211                 return super.getContentPane();
00212         }
00213 
00217         protected void setForegroundColor(Color color) {
00218                 if (primaryShape != null) {
00219                         primaryShape.setForegroundColor(color);
00220                 }
00221         }
00222 
00226         protected void setBackgroundColor(Color color) {
00227                 if (primaryShape != null) {
00228                         primaryShape.setBackgroundColor(color);
00229                 }
00230         }
00231 
00235         protected void setLineWidth(int width) {
00236                 if (primaryShape instanceof Shape) {
00237                         ((Shape) primaryShape).setLineWidth(width);
00238                 }
00239         }
00240 
00244         protected void setLineType(int style) {
00245                 if (primaryShape instanceof Shape) {
00246                         ((Shape) primaryShape).setLineStyle(style);
00247                 }
00248         }
00249 
00253         public EditPart getPrimaryChildEditPart() {
00254                 return getChildBySemanticHint(org.ros.model.ros_package.diagram.part.RosVisualIDRegistry
00255                                 .getType(org.ros.model.ros_package.diagram.edit.parts.ServiceClientNameEditPart.VISUAL_ID));
00256         }
00257 
00261         public class ServiceClientFigure extends ScalablePolygonShape {
00262                 public static final int BLUR_SHADOW_WIDTH = 5;
00263 
00264                 @Override
00265                 public void paintFigure(Graphics graphics) {
00266                         drawBlurredShadow(graphics);
00267                         super.paintFigure(graphics);
00268                 }
00269 
00270                 private void drawBlurredShadow(Graphics graphics) {
00271                         // draw the shadow...
00272                         graphics.pushState();
00273 
00274                         int size = MapModeUtil.getMapMode(this).DPtoLP(BLUR_SHADOW_WIDTH);
00275                         int step = MapModeUtil.getMapMode(this).DPtoLP(-1);
00276 
00277                         graphics.setForegroundColor(ColorConstants.gray);
00278                         graphics.setLineWidth(MapModeUtil.getMapMode(this).DPtoLP(2));
00279                         graphics.translate(size, size);
00280                         graphics.setClip(graphics.getClip(new Rectangle(getBounds()))
00281                                         .expand(size, size));
00282                         graphics.setAlpha(20);
00283                         outlineShape(graphics);
00284                         graphics.translate(step, step);
00285                         graphics.setAlpha(30);
00286                         outlineShape(graphics);
00287                         graphics.translate(step, step);
00288                         graphics.setAlpha(60);
00289                         outlineShape(graphics);
00290                         graphics.translate(step, step);
00291                         graphics.setAlpha(100);
00292                         outlineShape(graphics);
00293                         graphics.translate(step, step);
00294                         graphics.setAlpha(150);
00295                         outlineShape(graphics);
00296 
00297                         graphics.popState();
00298                 }
00302                 private WrappingLabel fFigureServiceClientNameFigure;
00303 
00307                 public ServiceClientFigure() {
00308 
00309                         FlowLayout layoutThis = new FlowLayout();
00310                         layoutThis.setStretchMinorAxis(false);
00311                         layoutThis.setMinorAlignment(FlowLayout.ALIGN_CENTER);
00312 
00313                         layoutThis.setMajorAlignment(FlowLayout.ALIGN_CENTER);
00314                         layoutThis.setMajorSpacing(5);
00315                         layoutThis.setMinorSpacing(5);
00316                         layoutThis.setHorizontal(false);
00317 
00318                         this.setLayoutManager(layoutThis);
00319 
00320                         this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
00321                                         .DPtoLP(0)));
00322                         this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode()
00323                                         .DPtoLP(0)));
00324                         this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode()
00325                                         .DPtoLP(40)));
00326                         this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
00327                                         .DPtoLP(40)));
00328                         this.addPoint(new Point(getMapMode().DPtoLP(10), getMapMode()
00329                                         .DPtoLP(20)));
00330                         this.setFill(true);
00331                         this.setBackgroundColor(THIS_BACK);
00332                         this.setPreferredSize(new Dimension(getMapMode().DPtoLP(80),
00333                                         getMapMode().DPtoLP(20)));
00334 
00335                         this.setBorder(new MarginBorder(getMapMode().DPtoLP(2),
00336                                         getMapMode().DPtoLP(22), getMapMode().DPtoLP(2),
00337                                         getMapMode().DPtoLP(2)));
00338                         createContents();
00339                 }
00340 
00344                 private void createContents() {
00345 
00346                         fFigureServiceClientNameFigure = new WrappingLabel();
00347 
00348                         fFigureServiceClientNameFigure.setText("<...>");
00349 
00350                         this.add(fFigureServiceClientNameFigure);
00351 
00352                 }
00353 
00357                 public WrappingLabel getFigureServiceClientNameFigure() {
00358                         return fFigureServiceClientNameFigure;
00359                 }
00360 
00361         }
00362 
00366         static final Color THIS_BACK = new Color(null, 150, 150, 0);
00367 
00368 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34