public IReason updateNeeded(IUpdateContext context) { // retrieve name from pictogram model String pictogramName = null; PictogramElement pictogramElement = context.getPictogramElement(); if (pictogramElement instanceof ContainerShape) { ContainerShape cs = (ContainerShape) pictogramElement; for (Shape shape : cs.getChildren()) { if (shape.getGraphicsAlgorithm() instanceof Text) { Text text = (Text) shape.getGraphicsAlgorithm(); pictogramName = text.getValue(); } } } // retrieve name from business model String businessName = null; Object bo = getBusinessObjectForPictogramElement(pictogramElement); if (bo instanceof EClass) { EClass eClass = (EClass) bo; businessName = eClass.getName(); } // update needed, if names are different boolean updateNameNeeded = ((pictogramName == null && businessName != null) || (pictogramName != null && !pictogramName.equals(businessName))); if (updateNameNeeded) { return Reason.createTrueReason("Name is out of date"); } else { return Reason.createFalseReason(); } }
protected void internalResize(IResizeShapeContext context) { Shape shape = context.getShape(); int x = context.getX(); int y = context.getY(); int width = context.getWidth(); int height = context.getHeight(); if (shape.getGraphicsAlgorithm() != null) { Graphiti.getGaService().setLocationAndSize(shape.getGraphicsAlgorithm(), x, y, width, height); } }
public boolean layout(ILayoutContext context) { boolean anythingChanged = false; ContainerShape containerShape = (ContainerShape) context.getPictogramElement(); GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm(); // the containerGa is the invisible rectangle // containing the visible rectangle as its (first and only) child GraphicsAlgorithm rectangle = containerGa.getGraphicsAlgorithmChildren().get(0); // height of invisible rectangle if (containerGa.getHeight() < MIN_HEIGHT) { containerGa.setHeight(MIN_HEIGHT); anythingChanged = true; } // height of visible rectangle (same as invisible rectangle) if (rectangle.getHeight() != containerGa.getHeight()) { rectangle.setHeight(containerGa.getHeight()); anythingChanged = true; } // width of invisible rectangle if (containerGa.getWidth() < MIN_WIDTH) { containerGa.setWidth(MIN_WIDTH); anythingChanged = true; } // width of visible rectangle (smaller than invisible rectangle) int rectangleWidth = containerGa.getWidth() - AddNodeFeature.INVISIBLE_RIGHT_SPACE; if (rectangle.getWidth() != rectangleWidth) { rectangle.setWidth(rectangleWidth); anythingChanged = true; } // width of text and line (same as visible rectangle) for (Shape shape : containerShape.getChildren()) { GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm(); IGaService gaService = Graphiti.getGaService(); IDimension size = gaService.calculateSize(graphicsAlgorithm); if (rectangleWidth != size.getWidth()) { gaService.setWidth(graphicsAlgorithm, rectangleWidth); anythingChanged = true; } } return anythingChanged; }
protected void moveClassShape( IFeatureProvider fp, Diagram diagram, int x, int y, String className) { Shape shape = findShapeForEClass(diagram, className); MoveShapeContext moveShapeContext = new MoveShapeContext(shape); moveShapeContext.setSourceContainer(shape.getContainer()); moveShapeContext.setTargetContainer(shape.getContainer()); moveShapeContext.setLocation(x, y); moveShapeContext.setDeltaX(x - shape.getGraphicsAlgorithm().getX()); moveShapeContext.setDeltaY(y - shape.getGraphicsAlgorithm().getY()); IMoveShapeFeature moveShapeFeature = fp.getMoveShapeFeature(moveShapeContext); assertNotNull("move shape feature not available", moveShapeFeature); if (moveShapeFeature.canMoveShape(moveShapeContext)) { moveShapeFeature.execute(moveShapeContext); } }
public boolean layout(ILayoutContext context) { boolean anythingChanged = false; ContainerShape containerShape = (ContainerShape) context.getPictogramElement(); GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm(); // height if (containerGa.getHeight() < MIN_HEIGHT) { containerGa.setHeight(MIN_HEIGHT); anythingChanged = true; } // width if (containerGa.getWidth() < MIN_WIDTH) { containerGa.setWidth(MIN_WIDTH); anythingChanged = true; } int containerWidth = containerGa.getWidth(); for (Shape shape : containerShape.getChildren()) { GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm(); IGaService gaService = Graphiti.getGaService(); IDimension size = gaService.calculateSize(graphicsAlgorithm); if (containerWidth != size.getWidth()) { if (graphicsAlgorithm instanceof Polyline) { Polyline polyline = (Polyline) graphicsAlgorithm; Point secondPoint = polyline.getPoints().get(1); Point newSecondPoint = gaService.createPoint(containerWidth, secondPoint.getY()); polyline.getPoints().set(1, newSecondPoint); anythingChanged = true; } else { gaService.setWidth(graphicsAlgorithm, containerWidth); anythingChanged = true; } } } return anythingChanged; }
private void performMove(Shape labelShape, Point position) { // always move within the original container GraphicsAlgorithm labelGraphicsAlgorithm = labelShape.getGraphicsAlgorithm(); if (labelGraphicsAlgorithm != null) { Graphiti.getGaService() .setLocation( labelGraphicsAlgorithm, position.getX() - labelGraphicsAlgorithm.getWidth() / 2, position.getY(), true); } }
@Override public void resizeShape(IResizeShapeContext context) { Shape shape = context.getShape(); int x = context.getX(); int y = context.getY(); // Application Component Width cannot be changed int width = StyleUtil.APP_COMPONENT_WIDTH; int height = context.getHeight(); if (shape.getGraphicsAlgorithm() != null) { Graphiti.getGaService().setLocationAndSize(shape.getGraphicsAlgorithm(), x, y, width, height); } layoutPictogramElement(shape); TNodeTemplateExtension applicationComponent = (TNodeTemplateExtension) getBusinessObjectForPictogramElement(shape); applicationComponent.setX(x); applicationComponent.setY(y); applicationComponent.setWidth(width); applicationComponent.setHeight(height); }
public boolean update(IUpdateContext context) { // retrieve name from business model String businessName = null; PictogramElement pictogramElement = context.getPictogramElement(); Object bo = getBusinessObjectForPictogramElement(pictogramElement); if (bo instanceof EClass) { EClass eClass = (EClass) bo; businessName = eClass.getName(); } // Set name in pictogram model if (pictogramElement instanceof ContainerShape) { ContainerShape cs = (ContainerShape) pictogramElement; for (Shape shape : cs.getChildren()) { if (shape.getGraphicsAlgorithm() instanceof Text) { Text text = (Text) shape.getGraphicsAlgorithm(); text.setValue(businessName); return true; } } } return false; }
/* * (non-Javadoc) * * @see * org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, * java.lang.Object) */ public EditPart createEditPart(EditPart context, Object model) { EditPart ret = null; IConfigurationProviderInternal configurationProvider = getConfigurationProvider(); Map<?, ?> epRegistry = getConfigurationProvider().getDiagramEditor().getGraphicalViewer().getEditPartRegistry(); if (epRegistry != null && epRegistry.containsKey(model)) { T.racer() .warning( "PictogramsEditPartFactory.createEditPart()", "edit part for this model already exists"); //$NON-NLS-1$ //$NON-NLS-2$ } if (model instanceof Shape) { Shape shape = (Shape) model; if (!(shape instanceof Diagram) && !shape.isActive()) { // return ret; // the following is a temorary fix just to make it fly ret = new ShapeEditPart(configurationProvider, shape); } } if (ret == null) { if (model instanceof Diagram) { ret = new DiagramEditPart(configurationProvider, (Diagram) model); } else if (model instanceof ConnectionDecorator) { ret = new ConnectionDecoratorEditPart(configurationProvider, (Shape) model); } else if (model instanceof ContainerShape) { ret = new ContainerShapeEditPart(configurationProvider, (ContainerShape) model); } else if (model instanceof Shape) { ret = new ShapeEditPart(configurationProvider, (Shape) model); } else if (model instanceof ManhattanConnection) { ret = new ManhattanConnectionEditPart( configurationProvider, (ManhattanConnection) model, context); } else if (model instanceof FreeFormConnection) { ret = new FreeFormConnectionEditPart( configurationProvider, (FreeFormConnection) model, context); } else if (model instanceof CurvedConnection) { ret = new CurvedConnectionEditPart(configurationProvider, (CurvedConnection) model, context); } else if (model instanceof CompositeConnection) { ret = new CompositeConnectionEditPart( configurationProvider, (CompositeConnection) model, this, context); } else if (model instanceof AdvancedAnchor) { ret = new AdvancedAnchorEditPart(configurationProvider, (AdvancedAnchor) model); } } // check whether autoswitch to direct editing has been set // if yes: store the affected edit part in the editor for later use in // the refresh method // if (ret instanceof ShapeEditPart) { // IDirectEditingInfo dei = // getConfigurationProvider().getDiagramTypeProvider().getFeatureProvider() // .getDirectEditingInfo(); // if (dei.isActive() && model.equals(dei.getMainPictogramElement())) { // getConfigurationProvider().getDiagramEditor().setDirectEditingEditPart((ShapeEditPart) // ret); // } // } return ret; }