private void calculate() { int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; minWidth = 0; minHeight = 0; for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm ga = pe.getGraphicsAlgorithm(); if (ga != null) { int x = ga.getX(); int y = ga.getY(); if (x < minX) minX = x; if (y < minY) minY = y; } } shiftX = minX; shiftY = minY; for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm ga = pe.getGraphicsAlgorithm(); if (ga != null) { int w = ga.getX() - minX + ga.getWidth(); int h = ga.getY() - minY + ga.getHeight(); if (w > minWidth) minWidth = w; if (h > minHeight) minHeight = h; } } if (minWidth <= 0) minWidth = GraphicsUtil.TASK_DEFAULT_WIDTH; if (minHeight <= 0) minHeight = GraphicsUtil.TASK_DEFAULT_HEIGHT; }
public static void updateDIEdge(Diagram diagram, Connection connection, Class clazz) { try { ModelHandler modelHandler = ModelHandlerLocator.getModelHandler( connection.getLink().getBusinessObjects().get(0).eResource()); EObject be = BusinessObjectUtil.getFirstElementOfType(connection, clazz); BPMNEdge edge = (BPMNEdge) modelHandler.findDIElement(diagram, (BaseElement) be); Point point = DcFactory.eINSTANCE.createPoint(); List<Point> waypoint = edge.getWaypoint(); waypoint.clear(); GraphicsAlgorithm graphicsAlgorithm = connection.getStart().getGraphicsAlgorithm(); // FIXME connections must create anchors!!! if (graphicsAlgorithm != null) { point.setX(graphicsAlgorithm.getX()); point.setY(graphicsAlgorithm.getY()); } else { point.setX(connection.getStart().getParent().getGraphicsAlgorithm().getX()); point.setY(connection.getStart().getParent().getGraphicsAlgorithm().getY()); } waypoint.add(point); if (connection instanceof FreeFormConnectionImpl) { FreeFormConnectionImpl freeForm = (FreeFormConnectionImpl) connection; EList<org.eclipse.graphiti.mm.algorithms.styles.Point> bendpoints = freeForm.getBendpoints(); for (org.eclipse.graphiti.mm.algorithms.styles.Point bp : bendpoints) { addBendPoint(freeForm, point); } } point = DcFactory.eINSTANCE.createPoint(); graphicsAlgorithm = connection.getEnd().getGraphicsAlgorithm(); if (graphicsAlgorithm != null) { point.setX(graphicsAlgorithm.getX()); point.setY(graphicsAlgorithm.getY()); } else { point.setX(connection.getEnd().getParent().getGraphicsAlgorithm().getX()); point.setY(connection.getEnd().getParent().getGraphicsAlgorithm().getY()); } waypoint.add(point); } catch (IOException e) { Activator.logError(e); } }
public static ContainerShape getLastLaneInContainer(ContainerShape root) { List<PictogramElement> laneShapes = BusinessObjectUtil.getChildElementsOfType(root, Lane.class); if (!laneShapes.isEmpty()) { Iterator<PictogramElement> iterator = laneShapes.iterator(); PictogramElement result = iterator.next(); if (result instanceof ContainerShape) { GraphicsAlgorithm ga = result.getGraphicsAlgorithm(); if (isHorizontal(root)) { while (iterator.hasNext()) { PictogramElement currentShape = iterator.next(); if (currentShape instanceof ContainerShape) { if (currentShape.getGraphicsAlgorithm().getY() > ga.getY()) { result = currentShape; } } } } else { while (iterator.hasNext()) { PictogramElement currentShape = iterator.next(); if (currentShape instanceof ContainerShape) { if (currentShape.getGraphicsAlgorithm().getX() > ga.getX()) { result = currentShape; } } } } return (ContainerShape) result; } } return root; }
private void movePin(Pin pin, IMoveShapeContext context) { PictogramElement pinShape = getPinShape(pin); if (pinShape != null) { GraphicsAlgorithm pinArea = pinShape.getGraphicsAlgorithm(); pinArea.setX(pinArea.getX() + context.getDeltaX()); pinArea.setY(pinArea.getY() + context.getDeltaY()); } }
private void splitBendPoints( FreeFormConnection startConnection, Connection endConnection, int x, int y) { List<Point> points = new ArrayList<Point>(); GraphicsAlgorithm startGa = startConnection.getStart().getGraphicsAlgorithm(); if (startGa != null) { Point p = StylesFactory.eINSTANCE.createPoint(); p.setX(startGa.getX()); p.setY(startGa.getY()); points.add(p); } points.addAll(startConnection.getBendpoints()); GraphicsAlgorithm endGa = startConnection.getEnd().getGraphicsAlgorithm(); if (endGa != null) { Point p = StylesFactory.eINSTANCE.createPoint(); p.setX(endGa.getX()); p.setY(endGa.getY()); points.add(p); } Point p0 = null; int min = -1, minDistance2 = -1; for (int i = 0; i < points.size(); i++) { Point p1 = points.get(i); if (p0 == null) { p0 = p1; } else { int distance2 = distance2(x, p0.getX(), y, p0.getX()) + distance2(x, p1.getX(), y, p1.getY()); if (min < 0 || distance2 < minDistance2) { min = i; minDistance2 = distance2; } p0 = p1; } } for (int i = min; i > 0 && i < points.size(); i++) { Point p = points.get(i); if (p.eContainer() != null) { ((List<?>) p.eContainer().eGet(p.eContainingFeature())).remove(p); } if (endConnection instanceof FreeFormConnection) { ((FreeFormConnection) endConnection).getBendpoints().add(p); } } }
@Override public void execute(ICustomContext context) { PictogramElement[] pes = context.getPictogramElements(); if (pes != null && pes.length == 1) { PictogramElement pe0 = pes[0]; Object bo = getBusinessObjectForPictogramElement(pe0); if (pe0 instanceof ContainerShape && bo instanceof FlowNode) { ContainerShape containerShape = (ContainerShape) pe0; FlowNode flowNode = (FlowNode) bo; try { BPMNShape bpmnShape = DIUtils.findBPMNShape(flowNode); if (bpmnShape.isIsExpanded()) { Bpmn2Preferences preferences = Bpmn2Preferences.getInstance(getDiagram()); ShapeStyle ss = preferences.getShapeStyle("TASKS"); // SubProcess is expanded - resize to standard Task size // NOTE: children tasks will be set not-visible in LayoutExpandableActivityFeature bpmnShape.setIsExpanded(false); GraphicsAlgorithm ga = containerShape.getGraphicsAlgorithm(); ResizeShapeContext resizeContext = new ResizeShapeContext(containerShape); IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(resizeContext); IDimension oldSize = FeatureSupport.getCollapsedSize(containerShape); int oldWidth = ga.getWidth(); int oldHeight = ga.getHeight(); FeatureSupport.setExpandedSize(containerShape, oldWidth, oldHeight); int newWidth = ss.getDefaultWidth(); int newHeight = ss.getDefaultHeight(); if (newWidth < oldSize.getWidth()) oldSize.setWidth(newWidth); if (newHeight < oldSize.getHeight()) oldSize.setHeight(newHeight); newWidth = oldSize.getWidth(); newHeight = oldSize.getHeight(); resizeContext.setX(ga.getX() + oldWidth / 2 - newWidth / 2); resizeContext.setY(ga.getY() + oldHeight / 2 - newHeight / 2); resizeContext.setWidth(newWidth); resizeContext.setHeight(newHeight); resizeFeature.resizeShape(resizeContext); UpdateContext updateContext = new UpdateContext(containerShape); IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(updateContext); if (updateFeature.updateNeeded(updateContext).toBoolean()) updateFeature.update(updateContext); getDiagramEditor().selectPictogramElements(new PictogramElement[] {}); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
@Override public void delete(IDeleteContext context) { ContainerShape laneContainerShape = (ContainerShape) context.getPictogramElement(); ContainerShape parentContainerShape = laneContainerShape.getContainer(); if (parentContainerShape != null) { boolean before = false; ContainerShape neighborContainerShape = FeatureSupport.getLaneAfter(laneContainerShape); if (neighborContainerShape == null) { neighborContainerShape = FeatureSupport.getLaneBefore(laneContainerShape); if (neighborContainerShape == null) { super.delete(context); return; } else { before = true; } } boolean isHorizontal = FeatureSupport.isHorizontal(laneContainerShape); GraphicsAlgorithm ga = laneContainerShape.getGraphicsAlgorithm(); GraphicsAlgorithm neighborGA = neighborContainerShape.getGraphicsAlgorithm(); ResizeShapeContext newContext = new ResizeShapeContext(neighborContainerShape); if (!before) { Graphiti.getGaService().setLocation(neighborGA, ga.getX(), ga.getY()); } newContext.setLocation(neighborGA.getX(), neighborGA.getY()); if (isHorizontal) { newContext.setHeight(neighborGA.getHeight() + ga.getHeight()); newContext.setWidth(neighborGA.getWidth()); } else { newContext.setHeight(neighborGA.getHeight()); newContext.setWidth(neighborGA.getWidth() + ga.getWidth()); } IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(newContext); if (resizeFeature.canResizeShape(newContext)) { super.delete(context); resizeFeature.resizeShape(newContext); return; } } super.delete(context); }
private void resizeLaneWidth(IResizeShapeContext context) { ContainerShape participantShape = (ContainerShape) context.getShape(); GraphicsAlgorithm ga = participantShape.getGraphicsAlgorithm(); int dHeight = context.getHeight() - ga.getHeight(); int dWidth = context.getWidth() - ga.getWidth(); if ((dWidth != 0 && FeatureSupport.isHorizontal(participantShape)) || (dHeight != 0 && !FeatureSupport.isHorizontal(participantShape))) { List<PictogramElement> childrenShapes = FeatureSupport.getChildsOfBusinessObjectType(participantShape, Lane.class); for (PictogramElement currentPicElem : childrenShapes) { if (currentPicElem instanceof ContainerShape) { ContainerShape currentContainerShape = (ContainerShape) currentPicElem; GraphicsAlgorithm laneGA = currentContainerShape.getGraphicsAlgorithm(); ResizeShapeContext newContext = new ResizeShapeContext(currentContainerShape); newContext.setLocation(laneGA.getX(), laneGA.getY()); if (FeatureSupport.isHorizontal(participantShape)) { newContext.setWidth(laneGA.getWidth() + dWidth); newContext.setHeight(laneGA.getHeight()); } else { newContext.setHeight(laneGA.getHeight() + dHeight); newContext.setWidth(laneGA.getWidth()); } newContext.putProperty(POOL_RESIZE_PROPERTY, true); IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(newContext); if (resizeFeature.canResizeShape(newContext)) { resizeFeature.resizeShape(newContext); } } } } }
@Override public void resizeShape(IResizeShapeContext context) { ResizeShapeContext resizeShapeContext = (ResizeShapeContext) context; ContainerShape containerShape = (ContainerShape) context.getPictogramElement(); Activity activity = BusinessObjectUtil.getFirstElementOfType(containerShape, Activity.class); try { BPMNShape shape = (BPMNShape) ModelHandlerLocator.getModelHandler(getDiagram().eResource()).findDIElement(activity); if (shape.isIsExpanded()) { // SubProcess is expanded GraphicsAlgorithm parentGa = containerShape.getGraphicsAlgorithm(); int newWidth = resizeShapeContext.getWidth(); int newHeight = resizeShapeContext.getHeight(); SizeCalculator sizeCalc = new SizeCalculator(containerShape); int shiftX = sizeCalc.shiftX; int shiftY = sizeCalc.shiftY; int minWidth = sizeCalc.minWidth; int minHeight = sizeCalc.minHeight; if (shiftX < 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int x = childGa.getX() - shiftX + MARGIN; childGa.setX(x); } } resizeShapeContext.setX(resizeShapeContext.getX() + shiftX - MARGIN); shiftX = MARGIN; } if (shiftY < 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int y = childGa.getY() - shiftY + MARGIN; childGa.setY(y); } } resizeShapeContext.setY(resizeShapeContext.getY() + shiftY - MARGIN); shiftX = MARGIN; } if (shiftX < MARGIN) shiftX = MARGIN; if (shiftY < MARGIN) shiftY = MARGIN; minWidth += 2 * MARGIN; minHeight += 2 * MARGIN; if (newWidth < minWidth) { parentGa.setWidth(minWidth); } if (newWidth < shiftX + minWidth) { int shift = shiftX + minWidth - newWidth; if (shift > shiftX - MARGIN) { shift = shiftX - MARGIN; } if (shift > 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int x = childGa.getX() - shift; childGa.setX(x); } } } } if (newHeight < minHeight) { parentGa.setHeight(minHeight); } if (newHeight < shiftY + minHeight) { int shift = shiftY + minHeight - newHeight; if (shift > shiftY - MARGIN) { shift = shiftY - MARGIN; } if (shift > 0) { for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { int y = childGa.getY() - shift; childGa.setY(y); } } } } if (resizeShapeContext.getWidth() < minWidth) resizeShapeContext.setWidth(minWidth); if (resizeShapeContext.getHeight() < minHeight) resizeShapeContext.setHeight(minHeight); } else { // SubProcess is collapsed for (PictogramElement pe : FeatureSupport.getContainerDecorators(containerShape)) { GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm(); if (childGa != null) { childGa.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth()); childGa.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight()); } } resizeShapeContext.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth()); resizeShapeContext.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight()); } } catch (Exception e) { Activator.logError(e); } Graphiti.getPeService().sendToBack(containerShape); super.resizeShape(context); }
private void resizeLaneHeight(IResizeShapeContext context) { ContainerShape participantShape = (ContainerShape) context.getShape(); GraphicsAlgorithm ga = participantShape.getGraphicsAlgorithm(); ContainerShape laneToResize = null; GraphicsAlgorithm laneToResizeGA = null; int width = 0; int height = 0; int x = 0; int y = 0; boolean resizeFirstLane = false; boolean resize = false; if (FeatureSupport.isHorizontal(participantShape)) { int dHeight = context.getHeight() - ga.getHeight(); if (dHeight != 0) { resize = true; if (context.getY() != ga.getY()) { laneToResize = (ContainerShape) FeatureSupport.getFirstLaneInContainer(participantShape); resizeFirstLane = true; } else { laneToResize = (ContainerShape) FeatureSupport.getLastLaneInContainer(participantShape); } laneToResizeGA = laneToResize.getGraphicsAlgorithm(); width = laneToResizeGA.getWidth(); height = laneToResizeGA.getHeight() + dHeight; x = laneToResizeGA.getX(); y = laneToResizeGA.getY(); } } else { int dWidth = context.getWidth() - ga.getWidth(); if (dWidth != 0) { resize = true; if (context.getX() != ga.getX()) { laneToResize = (ContainerShape) FeatureSupport.getFirstLaneInContainer(participantShape); resizeFirstLane = true; } else { laneToResize = (ContainerShape) FeatureSupport.getLastLaneInContainer(participantShape); } laneToResizeGA = laneToResize.getGraphicsAlgorithm(); width = laneToResizeGA.getWidth() + dWidth; height = laneToResizeGA.getHeight(); x = laneToResizeGA.getX(); y = laneToResizeGA.getY(); } } if (resize) { ResizeShapeContext newContext = new ResizeShapeContext(laneToResize); newContext.setLocation(x, y); newContext.setHeight(height); newContext.setWidth(width); newContext.putProperty(POOL_RESIZE_PROPERTY, true); newContext.putProperty(RESIZE_FIRST_LANE, resizeFirstLane); IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(newContext); if (resizeFeature.canResizeShape(newContext)) { resizeFeature.resizeShape(newContext); } if (FeatureSupport.isHorizontal(participantShape)) { ((ResizeShapeContext) context).setHeight(ga.getHeight()); } else { ((ResizeShapeContext) context).setWidth(ga.getWidth()); } } }