private Point getLocation(ContainerShape containerShape) { if (containerShape instanceof Diagram == true) { return new Point( containerShape.getGraphicsAlgorithm().getX(), containerShape.getGraphicsAlgorithm().getY()); } Point location = getLocation(containerShape.getContainer()); return new Point( location.x + containerShape.getGraphicsAlgorithm().getX(), location.y + containerShape.getGraphicsAlgorithm().getY()); }
private PictogramElement addContainerElement( BaseElement element, BpmnMemoryModel model, ContainerShape parent) { GraphicInfo graphicInfo = model.getBpmnModel().getGraphicInfo(element.getId()); if (graphicInfo == null) { return null; } final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); AddContext context = new AddContext(new AreaContext(), element); IAddFeature addFeature = featureProvider.getAddFeature(context); context.setNewObject(element); context.setSize((int) graphicInfo.getWidth(), (int) graphicInfo.getHeight()); context.setTargetContainer(parent); int x = (int) graphicInfo.getX(); int y = (int) graphicInfo.getY(); if (parent instanceof Diagram == false) { x = x - parent.getGraphicsAlgorithm().getX(); y = y - parent.getGraphicsAlgorithm().getY(); } context.setLocation(x, y); PictogramElement pictElement = null; if (addFeature.canAdd(context)) { pictElement = addFeature.add(context); featureProvider.link(pictElement, new Object[] {element}); } return pictElement; }
@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); } } } } }
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; }
@Override public IReason updateNeeded(IUpdateContext context) { if (!canUpdate(context)) { return Reason.createFalseReason(); } ContainerShape cs = (ContainerShape) context.getPictogramElement(); Reference reference = (Reference) getBusinessObjectForPictogramElement(cs); // make sure the component still exists in the model if (!GraphitiInternal.getEmfService().isObjectAlive(reference)) { return Reason.createTrueReason( String.format("Reference {0} has been removed.", reference.getName())); } // retrieve name from pictogram model String pictogramName = null; Text foundText = GraphitiUtil.findChildGA(cs.getGraphicsAlgorithm(), Text.class); if (foundText != null) { pictogramName = foundText.getValue(); } // update needed, if names are different String businessName = reference.getName(); boolean updateNameNeeded = ((pictogramName == null && businessName != null) || (pictogramName != null && !pictogramName.contentEquals(businessName))); if (updateNameNeeded) { return Reason.createTrueReason("Reference name is out of date"); } // check the wiring final Set<Contract> existingConnections = getExistingConnections(cs); for (ComponentReference promotedReference : reference.getPromote()) { if (promotedReference != null && !existingConnections.remove(promotedReference)) { return Reason.createTrueReason("Update connections."); } } if (existingConnections.size() > 0) { return Reason.createTrueReason("Update connections."); } return Reason.createFalseReason(); }
/** {@inheritDoc} */ @Override public PictogramElement add(final IAddContext context) { final Component addedModelElement = (Component) context.getNewObject(); // NEW stuff Object target = getBusinessObjectForPictogramElement(context.getTargetContainer()); final ContainerShape targetContainer = context.getTargetContainer(); final ISprayStyle style = new BcmSpray3DefaultStyle(); final ISprayShape shape = new ComponentShape(getFeatureProvider()); final ContainerShape conShape = shape.getShape(targetContainer, style); final IGaService gaService = Graphiti.getGaService(); gaService.setLocation(conShape.getGraphicsAlgorithm(), context.getX(), context.getY()); link(conShape, addedModelElement); linkShapes(conShape, addedModelElement); setDoneChanges(true); updatePictogramElement(conShape); layout(conShape); return conShape; }
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); }
@Override public boolean update(IUpdateContext context) { _hasDoneChanges = false; // retrieve name from business model ContainerShape cs = (ContainerShape) context.getPictogramElement(); Reference reference = (Reference) getBusinessObjectForPictogramElement(cs); // remove it if it's gone if (!GraphitiInternal.getEmfService().isObjectAlive(reference)) { IRemoveContext removeContext = new RemoveContext(context.getPictogramElement()); final IRemoveFeature removeFeature = getFeatureProvider().getRemoveFeature(removeContext); if (removeFeature != null && removeFeature.canRemove(removeContext)) { removeFeature.remove(removeContext); _hasDoneChanges = removeFeature.hasDoneChanges(); return true; } } // Set name in pictogram model String pictogramName = null; Text foundText = GraphitiUtil.findChildGA(cs.getGraphicsAlgorithm(), Text.class); if (foundText != null) { pictogramName = foundText.getValue(); } String businessName = reference.getName(); boolean updateNameNeeded = ((pictogramName == null && businessName != null) || (pictogramName != null && !pictogramName.contentEquals(businessName))); if (updateNameNeeded) { foundText.setValue(businessName); _hasDoneChanges = true; } // update the wires final Set<Contract> existingConnections = getExistingConnections(cs); final Anchor anchor = cs.getAnchors().get(0); for (ComponentReference promotedReference : reference.getPromote()) { if (promotedReference != null && !existingConnections.remove(promotedReference)) { for (PictogramElement pe : getFeatureProvider().getAllPictogramElementsForBusinessObject(promotedReference)) { if (pe instanceof Anchor) { AddConnectionContext addContext = new AddConnectionContext((Anchor) pe, anchor); addContext.setNewObject(reference); updatePictogramElement(getFeatureProvider().addIfPossible(addContext)); _hasDoneChanges = true; break; } } } } for (Connection connection : new ArrayList<Connection>(anchor.getIncomingConnections())) { Object bo = getBusinessObjectForPictogramElement(connection.getStart()); if (bo == null || existingConnections.remove(bo)) { RemoveContext removeContext = new RemoveContext(connection); IRemoveFeature removeFeature = getFeatureProvider().getRemoveFeature(removeContext); if (removeFeature.canExecute(removeContext)) { removeFeature.execute(removeContext); _hasDoneChanges = _hasDoneChanges || removeFeature.hasDoneChanges(); } } } return _hasDoneChanges; }
protected ContainerShape createNewShape( ModelHandler mh, ContainerShape oldShape, EClass newType) { ILayoutService layoutService = Graphiti.getLayoutService(); boolean horz = Bpmn2Preferences.getInstance().isHorizontalDefault(); ILocation loc = layoutService.getLocationRelativeToDiagram(oldShape); int x = loc.getX(); int y = loc.getY(); int xOffset = 0; int yOffset = 0; GraphicsAlgorithm ga = oldShape.getGraphicsAlgorithm(); int width = ga.getWidth(); int height = ga.getHeight(); BPMN2FeatureProvider fp = (BPMN2FeatureProvider) getFeatureProvider(); AbstractCreateFeature createFeature = (AbstractCreateFeature) fp.getCreateFeatureForBusinessObject(newType.getInstanceClass()); CreateContext createContext = new CreateContext(); createContext.putProperty(AbstractCreateFlowElementFeature.SKIP_ADD_GRAPHICS, true); createContext.setTargetContainer(oldShape.getContainer()); FlowElement newObject = null; if (createFeature != null) { newObject = (FlowElement) createFeature.create(createContext)[0]; } else { newObject = (FlowElement) mh.create(newType); } ContainerShape containerShape = oldShape.getContainer(); if (containerShape != getDiagram()) { // we are adding a new shape to a control (e.g a SubProcess) // so we need to adjust the location to be relative to the // control instead of the diagram loc = layoutService.getLocationRelativeToDiagram(containerShape); xOffset = loc.getX(); yOffset = loc.getY(); } BaseElement oldObject = BusinessObjectUtil.getFirstElementOfType(oldShape, BaseElement.class); if (oldObject instanceof Lane) { ((Lane) oldObject).getFlowNodeRefs().add((FlowNode) newObject); } AddContext ac = new AddContext(new AreaContext(), newObject); AbstractAddBpmnShapeFeature af = (AbstractAddBpmnShapeFeature) getFeatureProvider().getAddFeature(ac); int w = af.getDefaultWidth(); int h = af.getDefaultHeight(); if (horz) { x += width + 50 + w / 2; y += height / 2; boolean done = false; while (!done) { done = true; List<Shape> shapes = getFlowElementChildren(containerShape); for (Shape s : shapes) { if (GraphicsUtil.intersects(s, x - w / 2, y - h / 2, w, h)) { y += 100; done = false; break; } } } } else { x += width / 2; y += height + 50 + h / 2; boolean done = false; while (!done) { done = true; List<Shape> shapes = getFlowElementChildren(containerShape); for (Shape s : shapes) { if (GraphicsUtil.intersects(s, x - w / 2, y - h / 2, w, h)) { x += 100; done = false; break; } } } } ac.setX(x - xOffset); ac.setY(y - yOffset); ac.setTargetContainer(oldShape.getContainer()); return (ContainerShape) getFeatureProvider().addIfPossible(ac); }
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()); } } }