diff --git a/org.activiti.designer.eclipse/src/main/java/org/activiti/designer/eclipse/editor/ActivitiDiagramEditor.java b/org.activiti.designer.eclipse/src/main/java/org/activiti/designer/eclipse/editor/ActivitiDiagramEditor.java index 639129df..70af41b2 100644 --- a/org.activiti.designer.eclipse/src/main/java/org/activiti/designer/eclipse/editor/ActivitiDiagramEditor.java +++ b/org.activiti.designer.eclipse/src/main/java/org/activiti/designer/eclipse/editor/ActivitiDiagramEditor.java @@ -520,7 +520,7 @@ protected void doExecute() { for (Process process : model.getBpmnModel().getProcesses()) { drawFlowElements(process.getFlowElements(), model.getBpmnModel().getLocationMap(), diagram, process); - drawArtifacts(process.getArtifacts(), model.getBpmnModel().getLocationMap(), diagram, process); + drawArtifacts(process, model.getBpmnModel().getLocationMap(), diagram, process); } drawAllFlows(model); drawMessageFlows(model.getBpmnModel().getMessageFlows().values(), model); @@ -561,6 +561,7 @@ private PictogramElement addContainerElement(BaseElement element, BpmnMemoryMode return pictElement; } + @SuppressWarnings({ "rawtypes", "unchecked" }) protected void drawFlowElements(Collection elementList, Map locationMap, ContainerShape parentShape, Process process) { final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); @@ -778,7 +779,7 @@ protected Point getLocation(ContainerShape containerShape) { return new Point(location.x + containerShape.getGraphicsAlgorithm().getX(), location.y + containerShape.getGraphicsAlgorithm().getY()); } - private void drawMessageFlows(final Collection messageFlows, final BpmnMemoryModel model) { + protected void drawMessageFlows(final Collection messageFlows, final BpmnMemoryModel model) { for (final MessageFlow messageFlow : messageFlows) { @@ -833,13 +834,13 @@ private void drawMessageFlows(final Collection messageFlows, final } } - private void drawArtifacts(final Collection artifacts, final Map locationMap, final ContainerShape parent, - final Process process) { + protected void drawArtifacts(final FlowElementsContainer container, final Map locationMap, + final ContainerShape parent, final Process process) { final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider(); final List artifactsWithoutDI = new ArrayList(); - for (final Artifact artifact : artifacts) { + for (final Artifact artifact : container.getArtifacts()) { if (artifact instanceof Association) { continue; @@ -862,7 +863,25 @@ private void drawArtifacts(final Collection artifacts, final Map artifacts, final Map flowList, BpmnMemoryModel model) { + protected void drawSequenceFlowsInList(Collection flowList, BpmnMemoryModel model) { for (FlowElement flowElement : flowList) { if (flowElement instanceof SubProcess) { @@ -913,7 +939,7 @@ private void drawSequenceFlowsInList(Collection flowList, BpmnMemor } } - private void drawSequenceFlow(SequenceFlow sequenceFlow, BpmnMemoryModel model) { + protected void drawSequenceFlow(SequenceFlow sequenceFlow, BpmnMemoryModel model) { Anchor sourceAnchor = null; Anchor targetAnchor = null; ContainerShape sourceShape = (ContainerShape) getDiagramTypeProvider().getFeatureProvider().getPictogramElementForBusinessObject( @@ -964,7 +990,7 @@ private void drawSequenceFlow(SequenceFlow sequenceFlow, BpmnMemoryModel model) getDiagramTypeProvider().getFeatureProvider().addIfPossible(addContext); } - private void drawAssociationsInList(Collection artifactList, BpmnMemoryModel model) { + protected void drawAssociationsInList(Collection artifactList, BpmnMemoryModel model) { for (Artifact artifact : artifactList) { if (artifact instanceof Association == false) { @@ -976,8 +1002,7 @@ private void drawAssociationsInList(Collection artifactList, BpmnMemor } } - private void drawAssociation(Association association, BpmnMemoryModel model) { - + protected void drawAssociation(Association association, BpmnMemoryModel model) { Anchor sourceAnchor = null; Anchor targetAnchor = null; BaseElement sourceElement = model.getFlowElement(association.getSourceRef()); diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/controller/AssociationShapeController.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/controller/AssociationShapeController.java index cc40c828..141278f0 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/controller/AssociationShapeController.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/controller/AssociationShapeController.java @@ -134,8 +134,8 @@ public PictogramElement createShape(Object businessObject, ContainerShape layout if(bendpointList != null && bendpointList.size() >= 0) { for (GraphicInfo graphicInfo : bendpointList) { Point bendPoint = StylesFactory.eINSTANCE.createPoint(); - bendPoint.setX((int)graphicInfo.getX()); - bendPoint.setY((int)graphicInfo.getY()); + bendPoint.setX((int) graphicInfo.getX()); + bendPoint.setY((int) graphicInfo.getY()); connection.getBendpoints().add(bendPoint); } @@ -177,14 +177,14 @@ public PictogramElement createShape(Object businessObject, ContainerShape layout (sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) { boolean subProcessWithBendPoint = false; - if(sourceElement instanceof SubProcess) { + if (sourceElement instanceof SubProcess) { int middleSub = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2); - if((middleSub + 20) < targetGraphics.getY() || (middleSub - 20) > targetGraphics.getY()) { + if ((middleSub + 20) < targetGraphics.getY() || (middleSub - 20) > targetGraphics.getY()) { subProcessWithBendPoint = true; } } - if(sourceElement instanceof SubProcess == false || subProcessWithBendPoint == true) { + if (sourceElement instanceof SubProcess == false || subProcessWithBendPoint == true) { Point bendPoint = StylesFactory.eINSTANCE.createPoint(); bendPoint.setX(targetX + 20); bendPoint.setY(sourceY + (sourceGraphics.getHeight() / 2)); diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/ContainerResizeFeature.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/ContainerResizeFeature.java index 6b64d40c..7c7c55ea 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/ContainerResizeFeature.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/ContainerResizeFeature.java @@ -14,14 +14,21 @@ package org.activiti.designer.features; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.activiti.bpmn.model.Activity; +import org.activiti.bpmn.model.Artifact; +import org.activiti.bpmn.model.Association; import org.activiti.bpmn.model.BoundaryEvent; import org.activiti.bpmn.model.FlowElement; +import org.activiti.bpmn.model.FlowElementsContainer; import org.activiti.bpmn.model.Lane; import org.activiti.bpmn.model.Pool; import org.activiti.bpmn.model.Process; +import org.activiti.bpmn.model.SequenceFlow; import org.activiti.bpmn.model.SubProcess; import org.activiti.bpmn.model.Transaction; import org.activiti.designer.PluginImage; @@ -30,11 +37,14 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IResizeShapeContext; +import org.eclipse.graphiti.features.context.impl.ResizeShapeContext; import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.Image; import org.eclipse.graphiti.mm.algorithms.Text; +import org.eclipse.graphiti.mm.algorithms.styles.Point; import org.eclipse.graphiti.mm.pictograms.ContainerShape; +import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; @@ -93,32 +103,88 @@ public void resizeShape(IResizeShapeContext context) { if (bo instanceof Lane) { Lane lane = (Lane) bo; + List sortedLanes = sortLanesByHorizontalOrder(lane.getParentProcess().getLanes()); + List sortedLaneIds = createLaneOrderedIdList(sortedLanes); + int laneIndex = sortedLaneIds.indexOf(lane.getId()); + ContainerShape poolShape = shape.getContainer(); - setSize(poolShape, bo, poolShape.getGraphicsAlgorithm().getWidth() + deltaWidth, - poolShape.getGraphicsAlgorithm().getHeight() + deltaHeight); - centerText(poolShape); + int newWidth = poolShape.getGraphicsAlgorithm().getWidth() + deltaWidth; + int newHeight = poolShape.getGraphicsAlgorithm().getHeight() + deltaHeight; + + if ((deltaHeight > 0 && context.getDirection() == IResizeShapeContext.DIRECTION_NORTH) || + (deltaHeight < 0 && context.getDirection() == IResizeShapeContext.DIRECTION_SOUTH)) { + + Graphiti.getGaService().setLocationAndSize(poolShape.getGraphicsAlgorithm(), poolShape.getGraphicsAlgorithm().getX(), + poolShape.getGraphicsAlgorithm().getY() - deltaHeight, newWidth, newHeight); + ((ResizeShapeContext) context).setY(oldY); + + } else if (deltaHeight != 0 || deltaWidth != 0) { + Graphiti.getGaService().setSize(poolShape.getGraphicsAlgorithm(), newWidth, newHeight); + if (context.getDirection() == IResizeShapeContext.DIRECTION_NORTH) { + ((ResizeShapeContext) context).setY(oldY); + } + } - int laneY = shape.getGraphicsAlgorithm().getY(); + for (GraphicsAlgorithm childGraphicsAlgorithm : poolShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren()) { + int newChildWidth = childGraphicsAlgorithm.getWidth() + deltaWidth; + int newChildHeight = childGraphicsAlgorithm.getHeight() + deltaHeight; + Graphiti.getGaService().setSize(childGraphicsAlgorithm, newChildWidth, newChildHeight); + } - for (Lane otherLane : lane.getParentProcess().getLanes()) { + for (Lane lanePositionObject : lane.getParentProcess().getLanes()) { + ContainerShape laneShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(lanePositionObject); + if (lanePositionObject.getId().equals(lane.getId()) == false && sortedLaneIds.indexOf(lanePositionObject.getId()) > laneIndex) { + Graphiti.getGaService().setLocation(laneShape.getGraphicsAlgorithm(), laneShape.getGraphicsAlgorithm().getX(), + laneShape.getGraphicsAlgorithm().getY() + deltaHeight); + } - if(lane.equals(otherLane)) continue; + if (deltaWidth != 0 && lanePositionObject.getId().equals(lane.getId()) == false) { + Graphiti.getGaService().setWidth(laneShape.getGraphicsAlgorithm(), laneShape.getGraphicsAlgorithm().getWidth() + deltaWidth); + for (GraphicsAlgorithm childGraphicsAlgorithm : laneShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren()) { + Graphiti.getGaService().setWidth(childGraphicsAlgorithm, childGraphicsAlgorithm.getWidth() + deltaWidth); + } + } + } - ContainerShape otherLaneShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(otherLane); - setSize(otherLaneShape, bo, otherLaneShape.getGraphicsAlgorithm().getWidth() + deltaWidth, - otherLaneShape.getGraphicsAlgorithm().getHeight()); + centerText(poolShape); + + List associations = new ArrayList(); + findAllAssociations(lane.getParentProcess(), associations); + Map> associationMap = new HashMap>(); + for (Association association : associations) { + List sourceAssociations = null; + if (associationMap.containsKey(association.getSourceRef()) == false) { + sourceAssociations = new ArrayList(); + } else { + sourceAssociations = associationMap.get(association.getSourceRef()); + } + sourceAssociations.add(association); + associationMap.put(association.getSourceRef(), sourceAssociations); + } + + List flowReferences = new ArrayList(); + if ((deltaHeight > 0 && context.getDirection() == IResizeShapeContext.DIRECTION_NORTH) || + (deltaHeight < 0 && context.getDirection() == IResizeShapeContext.DIRECTION_SOUTH)) { - centerText(otherLaneShape); + for (int i = 0; i < laneIndex + 1; i++) { + Lane laneFlowReferences = sortedLanes.get(i); + flowReferences.addAll(laneFlowReferences.getFlowReferences()); + } + moveChildElements(lane.getParentProcess().getFlowElements(), flowReferences, associationMap, deltaWidth, -deltaHeight); + + } else if ((deltaHeight < 0 && context.getDirection() == IResizeShapeContext.DIRECTION_NORTH) || + (deltaHeight > 0 && context.getDirection() == IResizeShapeContext.DIRECTION_SOUTH)) { - if(laneY < otherLaneShape.getGraphicsAlgorithm().getY()) { - otherLaneShape.getGraphicsAlgorithm().setY(otherLaneShape.getGraphicsAlgorithm().getY() + deltaHeight); + for (int i = laneIndex + 1; i < sortedLanes.size(); i++) { + Lane laneFlowReferences = sortedLanes.get(i); + flowReferences.addAll(laneFlowReferences.getFlowReferences()); } + moveChildElements(lane.getParentProcess().getFlowElements(), flowReferences, associationMap, deltaWidth, deltaHeight); } - } else if (bo instanceof Pool) { - if(context.getProperty("org.activiti.designer.lane.create") == null) { + if (context.getProperty("org.activiti.designer.lane.create") == null) { BpmnMemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram())); Pool pool = (Pool) bo; Process process = model.getBpmnModel().getProcess(pool.getId()); @@ -152,22 +218,7 @@ public void resizeShape(IResizeShapeContext context) { boundaryElement.getGraphicsAlgorithm().setY(boundaryElement.getGraphicsAlgorithm().getY() + deltaHeight); } } - for (FlowElement flowElement : subProcess.getFlowElements()) { - if (flowElement instanceof Activity) { - Activity activity = (Activity) flowElement; - for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) { - if (oldX != newX) { - PictogramElement boundaryElement = getFeatureProvider().getPictogramElementForBusinessObject(boundaryEvent); - boundaryElement.getGraphicsAlgorithm().setX(boundaryElement.getGraphicsAlgorithm().getX() + newX - oldX); - } - - if (oldY != newY) { - PictogramElement boundaryElement = getFeatureProvider().getPictogramElementForBusinessObject(boundaryEvent); - boundaryElement.getGraphicsAlgorithm().setY(boundaryElement.getGraphicsAlgorithm().getY() + newY - oldY); - } - } - } - } + moveSubProcessElements(subProcess, oldX, oldY, newX, newY); List childShapes = ((ContainerShape) context.getShape()).getChildren(); for (Shape childShape : childShapes) { @@ -200,6 +251,102 @@ public void resizeShape(IResizeShapeContext context) { } } + protected void moveSubProcessElements(SubProcess subProcess, int oldX, int oldY, int newX, int newY) { + int deltaX = 0; + int deltaY = 0; + if (oldX != newX) { + deltaX = newX - oldX; + } + + if (oldY != newY) { + deltaY = newY - oldY; + } + + for (FlowElement flowElement : subProcess.getFlowElements()) { + if (flowElement instanceof Activity) { + Activity activity = (Activity) flowElement; + for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) { + if (oldX != newX) { + PictogramElement boundaryElement = getFeatureProvider().getPictogramElementForBusinessObject(boundaryEvent); + boundaryElement.getGraphicsAlgorithm().setX(boundaryElement.getGraphicsAlgorithm().getX() + deltaX); + } + + if (oldY != newY) { + PictogramElement boundaryElement = getFeatureProvider().getPictogramElementForBusinessObject(boundaryEvent); + boundaryElement.getGraphicsAlgorithm().setY(boundaryElement.getGraphicsAlgorithm().getY() + deltaY); + } + } + + if (flowElement instanceof SubProcess) { + moveSubProcessElements((SubProcess) flowElement, oldX, oldY, newX, newY); + } + + } else if (flowElement instanceof SequenceFlow) { + SequenceFlow sequenceFlow = (SequenceFlow) flowElement; + + FreeFormConnection freeFormConnection = (FreeFormConnection) getFeatureProvider().getPictogramElementForBusinessObject(sequenceFlow); + moveBendpoints(freeFormConnection, deltaX, deltaY); + } + } + + for (Artifact artifact : subProcess.getArtifacts()) { + if (artifact instanceof Association) { + FreeFormConnection freeFormConnection = (FreeFormConnection) getFeatureProvider().getPictogramElementForBusinessObject(artifact); + moveBendpoints(freeFormConnection, deltaX, deltaY); + } + } + } + + protected void moveChildElements(Collection flowElements, List flowReferences, + Map> associationMap, int deltaWidth, int deltaHeight) { + + for (FlowElement flowElement : flowElements) { + + if (flowReferences.contains(flowElement.getId()) && associationMap.containsKey(flowElement.getId())) { + List associations = associationMap.get(flowElement.getId()); + for (Association association : associations) { + FreeFormConnection freeFormConnection = (FreeFormConnection) getFeatureProvider().getPictogramElementForBusinessObject(association); + moveBendpoints(freeFormConnection, deltaWidth, deltaHeight); + } + associationMap.remove(flowElement.getId()); + } + + if (flowElement instanceof Activity) { + if (flowReferences.contains(flowElement.getId()) == false) continue; + + Activity activity = (Activity) flowElement; + for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) { + PictogramElement boundaryElement = getFeatureProvider().getPictogramElementForBusinessObject(boundaryEvent); + GraphicsAlgorithm boundaryGraphics = boundaryElement.getGraphicsAlgorithm(); + Graphiti.getGaService().setLocation(boundaryGraphics, boundaryGraphics.getX() + deltaWidth, + boundaryGraphics.getY() + deltaHeight); + } + + if (flowElement instanceof FlowElementsContainer) { + moveChildElements(((FlowElementsContainer) flowElement).getFlowElements(), flowReferences, + associationMap, deltaWidth, deltaHeight); + } + + } else if (flowElement instanceof SequenceFlow) { + SequenceFlow sequenceFlow = (SequenceFlow) flowElement; + + if (flowReferences.contains(sequenceFlow.getSourceRef()) == false) continue; + + FreeFormConnection freeFormConnection = (FreeFormConnection) getFeatureProvider().getPictogramElementForBusinessObject(sequenceFlow); + moveBendpoints(freeFormConnection, deltaWidth, deltaHeight); + } + } + } + + protected void moveBendpoints(FreeFormConnection freeFormConnection, int deltaWidth, int deltaHeight) { + if (freeFormConnection.getBendpoints() != null && freeFormConnection.getBendpoints().size() > 0) { + for (Point point : freeFormConnection.getBendpoints()) { + point.setX(point.getX() + deltaWidth); + point.setY(point.getY() + deltaHeight); + } + } + } + protected void centerText(ContainerShape shape) { for (Shape shapeChild : shape.getChildren()) { if (shapeChild.getGraphicsAlgorithm() instanceof Text) { @@ -209,6 +356,11 @@ protected void centerText(ContainerShape shape) { } } + protected void setSizeOfObject(Shape shape, int width, int height) { + shape.getGraphicsAlgorithm().setHeight(height); + shape.getGraphicsAlgorithm().setWidth(width); + } + protected void setSize(Shape shape, Object bo, int width, int height) { int originalWidth = shape.getGraphicsAlgorithm().getWidth(); shape.getGraphicsAlgorithm().setHeight(height); @@ -233,7 +385,7 @@ protected List sortLanesByHorizontalOrder(List lanes) { for (int i = 0; i < sortedLanes.size(); i++) { Lane sortedLane = sortedLanes.get(i); ContainerShape sortedLaneShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(sortedLane); - if(sortedLaneShape.getGraphicsAlgorithm().getY() > laneShape.getGraphicsAlgorithm().getY()) { + if (sortedLaneShape.getGraphicsAlgorithm().getY() > laneShape.getGraphicsAlgorithm().getY()) { index = i; break; } @@ -247,4 +399,26 @@ protected List sortLanesByHorizontalOrder(List lanes) { } return sortedLanes; } + + protected List createLaneOrderedIdList(List sortedLanes) { + List laneIds = new ArrayList(sortedLanes.size()); + for (Lane lane : sortedLanes) { + laneIds.add(lane.getId()); + } + return laneIds; + } + + protected void findAllAssociations(FlowElementsContainer container, List resultAssociations) { + for (Artifact artifact : container.getArtifacts()) { + if (artifact instanceof Association) { + resultAssociations.add((Association) artifact); + } + } + + for (FlowElement flowElement : container.getFlowElements()) { + if (flowElement instanceof SubProcess) { + findAllAssociations((SubProcess) flowElement, resultAssociations); + } + } + } } diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateAssociationFeature.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateAssociationFeature.java index f71ec439..d15b2927 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateAssociationFeature.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateAssociationFeature.java @@ -1,5 +1,6 @@ package org.activiti.designer.features; +import org.activiti.bpmn.model.Activity; import org.activiti.bpmn.model.Association; import org.activiti.bpmn.model.BaseElement; import org.activiti.bpmn.model.BoundaryEvent; @@ -8,7 +9,6 @@ import org.activiti.bpmn.model.SubProcess; import org.activiti.bpmn.model.TextAnnotation; import org.activiti.designer.PluginImage; -import org.activiti.designer.util.editor.BpmnMemoryModel; import org.activiti.designer.util.editor.ModelHandler; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.graphiti.features.IFeatureProvider; @@ -69,7 +69,7 @@ public Connection create(ICreateConnectionContext context) { } } - private Association createAssociation(final BaseElement sourceBo, final BaseElement targetBo, + protected Association createAssociation(final BaseElement sourceBo, final BaseElement targetBo, final ICreateConnectionContext context) { final Association association = new Association(); @@ -78,25 +78,28 @@ private Association createAssociation(final BaseElement sourceBo, final BaseElem association.setSourceRef(sourceBo.getId()); association.setTargetRef(targetBo.getId()); - final ContainerShape targetContainer = (ContainerShape) context.getSourcePictogramElement(); - final ContainerShape parentContainer = targetContainer.getContainer(); - - if (parentContainer instanceof Diagram) { - final BpmnMemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram())); - if (model.getBpmnModel().getPools().size() > 0) { - String poolRef = model.getBpmnModel().getPools().get(0).getId(); - model.getBpmnModel().getProcess(poolRef).addArtifact(association); - } else { - model.getBpmnModel().getMainProcess().addArtifact(association); + ContainerShape targetContainer = null; + if (sourceBo instanceof BoundaryEvent) { + BoundaryEvent boundaryEvent = (BoundaryEvent) sourceBo; + if (boundaryEvent.getAttachedToRef() != null) { + Activity attachedActivity = boundaryEvent.getAttachedToRef(); + targetContainer = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(attachedActivity); } } else { - final Object parentBo = getBusinessObjectForPictogramElement(parentContainer); + targetContainer = (ContainerShape) context.getSourcePictogramElement(); + } - if (parentBo instanceof SubProcess) { - final SubProcess subProcess = (SubProcess) parentBo; - subProcess.addArtifact(association); - } else if (parentBo instanceof Lane) { - final Lane lane = (Lane) parentBo; + ContainerShape parentContainer = targetContainer.getContainer(); + if (parentContainer instanceof Diagram) { + ModelHandler.getModel(EcoreUtil.getURI(getDiagram())).getBpmnModel().getMainProcess().addArtifact(association); + + } else { + Object parentObject = getBusinessObjectForPictogramElement(parentContainer); + if (parentObject instanceof SubProcess) { + ((SubProcess) parentObject).addArtifact(association); + + } else if (parentObject instanceof Lane) { + Lane lane = (Lane) parentObject; lane.getParentProcess().addArtifact(association); } } diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateLaneFeature.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateLaneFeature.java index b1a7644e..bbd6559a 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateLaneFeature.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateLaneFeature.java @@ -76,11 +76,26 @@ public Object[] create(ICreateContext context) { height = poolShape.getGraphicsAlgorithm().getHeight(); } else { - ContainerShape lastLaneShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(lanes.get(lanes.size() - 1)); - x = lastLaneShape.getGraphicsAlgorithm().getX(); - y = lastLaneShape.getGraphicsAlgorithm().getY() + lastLaneShape.getGraphicsAlgorithm().getHeight(); - width = lastLaneShape.getGraphicsAlgorithm().getWidth(); - height = lastLaneShape.getGraphicsAlgorithm().getHeight(); + ContainerShape lastLaneShape = null; + for (int i = lanes.size() - 1; i >= 0; i--) { + lastLaneShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(lanes.get(i)); + if (lastLaneShape != null) { + break; + } + } + + if (lastLaneShape != null) { + x = lastLaneShape.getGraphicsAlgorithm().getX(); + y = lastLaneShape.getGraphicsAlgorithm().getY() + lastLaneShape.getGraphicsAlgorithm().getHeight(); + width = lastLaneShape.getGraphicsAlgorithm().getWidth(); + height = lastLaneShape.getGraphicsAlgorithm().getHeight(); + + } else { + x = 20; + y = 0; + width = poolShape.getGraphicsAlgorithm().getWidth() - 20; + height = poolShape.getGraphicsAlgorithm().getHeight(); + } } Lane newLane = new Lane(); diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateSequenceFlowFeature.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateSequenceFlowFeature.java index 5620aeff..fefdc7ab 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateSequenceFlowFeature.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/CreateSequenceFlowFeature.java @@ -123,7 +123,7 @@ private FlowNode getFlowNode(Anchor anchor) { /** * Creates a SequenceFlow between two BaseElements. */ - private SequenceFlow createSequenceFlow(FlowNode source, FlowNode target, ICreateConnectionContext context) { + protected SequenceFlow createSequenceFlow(FlowNode source, FlowNode target, ICreateConnectionContext context) { SequenceFlow sequenceFlow = new SequenceFlow(); sequenceFlow.setId(getNextId()); diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/DeleteLaneFeature.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/DeleteLaneFeature.java index 9fe6f616..45d9c113 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/DeleteLaneFeature.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/DeleteLaneFeature.java @@ -154,11 +154,14 @@ private void deleteSequenceFlows(FlowNode flowNode) { toDeleteSequenceFlows.add(outgoingSequenceFlow); } for (SequenceFlow deleteObject : toDeleteSequenceFlows) { - IRemoveContext rc = new RemoveContext(getFeatureProvider().getPictogramElementForBusinessObject(deleteObject)); - IFeatureProvider featureProvider = getFeatureProvider(); - IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc); - if (removeFeature != null) { - removeFeature.remove(rc); + PictogramElement deleteElement = getFeatureProvider().getPictogramElementForBusinessObject(deleteObject); + if (deleteElement != null) { + IRemoveContext rc = new RemoveContext(deleteElement); + IFeatureProvider featureProvider = getFeatureProvider(); + IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc); + if (removeFeature != null) { + removeFeature.remove(rc); + } } BpmnMemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram())); diff --git a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/MoveActivityFeature.java b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/MoveActivityFeature.java index acc58c4c..0120e384 100644 --- a/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/MoveActivityFeature.java +++ b/org.activiti.designer.gui/src/main/java/org/activiti/designer/features/MoveActivityFeature.java @@ -3,6 +3,8 @@ import java.util.List; import org.activiti.bpmn.model.Activity; +import org.activiti.bpmn.model.Artifact; +import org.activiti.bpmn.model.Association; import org.activiti.bpmn.model.BoundaryEvent; import org.activiti.bpmn.model.FlowElement; import org.activiti.bpmn.model.Lane; @@ -15,7 +17,9 @@ import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IMoveShapeContext; import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature; +import org.eclipse.graphiti.mm.algorithms.styles.Point; import org.eclipse.graphiti.mm.pictograms.Diagram; +import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; @@ -51,6 +55,15 @@ protected void preMoveShape(IMoveShapeContext context) { shapeLocationBeforeMove = Graphiti.getLayoutService().getLocationRelativeToDiagram(shape); super.preMoveShape(context); } + + + + @Override + public void moveShape(IMoveShapeContext context) { + preMoveShape(context); + internalMove(context); + postMoveShape(context); + } /** * Makes sure attached boundary events will be moved too, in case the shape itself is moved. @@ -142,22 +155,31 @@ protected void postMoveShape(IMoveShapeContext context) { } } - private void moveActivityChilds(Activity activity, ILocation shapeLocationAfterMove) { + protected void moveActivityChilds(Activity activity, ILocation shapeLocationAfterMove) { // get all boundary events of the activity final List boundaryEvents = activity.getBoundaryEvents(); moveBoundaryEvents(boundaryEvents, shapeLocationAfterMove); - // also move all boundary events in the sub process - if(activity instanceof SubProcess) { - for (FlowElement subElement : ((SubProcess) activity).getFlowElements()) { - if(subElement instanceof Activity) { + // also move all boundary events and bendpoints in the sub process + if (activity instanceof SubProcess) { + SubProcess subProcess = (SubProcess) activity; + for (FlowElement subElement : subProcess.getFlowElements()) { + if (subElement instanceof Activity) { moveActivityChilds((Activity) subElement, shapeLocationAfterMove); + } else if (subElement instanceof SequenceFlow) { + moveSequenceFlowBendpoints((SequenceFlow) subElement, shapeLocationAfterMove); } } + + for (Artifact artifact : subProcess.getArtifacts()) { + if (artifact instanceof Association) { + moveAssociationBendpoints((Association) artifact, shapeLocationAfterMove); + } + } } } - private void moveBoundaryEvents(final List boundaryEvents, ILocation shapeLocationAfterMove) { + protected void moveBoundaryEvents(final List boundaryEvents, ILocation shapeLocationAfterMove) { final IGaService gaService = Graphiti.getGaService(); for (final BoundaryEvent boundaryEvent : boundaryEvents) { @@ -177,4 +199,27 @@ private void moveBoundaryEvents(final List boundaryEvents, ILocat Graphiti.getPeService().sendToFront((Shape) picto); } } + + protected void moveSequenceFlowBendpoints(SequenceFlow sequenceFlow, ILocation shapeLocationAfterMove) { + FreeFormConnection freeFormConnection = (FreeFormConnection) getFeatureProvider().getPictogramElementForBusinessObject(sequenceFlow); + moveBendpoints(freeFormConnection, shapeLocationAfterMove); + } + + protected void moveAssociationBendpoints(Association association, ILocation shapeLocationAfterMove) { + FreeFormConnection freeFormConnection = (FreeFormConnection) getFeatureProvider().getPictogramElementForBusinessObject(association); + moveBendpoints(freeFormConnection, shapeLocationAfterMove); + } + + protected void moveBendpoints(FreeFormConnection freeFormConnection, ILocation shapeLocationAfterMove) { + if (freeFormConnection != null && freeFormConnection.getBendpoints() != null && freeFormConnection.getBendpoints().size() > 0) { + + int deltaX = shapeLocationAfterMove.getX() - shapeLocationBeforeMove.getX(); + int deltaY = shapeLocationAfterMove.getY() - shapeLocationBeforeMove.getY(); + + for (Point point : freeFormConnection.getBendpoints()) { + point.setX(point.getX() + deltaX); + point.setY(point.getY() + deltaY); + } + } + } } \ No newline at end of file diff --git a/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT-sources.jar b/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT-sources.jar index 1162bc99..8bbb2f58 100644 Binary files a/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT-sources.jar and b/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT-sources.jar differ diff --git a/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT.jar b/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT.jar index 8b2a6d2b..0959003e 100644 Binary files a/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT.jar and b/org.activiti.designer.libs/activiti-bpmn-converter-5.18.1-SNAPSHOT.jar differ diff --git a/org.activiti.designer.util/src/main/java/org/activiti/designer/util/eclipse/ActivitiUiUtil.java b/org.activiti.designer.util/src/main/java/org/activiti/designer/util/eclipse/ActivitiUiUtil.java index ad3b5f40..a5c55058 100644 --- a/org.activiti.designer.util/src/main/java/org/activiti/designer/util/eclipse/ActivitiUiUtil.java +++ b/org.activiti.designer.util/src/main/java/org/activiti/designer/util/eclipse/ActivitiUiUtil.java @@ -9,6 +9,7 @@ import org.activiti.bpmn.model.BaseElement; import org.activiti.bpmn.model.BoundaryEvent; import org.activiti.bpmn.model.FlowElement; +import org.activiti.bpmn.model.FlowElementsContainer; import org.activiti.bpmn.model.Lane; import org.activiti.bpmn.model.MessageFlow; import org.activiti.bpmn.model.Pool; @@ -214,7 +215,8 @@ public static final String getNextId(final Class featureC if (featureClass.equals(Lane.class)) { determinedId = loopThroughLanes(featureClass, determinedId, process.getLanes(), featureIdKey); } else if (featureClass.equals(TextAnnotation.class) || featureClass.equals(Association.class)) { - determinedId = loopThroughArtifacts(featureClass, determinedId, process.getArtifacts(), featureIdKey); + determinedId = loopThroughArtifacts(featureClass, determinedId, process, featureIdKey); + } else if (featureClass.equals(MessageFlow.class)) { determinedId = loopThroughMessageFlows(determinedId, model.getBpmnModel().getMessageFlows().values(), featureIdKey); } else { @@ -247,12 +249,19 @@ public static int loopThroughLanes(final Class featureCla } public static int loopThroughArtifacts(final Class featureClass, int determinedId, - Collection artifactList, final String featureIdKey) { + FlowElementsContainer container, final String featureIdKey) { - for (Artifact artifact : artifactList) { + for (Artifact artifact : container.getArtifacts()) { String contentObjectId = artifact.getId().replace(featureIdKey, ""); determinedId = getId(contentObjectId, determinedId); } + + for (FlowElement element : container.getFlowElements()) { + if (element instanceof SubProcess) { + determinedId = loopThroughArtifacts(featureClass, determinedId, (SubProcess) element, featureIdKey); + } + } + return determinedId; } @@ -271,11 +280,11 @@ public static int loopThroughElements(final Class feature for (FlowElement element : elementList) { - if(element instanceof SubProcess) { + if (element instanceof SubProcess) { determinedId = loopThroughElements(featureClass, determinedId, ((SubProcess) element).getFlowElements(), featureIdKey); } - if(featureClass == BoundaryEvent.class && element instanceof Activity) { + if (featureClass == BoundaryEvent.class && element instanceof Activity) { Activity activity = (Activity) element; for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) { if (boundaryEvent.getId() != null) {