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; }
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; }
@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); }