Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Brodt2014-07-28 16:05:00 -0400
committerBob Brodt2014-07-28 16:05:00 -0400
commitb0dbc9c6571083df1b7da6aab1eaeff1be04b722 (patch)
treeaf75ee02de4d523973b4298d358988f029e4c6e4
parent041761463d9cace31edb38919d19036f4c228ba9 (diff)
downloadorg.eclipse.bpmn2-modeler-b0dbc9c6571083df1b7da6aab1eaeff1be04b722.tar.gz
org.eclipse.bpmn2-modeler-b0dbc9c6571083df1b7da6aab1eaeff1be04b722.tar.xz
org.eclipse.bpmn2-modeler-b0dbc9c6571083df1b7da6aab1eaeff1be04b722.zip
Anchor rework now includes Connection anchors.
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIImport.java73
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AutomaticConnectionRouter.java118
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/BendpointConnectionRouter.java20
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ConnectionRoute.java180
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java294
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultDeleteBPMNShapeFeature.java18
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultLayoutBPMNConnectionFeature.java89
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultResizeBPMNShapeFeature.java2
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/GraphitiConstants.java26
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/IConnectionRouter.java21
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java265
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ReconnectBaseElementFeature.java40
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/ChoreographyUtil.java49
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/UpdateChoreographyParticipantRefsFeature.java2
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractAddFlowFeature.java11
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractCreateFlowFeature.java28
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/messages.properties6
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/model/ModelHandler.java6
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorSite.java (renamed from plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorLocation.java)68
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorType.java18
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java680
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/BusinessObjectUtil.java18
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java8
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/GraphicsUtil.java66
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/diagram/BPMN2FeatureProvider.java4
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/ConnectionLayerClippingStrategy.java12
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/AddChoreographyMessageFeature.java186
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyMessageLinkFeatureContainer.java106
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographySelectionBehavior.java17
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyTaskFeatureContainer.java13
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/Messages.java1
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/RemoveChoreographyMessageFeature.java89
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/UpdateChoreographyMessageLinkFeature.java143
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/messages.properties1
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/MessageFeatureContainer.java6
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/AssociationFeatureContainer.java132
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/DataAssociationFeatureContainer.java23
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/MessageFlowFeatureContainer.java81
38 files changed, 1609 insertions, 1311 deletions
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIImport.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIImport.java
index 36f3fa94..657b6782 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIImport.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIImport.java
@@ -56,7 +56,6 @@ import org.eclipse.bpmn2.modeler.core.model.ModelHandler;
import org.eclipse.bpmn2.modeler.core.preferences.Bpmn2Preferences;
import org.eclipse.bpmn2.modeler.core.preferences.ShapeStyle;
import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
-import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
import org.eclipse.bpmn2.modeler.core.utils.ModelUtil;
@@ -85,7 +84,6 @@ import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
-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;
@@ -888,33 +886,26 @@ public class DIImport {
private FixPointAnchor createAnchor(PictogramElement pictogramElement, BPMNEdge bpmnEdge, boolean isSource) {
FixPointAnchor anchor;
- if (pictogramElement instanceof FreeFormConnection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(featureProvider,
- (FreeFormConnection)pictogramElement,
- Graphiti.getPeLayoutService().getConnectionMidpoint((FreeFormConnection)pictogramElement, 0.5));
- anchor = AnchorUtil.getConnectionPointAnchor(connectionPointShape);
- }
- else
- {
- Point waypoint = null;
- if (isSource) {
- waypoint = bpmnEdge.getWaypoint().get(0);
- }
- else {
- waypoint = bpmnEdge.getWaypoint().get(bpmnEdge.getWaypoint().size()-1);
- }
-
- int x = (int)waypoint.getX();
- int y = (int)waypoint.getY();
- org.eclipse.graphiti.mm.algorithms.styles.Point anchorPoint = gaService.createPoint(x,y);
-
- // Some tools generate Edges that have their origin or destination waypoint at the center
- // of the source/target shape. Adjust these locations so that they are at the edge of
- // the shape.
- //
- // TODO: Figure out a way to maintain the original waypoint locations and still
- // support the connection line routers. This will require a major rewrite of the
- // whole anchor management ("anger management"?) scheme.
+ Point waypoint = null;
+ if (isSource) {
+ waypoint = bpmnEdge.getWaypoint().get(0);
+ }
+ else {
+ waypoint = bpmnEdge.getWaypoint().get(bpmnEdge.getWaypoint().size()-1);
+ }
+
+ int x = (int)waypoint.getX();
+ int y = (int)waypoint.getY();
+ org.eclipse.graphiti.mm.algorithms.styles.Point anchorPoint = gaService.createPoint(x,y);
+
+ // Some tools generate Edges that have their origin or destination waypoint at the center
+ // of the source/target shape. Adjust these locations so that they are at the edge of
+ // the shape.
+ //
+ // TODO: Figure out a way to maintain the original waypoint locations and still
+ // support the connection line routers. This will require a major rewrite of the
+ // whole anchor management ("anger management"?) scheme.
+ if (pictogramElement instanceof Shape) {
if (GraphicsUtil.contains((Shape)pictogramElement, anchorPoint)) {
// Only do this if the waypoint is "near" the center; "near" was arbitrarily chosen
// to mean within 3/4 of the shape's smallest dimension
@@ -935,30 +926,12 @@ public class DIImport {
anchorPoint = gaService.createPoint(x,y);
}
}
-
- anchor = AnchorUtil.createAnchor((AnchorContainer)pictogramElement, anchorPoint);
}
+
+ anchor = AnchorUtil.createAnchor((AnchorContainer)pictogramElement, anchorPoint);
+
return anchor;
}
-
-// private void setAnchorLocation(PictogramElement elem, FixPointAnchor anchor, Point point) {
-// org.eclipse.graphiti.mm.algorithms.styles.Point p = gaService.createPoint((int) point.getX(),
-// (int) point.getY());
-//
-// ILocation loc;
-// if (elem instanceof Connection)
-// loc = Graphiti.getPeLayoutService().getConnectionMidpoint((Connection)elem, 0.5);
-// else
-// loc = Graphiti.getPeLayoutService().getLocationRelativeToDiagram((Shape) elem);
-//
-// int x = p.getX() - loc.getX();
-// int y = p.getY() - loc.getY();
-//
-// p.setX(x);
-// p.setY(y);
-//
-// anchor.setLocation(p);
-// }
private boolean canAdd(IAddFeature addFeature, AddContext context) {
if (addFeature==null)
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AutomaticConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AutomaticConnectionRouter.java
index b7374ea7..0c1806db 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AutomaticConnectionRouter.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AutomaticConnectionRouter.java
@@ -16,7 +16,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.eclipse.bpmn2.modeler.core.utils.AnchorLocation;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
import org.eclipse.bpmn2.modeler.core.utils.AnchorType;
import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
@@ -54,6 +54,9 @@ public class AutomaticConnectionRouter extends BendpointConnectionRouter {
return calculateSelfConnectionRoute();
}
+GraphicsUtil.debug = false;
+
+ boolean initialUpdate = (peService.getPropertyValue(ffc, GraphitiConstants.INITIAL_UPDATE) != null);
Point start = null;
Point end = null;
Point middle = null;
@@ -66,70 +69,59 @@ public class AutomaticConnectionRouter extends BendpointConnectionRouter {
// Calculate all possible routes: this iterates over every permutation
// of 4 sides for both source and target shape
+ AnchorSite sourceSite = AnchorSite.getSite(sourceAnchor);
+ AnchorSite targetSite = AnchorSite.getSite(targetAnchor);
+ AnchorSite initialSourceSite = sourceSite;
+ AnchorSite initialTargetSite = targetSite;
for (int i=0; i<16; ++i) {
- ConnectionRoute route = new ConnectionRoute(this, allRoutes.size()+1, source,target);
- route.setSourceAnchor(sourceAnchor);
- route.setTargetAnchor(targetAnchor);
-
- start = GraphicsUtil.createPoint(sourceAnchor);
- end = GraphicsUtil.createPoint(targetAnchor);
-
- // if either the source or target anchor is a "Pool" anchor (i.e. attached to a Pool)
- // then try to move it so it lines up either vertically or horizontally with the other
- // anchor.
- if (AnchorType.getType(sourceAnchor) == AnchorType.POOL) {
- AnchorUtil.moveAnchor(sourceAnchor, middle==null ? end : middle);
+ if (shouldCalculate(sourceSite, targetSite)) {
+ AnchorSite.setSite(sourceAnchor, sourceSite);
+ AnchorUtil.adjustAnchors(source);
+ AnchorSite.setSite(targetAnchor, targetSite);
+ AnchorUtil.adjustAnchors(target);
+
+ ConnectionRoute route = new ConnectionRoute(this, allRoutes.size()+1, source,target);
+
start = GraphicsUtil.createPoint(sourceAnchor);
- }
- else if (AnchorType.getType(targetAnchor) == AnchorType.POOL) {
- AnchorUtil.moveAnchor(targetAnchor, start);
end = GraphicsUtil.createPoint(targetAnchor);
- }
-
- calculateRoute(route, start,middle,end);
- allRoutes.add(route);
-
- if ((i % 4)==0) {
- switch (AnchorLocation.getLocation(sourceAnchor)) {
- case BOTTOM:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.LEFT);
- break;
- case CENTER:
- break;
- case LEFT:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.RIGHT);
- break;
- case RIGHT:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.TOP);
- break;
- case TOP:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.BOTTOM);
- break;
- default:
- break;
+
+ // If either the source or target anchor is a "Pool" anchor
+ // (i.e. attached to a Pool) then try to move it so it lines
+ // up either vertically or horizontally with the other anchor.
+ // This is only done for these conditions:
+ // 1. this is an initial update, i.e. the Connection has just been created
+ // 2. the Connection was manually moved
+ // 3. the edge to which the Connection was attached has changed
+ if (initialUpdate || middle!=null ||
+ sourceSite!=initialSourceSite || targetSite!=initialTargetSite) {
+ if (AnchorType.getType(sourceAnchor) == AnchorType.POOL) {
+ if (middle!=null)
+ AnchorUtil.moveAnchor(sourceAnchor, middle);
+ else
+ AnchorUtil.moveAnchor(sourceAnchor, targetAnchor);
+ start = GraphicsUtil.createPoint(sourceAnchor);
+ route.setRank(sourceSite!=initialSourceSite ? 3 : 0);
+ }
+ if (AnchorType.getType(targetAnchor) == AnchorType.POOL) {
+ if (middle!=null)
+ AnchorUtil.moveAnchor(targetAnchor, middle);
+ else
+ AnchorUtil.moveAnchor(targetAnchor, sourceAnchor);
+ end = GraphicsUtil.createPoint(targetAnchor);
+ route.setRank(targetSite!=initialTargetSite ? 3 : 0);
+ }
}
- AnchorUtil.relocateAnchors(source);
+ route.setSourceAnchor(sourceAnchor);
+ route.setTargetAnchor(targetAnchor);
+
+ calculateRoute(route, start,middle,end);
+ allRoutes.add(route);
+ }
+ if ((i % 4)==0) {
+ sourceSite = getNextAnchorSite(sourceSite);
}
else {
- switch (AnchorLocation.getLocation(targetAnchor)) {
- case BOTTOM:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.LEFT);
- break;
- case CENTER:
- break;
- case LEFT:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.RIGHT);
- break;
- case RIGHT:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.TOP);
- break;
- case TOP:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.BOTTOM);
- break;
- default:
- break;
- }
- AnchorUtil.relocateAnchors(target);
+ targetSite = getNextAnchorSite(targetSite);
}
}
@@ -148,7 +140,7 @@ public class AutomaticConnectionRouter extends BendpointConnectionRouter {
Point p1 = r.getPoints().get(0);
for (int i=1; i<r.getPoints().size(); ++i) {
Point p2 = r.getPoints().get(i);
- List<Connection> crossings = findCrossings(p1, p2);
+ List<Connection> crossings = findCrossings(connection, p1, p2);
for (Connection c : crossings) {
if (c!=this.connection)
r.addCrossing(c, p1, p2);
@@ -170,7 +162,8 @@ public class AutomaticConnectionRouter extends BendpointConnectionRouter {
drawConnectionRoutes(allRoutes);
- route = allRoutes.get(0);
+ if (allRoutes.size()>0)
+ route = allRoutes.get(0);
return route;
}
@@ -202,7 +195,8 @@ public class AutomaticConnectionRouter extends BendpointConnectionRouter {
// navigate around this shape
DetourPoints detour = new DetourPoints(shape, margin);
for (Point d : detour.calculateDetour(p1, p2)) {
- route.add(d);
+ if (!route.add(d))
+ return route;
}
p1 = route.get(route.size() - 1);
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/BendpointConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/BendpointConnectionRouter.java
index 69dfbb17..fdbe700b 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/BendpointConnectionRouter.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/BendpointConnectionRouter.java
@@ -15,7 +15,7 @@ package org.eclipse.bpmn2.modeler.core.features;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.bpmn2.modeler.core.di.DIUtils;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
import org.eclipse.graphiti.datatypes.IDimension;
@@ -105,6 +105,7 @@ public class BendpointConnectionRouter extends DefaultConnectionRouter {
oldPoints.add(GraphicsUtil.createPoint(p));
}
oldPoints.add(GraphicsUtil.createPoint(ffc.getEnd()));
+ calculateAllowedAnchorSites();
}
/**
@@ -240,7 +241,22 @@ public class BendpointConnectionRouter extends DefaultConnectionRouter {
*/
protected void applyRoute(ConnectionRoute route) {
route.apply(ffc, sourceAnchor, targetAnchor);
- DIUtils.updateDIEdge(ffc);
+ }
+
+ protected AnchorSite getNextAnchorSite(AnchorSite site) {
+ switch (site) {
+ case BOTTOM:
+ return AnchorSite.LEFT;
+ case LEFT:
+ return AnchorSite.RIGHT;
+ case RIGHT:
+ return AnchorSite.TOP;
+ case TOP:
+ return AnchorSite.BOTTOM;
+ case CENTER:
+ return AnchorSite.CENTER;
+ }
+ return site;
}
/**
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ConnectionRoute.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ConnectionRoute.java
index 91bac219..356d2367 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ConnectionRoute.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ConnectionRoute.java
@@ -15,7 +15,7 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.bpmn2.modeler.core.utils.AnchorLocation;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
@@ -26,6 +26,7 @@ import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
/**
* The Class ConnectionRoute.
@@ -101,34 +102,50 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
}
/** The router. */
- DefaultConnectionRouter router;
+ private DefaultConnectionRouter router;
/** The route id. */
- int id;
+ private int id;
private List<Point> points = new ArrayList<Point>();
private List<Point> special = new ArrayList<Point>();
/** The list of shape collisions. */
- List<Collision> collisions = new ArrayList<Collision>();
+ private List<Collision> collisions = new ArrayList<Collision>();
/** The list of connection crossings. */
- List<Crossing> crossings = new ArrayList<Crossing>();
+ private List<Crossing> crossings = new ArrayList<Crossing>();
/** The source shape of the route being calculated. */
- Shape source;
+ private Shape source;
/** The Source Anchor Location for this Route */
- public AnchorLocation sourceAnchorLocation;
+ private AnchorSite sourceAnchorSite;
+ private Point sourceAnchorLocation;
/** The target shape of the route being calculated. */
- Shape target;
+ private Shape target;
/** The Target Anchor Location for this Route */
- public AnchorLocation targetAnchorLocation;
+ private AnchorSite targetAnchorSite;
+ private Point targetAnchorLocation;
- boolean valid = true;
+ private boolean valid = true;
private int rank = 0;
/**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
* Instantiates a new connection route.
*
* @param router the router
@@ -138,7 +155,7 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
*/
public ConnectionRoute(DefaultConnectionRouter router, int id, Shape source, Shape target) {
this.router = router;
- this.id = id;
+ this.setId(id);
this.source = source;
this.target = target;
}
@@ -169,8 +186,11 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
}
else {
AnchorUtil.moveAnchor(sourceAnchor, p);
- if (sourceAnchorLocation!=null)
- AnchorLocation.setLocation(sourceAnchor, sourceAnchorLocation);
+ if (sourceAnchorSite!=null) {
+ AnchorUtil.moveAnchor(sourceAnchor, sourceAnchorLocation);
+ AnchorSite.setSite(sourceAnchor, sourceAnchorSite);
+ AnchorUtil.adjustAnchors(source);
+ }
}
p = get(size() - 1);
@@ -182,8 +202,11 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
}
else {
AnchorUtil.moveAnchor(targetAnchor, p);
- if (targetAnchorLocation!=null)
- AnchorLocation.setLocation(targetAnchor, targetAnchorLocation);
+ if (targetAnchorSite!=null) {
+ AnchorUtil.moveAnchor(targetAnchor, targetAnchorLocation);
+ AnchorSite.setSite(targetAnchor, targetAnchorSite);
+ AnchorUtil.adjustAnchors(target);
+ }
}
// add the bendpoints
@@ -198,51 +221,58 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
*/
public String toString() {
String text;
- if (isValid()) {
-// BoundaryAnchor sa = AnchorUtil.findNearestBoundaryAnchor(source, get(0));
-// BoundaryAnchor ta = AnchorUtil.findNearestBoundaryAnchor(target, get(size()-1));
- int size = getPoints().size();
- Point p0 = size==0 ? null : getPoints().get(0);
- Point p1 = size==0 ? null : getPoints().get(size-1);
- String start = p0==null ? "null" : p0.getX()+","+p0.getY();
- String end = p1==null ? "null" : p1.getX()+","+p1.getY();
-
- text = id+(valid?"" : " invalid")+
- ": length="+getLength()+" points="+getPoints().size() + //$NON-NLS-1$ //$NON-NLS-2$
- " source="+sourceAnchorLocation+" "+start+ //$NON-NLS-1$ //$NON-NLS-2$
- " target="+targetAnchorLocation+" "+end; //$NON-NLS-1$ //$NON-NLS-2$
- if (collisions.size()>0) {
- text += " collisions="; //$NON-NLS-1$
- Iterator<Collision> iter=collisions.iterator();
- while (iter.hasNext()) {
- Collision c = iter.next();
- text += "'" + c.toString() + "'"; //$NON-NLS-1$ //$NON-NLS-2$
- if (iter.hasNext())
- text += ", "; //$NON-NLS-1$
- }
+ int size = getPoints().size();
+ Point p0 = size==0 ? null : getPoints().get(0);
+ Point p1 = size==0 ? null : getPoints().get(size-1);
+ String start = p0==null ? "null" : p0.getX()+","+p0.getY();
+ String end = p1==null ? "null" : p1.getX()+","+p1.getY();
+
+ text = getId()+(valid?" :" : "X:")+
+ " rank="+rank+
+ " length="+getLength()+
+ " points="+getPoints().size() + //$NON-NLS-1$ //$NON-NLS-2$
+ " source="+sourceAnchorSite+" "+start+ //$NON-NLS-1$ //$NON-NLS-2$
+ " target="+targetAnchorSite+" "+end; //$NON-NLS-1$ //$NON-NLS-2$
+ if (collisions.size()>0) {
+ text += " collisions="; //$NON-NLS-1$
+ Iterator<Collision> iter=collisions.iterator();
+ while (iter.hasNext()) {
+ Collision c = iter.next();
+ text += "'" + c.toString() + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+ if (iter.hasNext())
+ text += ", "; //$NON-NLS-1$
}
- if (crossings.size()>0) {
- text += " crossings="; //$NON-NLS-1$
- Iterator<Crossing> iter=crossings.iterator();
- while (iter.hasNext()) {
- Crossing c = iter.next();
- text += "'" + c.toString() + "'"; //$NON-NLS-1$ //$NON-NLS-2$
- if (iter.hasNext())
- text += ", "; //$NON-NLS-1$
- }
+ }
+ if (crossings.size()>0) {
+ text += " crossings="; //$NON-NLS-1$
+ Iterator<Crossing> iter=crossings.iterator();
+ while (iter.hasNext()) {
+ Crossing c = iter.next();
+ text += "'" + c.toString() + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+ if (iter.hasNext())
+ text += ", "; //$NON-NLS-1$
}
}
- else
- text = "not valid"; //$NON-NLS-1$
return text;
}
public void setSourceAnchor(FixPointAnchor sourceAnchor) {
- this.sourceAnchorLocation = AnchorLocation.getLocation(sourceAnchor);
+ this.sourceAnchorSite = AnchorSite.getSite(sourceAnchor);
+ this.sourceAnchorLocation = GraphicsUtil.createPoint(sourceAnchor);
+
}
public void setTargetAnchor(FixPointAnchor targetAnchor) {
- this.targetAnchorLocation = AnchorLocation.getLocation(targetAnchor);
+ this.targetAnchorSite = AnchorSite.getSite(targetAnchor);
+ this.targetAnchorLocation = GraphicsUtil.createPoint(targetAnchor);
+ }
+
+ public AnchorSite getSourceAnchorSite() {
+ return sourceAnchorSite;
+ }
+
+ public AnchorSite getTargetAnchorSite() {
+ return targetAnchorSite;
}
/**
@@ -254,7 +284,7 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
public boolean add(Point newPoint) {
for (Point p : getPoints()) {
if (GraphicsUtil.pointsEqual(newPoint, p)) {
- valid = false;
+ setValid(false);
return false;
}
}
@@ -324,8 +354,8 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
/**
* Sets the valid.
*/
- public void setValid() {
- valid = true;
+ public void setValid(boolean valid) {
+ this.valid = valid;
}
/**
@@ -378,30 +408,42 @@ public class ConnectionRoute implements Comparable<ConnectionRoute>, Comparator<
@Override
public int compare(ConnectionRoute o1, ConnectionRoute o2) {
int i = 0;
- if (o1.isValid()) {
- if (o2.isValid()) {
+ int v1 = o1.isValid() ? 1 : 0;
+ int v2 = o2.isValid() ? 1 : 0;
+ i = v2 - v1;
+ if (i==0) {
+ i = o1.collisions.size() - o2.collisions.size();
+ if (i==0) {
i = o1.getRank() - o2.getRank();
if (i==0) {
- i = o1.collisions.size() - o2.collisions.size();
+ i = o1.crossings.size() - o2.crossings.size();
if (i==0) {
- // TODO: figure out why connection crossing detection isn't working!
-// i = o1.crossings.size() - o2.crossings.size();
- if (i==0) {
- i = o1.getLength() - o2.getLength();
- if (i==0)
- {
- i = o1.getPoints().size() - o2.getPoints().size();
- }
+ i = o1.getLength() - o2.getLength();
+ if (i==0)
+ {
+ i = o1.getPoints().size() - o2.getPoints().size();
}
}
}
- return i;
+// else {
+// // pick the shorter route
+// float dl = Math.abs(o1.getLength() - o2.getLength());
+// float sl = (o1.getLength() + o2.getLength()) / 2;
+// dl = dl/sl;
+// if ( dl > 0.5)
+// return o1.getLength() - o2.getLength();
+// }
}
- return -1;
}
- else if (!o2.isValid())
- return 0;
- return 1;
+ else {
+ // pick the shorter route
+ float dl = Math.abs(o1.getLength() - o2.getLength());
+ float sl = (o1.getLength() + o2.getLength()) / 2;
+ dl = dl/sl;
+ if ( dl > 0.5)
+ return o1.getLength() - o2.getLength();
+ }
+ return i;
}
private boolean removeUnusedPoints() {
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java
index d8fc1da1..51ac9ac8 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java
@@ -18,14 +18,22 @@ import java.util.Comparator;
import java.util.List;
import org.eclipse.bpmn2.BaseElement;
+import org.eclipse.bpmn2.BoundaryEvent;
import org.eclipse.bpmn2.FlowElementsContainer;
import org.eclipse.bpmn2.Lane;
import org.eclipse.bpmn2.di.BPMNShape;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorType;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
+import org.eclipse.bpmn2.modeler.core.utils.BoundaryEventPositionHelper;
+import org.eclipse.bpmn2.modeler.core.utils.BoundaryEventPositionHelper.PositionOnLine;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.graphiti.datatypes.IDimension;
+import org.eclipse.graphiti.datatypes.ILocation;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
@@ -36,6 +44,7 @@ import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
@@ -69,6 +78,10 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter {
/** The target anchor. */
protected FixPointAnchor sourceAnchor, targetAnchor;
+
+ AnchorSite sourceAnchorSites[];
+
+ AnchorSite targetAnchorSites[];
/**
* Instantiates a new default connection router.
@@ -87,16 +100,31 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter {
this.connection = connection;
this.sourceAnchor = (FixPointAnchor) connection.getStart();
this.targetAnchor = (FixPointAnchor) connection.getEnd();
- this.source = (Shape) sourceAnchor.getParent();
- this.target = (Shape) targetAnchor.getParent();
+ this.source = (Shape) AnchorUtil.getAnchorContainer(sourceAnchor);
+ this.target = (Shape) AnchorUtil.getAnchorContainer(targetAnchor);
return false;
}
/* (non-Javadoc)
+ * @see org.eclipse.bpmn2.modeler.core.features.IConnectionRouter#canRoute(org.eclipse.graphiti.mm.pictograms.Connection)
+ */
+ @Override
+ public boolean canRoute(Connection connection) {
+ // don't touch Choreography Task Message Links.
+ AnchorContainer ac = AnchorUtil.getAnchorContainer(connection.getStart());
+ if (AnchorType.getType(ac) == AnchorType.MESSAGELINK)
+ return false;
+ ac = AnchorUtil.getAnchorContainer(connection.getEnd());
+ if (AnchorType.getType(ac) == AnchorType.MESSAGELINK)
+ return false;
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.bpmn2.modeler.core.features.IConnectionRouter#needsUpdate(org.eclipse.graphiti.mm.pictograms.Connection)
*/
@Override
- public boolean needsLayout(Connection connection) {
+ public boolean routingNeeded(Connection connection) {
return false;
}
@@ -246,38 +274,45 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter {
}
/**
- * Find crossings.
+ * Find Connection line crossings. This will return a list of all
+ * Connections on the Diagram that intersect any line segment of the given
+ * Connection. Connections that are attached to the given Connection are
+ * ignored.
*
- * @param start the start
- * @param end the end
- * @return the list
+ * @param connection the Connection to test.
+ * @param start the starting point of a line segment on the connection.
+ * @param end the ending point of the line segment.
+ * @return a list of Connections that cross over the line segment.
*/
- protected List<Connection> findCrossings(Point start, Point end) {
+ protected List<Connection> findCrossings(Connection connection, Point start, Point end) {
// TODO: figure out why this isn't working!
List<Connection> crossings = new ArrayList<Connection>();
List<Connection> allConnections = fp.getDiagramTypeProvider().getDiagram().getConnections();
- for (Connection connection : allConnections) {
- if (Graphiti.getPeService().getProperty(connection, RoutingNet.CONNECTION)!=null) {
+ List<FixPointAnchor> connectionAnchors = AnchorUtil.getAnchors(connection);
+ for (Connection c : allConnections) {
+ if (Graphiti.getPeService().getProperty(c, RoutingNet.CONNECTION)!=null) {
continue;
}
- Point p1 = GraphicsUtil.createPoint(connection.getStart());
- Point p3 = GraphicsUtil.createPoint(connection.getEnd());
- if (connection instanceof FreeFormConnection) {
- FreeFormConnection ffc = (FreeFormConnection) connection;
+ if (connectionAnchors.contains(c.getStart()) || connectionAnchors.contains(c.getEnd()))
+ continue;
+ Point p1 = GraphicsUtil.createPoint(c.getStart());
+ Point p3 = GraphicsUtil.createPoint(c.getEnd());
+ if (c instanceof FreeFormConnection) {
+ FreeFormConnection ffc = (FreeFormConnection) c;
Point p2 = p1;
for (Point p : ffc.getBendpoints()) {
if (GraphicsUtil.intersects(start, end, p1, p)) {
- crossings.add(connection);
+ crossings.add(c);
break;
}
p2 = p1 = p;
}
if (GraphicsUtil.intersects(start, end, p2, p3)) {
- crossings.add(connection);
+ crossings.add(c);
}
}
else if (GraphicsUtil.intersects(start, end, p1, p3)) {
- crossings.add(connection);
+ crossings.add(c);
}
}
return crossings;
@@ -321,6 +356,229 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter {
}
}
+ protected void calculateAllowedAnchorSites() {
+
+ EObject bo = BusinessObjectUtil.getBusinessObjectForPictogramElement(source);
+ if (bo instanceof BoundaryEvent) {
+ sourceAnchorSites = calculateBoundaryEventAnchorSites(source);
+ }
+ bo = BusinessObjectUtil.getBusinessObjectForPictogramElement(target);
+ if (bo instanceof BoundaryEvent) {
+ targetAnchorSites = calculateBoundaryEventAnchorSites(target);
+ }
+ if (AnchorType.getType(source) == AnchorType.CONNECTION) {
+ sourceAnchorSites = new AnchorSite[1];
+ sourceAnchorSites[0] = AnchorSite.CENTER;
+ }
+ if (AnchorType.getType(target) == AnchorType.CONNECTION) {
+ targetAnchorSites = new AnchorSite[1];
+ targetAnchorSites[0] = AnchorSite.CENTER;
+ }
+ ILocation sPos = Graphiti.getPeService().getLocationRelativeToDiagram(source);
+ IDimension sSize = GraphicsUtil.calculateSize(source);
+ ILocation tPos = Graphiti.getPeService().getLocationRelativeToDiagram(target);
+ IDimension tSize = GraphicsUtil.calculateSize(target);
+ // find relative locations
+ if (sPos.getX()+sSize.getWidth() < tPos.getX()) {
+ // source shape is to left of target
+ if (sPos.getY()+sSize.getHeight() < tPos.getY()) {
+ // source shape is to left and above target:
+ // omit the two opposite sides of both source and target
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[2];
+ sourceAnchorSites[0] = AnchorSite.RIGHT;
+ sourceAnchorSites[1] = AnchorSite.BOTTOM;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[2];
+ targetAnchorSites[0] = AnchorSite.LEFT;
+ targetAnchorSites[1] = AnchorSite.TOP;
+ }
+ }
+ else if(sPos.getY() > tPos.getY()+tSize.getHeight()) {
+ // source shape is to left and below target
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[2];
+ sourceAnchorSites[0] = AnchorSite.RIGHT;
+ sourceAnchorSites[1] = AnchorSite.TOP;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[2];
+ targetAnchorSites[0] = AnchorSite.LEFT;
+ targetAnchorSites[1] = AnchorSite.BOTTOM;
+ }
+ }
+ else {
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[3];
+ sourceAnchorSites[0] = AnchorSite.RIGHT;
+ sourceAnchorSites[1] = AnchorSite.TOP;
+ sourceAnchorSites[2] = AnchorSite.BOTTOM;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[3];
+ targetAnchorSites[0] = AnchorSite.LEFT;
+ targetAnchorSites[1] = AnchorSite.TOP;
+ targetAnchorSites[2] = AnchorSite.BOTTOM;
+ }
+ }
+ }
+ else if (sPos.getX() > tPos.getX()+tSize.getWidth()) {
+ // source shape is to right of target
+ if (sPos.getY()+sSize.getHeight() < tPos.getY()) {
+ // source shape is to right and above target
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[2];
+ sourceAnchorSites[0] = AnchorSite.LEFT;
+ sourceAnchorSites[1] = AnchorSite.BOTTOM;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[2];
+ targetAnchorSites[0] = AnchorSite.RIGHT;
+ targetAnchorSites[1] = AnchorSite.TOP;
+ }
+ }
+ else if(sPos.getY() > tPos.getY()+tSize.getHeight()) {
+ // source shape is to right and below target
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[2];
+ sourceAnchorSites[0] = AnchorSite.LEFT;
+ sourceAnchorSites[1] = AnchorSite.TOP;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[2];
+ targetAnchorSites[0] = AnchorSite.RIGHT;
+ targetAnchorSites[1] = AnchorSite.BOTTOM;
+ }
+ }
+ else {
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[3];
+ sourceAnchorSites[0] = AnchorSite.LEFT;
+ sourceAnchorSites[1] = AnchorSite.TOP;
+ sourceAnchorSites[2] = AnchorSite.BOTTOM;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[3];
+ targetAnchorSites[0] = AnchorSite.RIGHT;
+ targetAnchorSites[1] = AnchorSite.TOP;
+ targetAnchorSites[2] = AnchorSite.BOTTOM;
+ }
+ }
+ }
+ else if (sPos.getY()+sSize.getHeight() < tPos.getY()) {
+ // source shape is above target
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[3];
+ sourceAnchorSites[0] = AnchorSite.LEFT;
+ sourceAnchorSites[1] = AnchorSite.RIGHT;
+ sourceAnchorSites[2] = AnchorSite.BOTTOM;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[3];
+ targetAnchorSites[0] = AnchorSite.LEFT;
+ targetAnchorSites[1] = AnchorSite.RIGHT;
+ targetAnchorSites[2] = AnchorSite.TOP;
+ }
+ }
+ else if(sPos.getY() > tPos.getY()+tSize.getHeight()) {
+ // source shape is below target
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[3];
+ sourceAnchorSites[0] = AnchorSite.LEFT;
+ sourceAnchorSites[1] = AnchorSite.RIGHT;
+ sourceAnchorSites[2] = AnchorSite.TOP;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[3];
+ targetAnchorSites[0] = AnchorSite.LEFT;
+ targetAnchorSites[1] = AnchorSite.RIGHT;
+ targetAnchorSites[2] = AnchorSite.BOTTOM;
+ }
+ }
+ else {
+ // source and target overlap
+ if (sourceAnchorSites==null) {
+ sourceAnchorSites = new AnchorSite[4];
+ sourceAnchorSites[0] = AnchorSite.LEFT;
+ sourceAnchorSites[1] = AnchorSite.RIGHT;
+ sourceAnchorSites[2] = AnchorSite.TOP;
+ sourceAnchorSites[3] = AnchorSite.BOTTOM;
+ }
+ if (targetAnchorSites==null) {
+ targetAnchorSites = new AnchorSite[4];
+ targetAnchorSites[0] = AnchorSite.LEFT;
+ targetAnchorSites[1] = AnchorSite.RIGHT;
+ targetAnchorSites[2] = AnchorSite.TOP;
+ targetAnchorSites[3] = AnchorSite.BOTTOM;
+ }
+ }
+ }
+
+ protected AnchorSite[] calculateBoundaryEventAnchorSites(Shape shape) {
+ AnchorSite sites[];
+ PositionOnLine pol = BoundaryEventPositionHelper.getPositionOnLineProperty(shape);
+ switch (pol.getLocationType()) {
+ case BOTTOM:
+ sites = new AnchorSite[1];
+ sites[0] = AnchorSite.BOTTOM;
+ break;
+ case BOTTOM_LEFT:
+ sites = new AnchorSite[2];
+ sites[0] = AnchorSite.BOTTOM;
+ sites[1] = AnchorSite.LEFT;
+ break;
+ case BOTTOM_RIGHT:
+ sites = new AnchorSite[2];
+ sites[0] = AnchorSite.BOTTOM;
+ sites[1] = AnchorSite.RIGHT;
+ break;
+ case LEFT:
+ sites = new AnchorSite[1];
+ sites[0] = AnchorSite.LEFT;
+ break;
+ case RIGHT:
+ sites = new AnchorSite[1];
+ sites[0] = AnchorSite.RIGHT;
+ break;
+ case TOP:
+ sites = new AnchorSite[1];
+ sites[0] = AnchorSite.TOP;
+ break;
+ case TOP_LEFT:
+ sites = new AnchorSite[2];
+ sites[0] = AnchorSite.TOP;
+ sites[1] = AnchorSite.LEFT;
+ break;
+ case TOP_RIGHT:
+ sites = new AnchorSite[2];
+ sites[0] = AnchorSite.TOP;
+ sites[1] = AnchorSite.RIGHT;
+ break;
+ default:
+ sites = new AnchorSite[4];
+ sites[0] = AnchorSite.TOP;
+ sites[1] = AnchorSite.LEFT;
+ sites[2] = AnchorSite.BOTTOM;
+ sites[3] = AnchorSite.RIGHT;
+ break;
+ }
+ return sites;
+ }
+
+ protected boolean shouldCalculate(AnchorSite sourceSite, AnchorSite targetSite) {
+ for (int i=0; i<sourceAnchorSites.length; ++i) {
+ if (sourceSite == sourceAnchorSites[i]) {
+ for (int j=0; j<targetAnchorSites.length; ++j) {
+ if (targetSite == targetAnchorSites[j]) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
/**
* The Class AddRoutingConnectionFeature.
*/
@@ -365,7 +623,7 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter {
connection.getBendpoints().add(route.get(i));
}
- peService.setPropertyValue(connection, CONNECTION, "" + route.id); //$NON-NLS-1$
+ peService.setPropertyValue(connection, CONNECTION, "" + route.getId()); //$NON-NLS-1$
Polyline connectionLine = Graphiti.getGaService().createPolyline(
connection);
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultDeleteBPMNShapeFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultDeleteBPMNShapeFeature.java
index 8ed9429f..7675df6e 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultDeleteBPMNShapeFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultDeleteBPMNShapeFeature.java
@@ -34,7 +34,6 @@ import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
@@ -84,11 +83,9 @@ public class DefaultDeleteBPMNShapeFeature extends DefaultDeleteFeature {
// The PE being deleted is a Connection:
// if it has other connections connected to it,
// delete those as well.
- for (Shape shape : AnchorUtil.getConnectionPoints((Connection)pe)) {
- for (Anchor a : shape.getAnchors()) {
- connections.addAll(a.getIncomingConnections());
- connections.addAll(a.getOutgoingConnections());
- }
+ for (Anchor a : AnchorUtil.getAnchors((Connection)pe)) {
+ connections.addAll(a.getIncomingConnections());
+ connections.addAll(a.getOutgoingConnections());
}
for (Connection c : connections) {
DeleteContext dc = new DeleteContext(c);
@@ -97,8 +94,13 @@ public class DefaultDeleteBPMNShapeFeature extends DefaultDeleteFeature {
}
Connection connection = (Connection) pe;
- shapes.add(connection.getStart().getParent());
- shapes.add(connection.getEnd().getParent());
+ AnchorContainer ac;
+ ac = connection.getStart()==null ? null : connection.getStart().getParent();
+ if (ac!=null)
+ shapes.add(ac);
+ ac = connection.getEnd()==null ? null : connection.getEnd().getParent();
+ if (ac!=null)
+ shapes.add(ac);
}
super.delete(context);
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultLayoutBPMNConnectionFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultLayoutBPMNConnectionFeature.java
index 8f755cd9..89b5e937 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultLayoutBPMNConnectionFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultLayoutBPMNConnectionFeature.java
@@ -12,6 +12,8 @@
******************************************************************************/
package org.eclipse.bpmn2.modeler.core.features;
+import java.util.Hashtable;
+
import org.eclipse.bpmn2.BaseElement;
import org.eclipse.bpmn2.modeler.core.LifecycleEvent;
import org.eclipse.bpmn2.modeler.core.LifecycleEvent.EventType;
@@ -24,10 +26,12 @@ import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
/**
* Default Graphiti {@code LayoutFeature} class for Connections.
@@ -40,7 +44,9 @@ public class DefaultLayoutBPMNConnectionFeature extends AbstractLayoutFeature {
/** True if changes were made by this feature. */
boolean hasDoneChanges = false;
-
+ Diagram diagram;
+ Hashtable<Connection, IConnectionRouter> routers = new Hashtable<Connection, IConnectionRouter>();
+
/**
* Instantiates a new default layout bpmn connection feature.
*
@@ -88,58 +94,48 @@ public class DefaultLayoutBPMNConnectionFeature extends AbstractLayoutFeature {
public boolean layout(ILayoutContext context) {
if (canLayout(context)) {
Connection connection = (Connection) context.getPictogramElement();
- doLayout(connection);
- }
- return hasDoneChanges;
- }
-
- private int recursion = 0;
-
- private synchronized void doLayout(Connection connection) {
- if (++recursion < 10) {
- BaseElement be = BusinessObjectUtil.getFirstBaseElement(connection);
- if (be!=null) {
- // get the user preference of routing style for this connection
- ShapeStyle ss = ShapeStyle.getShapeStyle(be);
- if (ss!=null) {
- IFeatureProvider fp = getFeatureProvider();
- IConnectionRouter router = null;
- if (ss.getRoutingStyle() == RoutingStyle.MANHATTAN)
- router = new ManhattanConnectionRouter(fp);
- else if (ss.getRoutingStyle() == RoutingStyle.MANUAL) {
- router = new BendpointConnectionRouter(fp);
- }
- else if (ss.getRoutingStyle() == RoutingStyle.AUTOMATIC) {
- router = new AutomaticConnectionRouter(fp);
- }
-
- if (router!=null) {
- hasDoneChanges = router.route(connection);
-
- Diagram diagram = fp.getDiagramTypeProvider().getDiagram();
- for (Connection c : diagram.getConnections()) {
- if (needsLayout(c)) {
- doLayout(c);
- }
- }
-
- router.dispose();
-
+ if (context.getProperty(GraphitiConstants.INITIAL_UPDATE) == Boolean.TRUE)
+ Graphiti.getPeService().setPropertyValue(connection, GraphitiConstants.INITIAL_UPDATE, Boolean.TRUE.toString());
+ diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram();
+ // limit the number of iterations for recalculating other connections
+ int iterations = 0;
+ boolean repeat;
+ do {
+ repeat = false;
+ IConnectionRouter router = getRouter(connection);
+ hasDoneChanges |= router.route(connection);
+
+ UpdateContext uc = new UpdateContext(connection);
+ getFeatureProvider().updateIfPossible(uc);
+ for (Connection c : diagram.getConnections()) {
+ router = getRouter(c);
+ if (router.canRoute(c) && router.routingNeeded(c)) {
+ router.route(c);
+
+ uc = new UpdateContext(c);
+ getFeatureProvider().updateIfPossible(uc);
+
+ repeat = true;
}
}
}
- --recursion;
+ while (repeat && ++iterations < 3);
+ Graphiti.getPeService().removeProperty(connection, GraphitiConstants.INITIAL_UPDATE);
}
+ return hasDoneChanges;
}
- private boolean needsLayout(Connection connection) {
+ private IConnectionRouter getRouter(Connection connection) {
+ if (routers.containsKey(connection))
+ return routers.get(connection);
+
+ IConnectionRouter router = null;
+ IFeatureProvider fp = getFeatureProvider();
BaseElement be = BusinessObjectUtil.getFirstBaseElement(connection);
if (be!=null) {
// get the user preference of routing style for this connection
ShapeStyle ss = ShapeStyle.getShapeStyle(be);
if (ss!=null) {
- IFeatureProvider fp = getFeatureProvider();
- IConnectionRouter router = null;
if (ss.getRoutingStyle() == RoutingStyle.MANHATTAN)
router = new ManhattanConnectionRouter(fp);
else if (ss.getRoutingStyle() == RoutingStyle.MANUAL) {
@@ -148,12 +144,11 @@ public class DefaultLayoutBPMNConnectionFeature extends AbstractLayoutFeature {
else if (ss.getRoutingStyle() == RoutingStyle.AUTOMATIC) {
router = new AutomaticConnectionRouter(fp);
}
-
- if (router!=null) {
- return router.needsLayout(connection);
- }
}
}
- return false;
+ if (router==null)
+ router = new BendpointConnectionRouter(fp);
+ routers.put(connection, router);
+ return router;
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultResizeBPMNShapeFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultResizeBPMNShapeFeature.java
index a0502f0f..203164fd 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultResizeBPMNShapeFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultResizeBPMNShapeFeature.java
@@ -86,7 +86,7 @@ public class DefaultResizeBPMNShapeFeature extends DefaultResizeShapeFeature {
super.resizeShape(context);
if (shape!=null) {
- AnchorUtil.relocateAnchors(shape, context.getWidth(), context.getHeight());
+ AnchorUtil.adjustAnchors(shape);
}
DIUtils.updateDIShape(context.getPictogramElement());
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/GraphitiConstants.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/GraphitiConstants.java
index bfda60a3..86bcbeaf 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/GraphitiConstants.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/GraphitiConstants.java
@@ -255,16 +255,28 @@ public interface GraphitiConstants {
public static final String CONNECTION_BENDPOINTS = "connection.bendpoints"; //$NON-NLS-1$
- // the Anchor Type, one of the string values defined by {@see AnchorUtil$AnchorType}
+ /**
+ * The {@link FixPointAnchor} property key that indicates the Anchor Type,
+ * one of the string values defined by {@see AnchorUtil$AnchorType}
+ **/
public static final String ANCHOR_TYPE = "anchor.type";
- // the edge at which an anchor is located, one of the AnchorLocation enum values
+
+ /**
+ * The {@link FixPointAnchor} property key that indicates the edge on which
+ * anchor is located, one of the {@see AnchorSite} enum values
+ **/
public static final String ANCHOR_LOCATION = "anchor.location";
+
+ /**
+ * The {@link IContext} property key used by the {@link LayoutFeature} to
+ * indicate that a new Shape or Connection PictogramElement is first
+ * created. An initial update may require special handling.
+ **/
+ public static final String INITIAL_UPDATE = "initial.update";
// values for connection points
public static final String CONNECTION_POINT = "connection.point"; //$NON-NLS-1$
- public static final String CONNECTION_POINT_KEY = "connection.point.key"; //$NON-NLS-1$
-
public static final String EVENT_SUBPROCESS_DECORATOR = "event.subprocess.decorator";
public static final String IS_EXPANDED = "is.expanded"; //$NON-NLS-1$
@@ -273,4 +285,10 @@ public interface GraphitiConstants {
public static final String TRIGGERED_BY_EVENT = "triggered.by.event"; //$NON-NLS-1$
+ /**
+ * The {@link PictogramElement} property key that indicates the Shape or
+ * Connection is part of a Choreography Task Message Link i.e. an image of
+ * an envelope connected to a Participant band in a Choreography Task
+ **/
+ public final static String MESSAGE_LINK = "choreography.messageLink"; //$NON-NLS-1$
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/IConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/IConnectionRouter.java
index 02eb53f7..10c34993 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/IConnectionRouter.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/IConnectionRouter.java
@@ -29,14 +29,29 @@ public interface IConnectionRouter {
public static final String ROUTING_INFO_BENDPOINT = "bendpoint"; //$NON-NLS-1$
/**
- * Route.
+ * Perform connection routing.
*
- * @param connection the connection
+ * @param connection the Connection
* @return true, if successful
*/
public boolean route(Connection connection);
- public boolean needsLayout(Connection connection);
+ /**
+ * Check if the Connection allows routing.
+ *
+ * @param connection the Connection
+ * @return true if the Connection can be routed, false otherwise.
+ */
+ public boolean canRoute(Connection connection);
+
+ /**
+ * Check if the Connection needs to be rerouted after the
+ * source or target shapes have been moved.
+ *
+ * @param connection the Connection
+ * @return true if the Connection routing needs to be recalculated.
+ */
+ public boolean routingNeeded(Connection connection);
/**
* Dispose.
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java
index cbd7eebd..ca86c401 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java
@@ -16,13 +16,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.eclipse.bpmn2.modeler.core.di.DIUtils;
import org.eclipse.bpmn2.modeler.core.preferences.Bpmn2Preferences;
import org.eclipse.bpmn2.modeler.core.preferences.Bpmn2Preferences.BPMNDIAttributeDefault;
-import org.eclipse.bpmn2.modeler.core.utils.AnchorLocation;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
import org.eclipse.bpmn2.modeler.core.utils.AnchorType;
import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
+import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil.LineSegment;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
import org.eclipse.graphiti.mm.pictograms.Connection;
@@ -42,13 +42,12 @@ import org.eclipse.graphiti.mm.pictograms.Shape;
public class ManhattanConnectionRouter extends BendpointConnectionRouter {
/** The Constant offset. */
- static final int offset = 20;
+ static final int offset = 10;
/** The test route solver. */
static boolean testRouteSolver = false;
Orientation orientation;
-
/**
* The Orientation of next line segment being calculated.
*/
@@ -79,26 +78,27 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
}
@Override
- public boolean needsLayout(Connection connection) {
+ public boolean routingNeeded(Connection connection) {
if (connection instanceof FreeFormConnection) {
FreeFormConnection ffc = (FreeFormConnection) connection;
- List<Point> points = new ArrayList<Point>();
- points.add(GraphicsUtil.createPoint(ffc.getStart()));
- points.addAll(ffc.getBendpoints());
- points.add(GraphicsUtil.createPoint(ffc.getEnd()));
- Point p0 = points.get(0);
- for (int i=1; i<points.size(); ++i) {
- Point p1 = points.get(i);
+ Point p0 = GraphicsUtil.createPoint(ffc.getStart());
+ Point p1;
+ for (int i=0; i<ffc.getBendpoints().size(); ++i) {
+ p1 = ffc.getBendpoints().get(i);
if (!(GraphicsUtil.isHorizontal(p0, p1) || GraphicsUtil.isVertical(p0, p1))) {
return true;
}
p0 = p1;
}
+ p1 = GraphicsUtil.createPoint(ffc.getEnd());
+ if (!(GraphicsUtil.isHorizontal(p0, p1) || GraphicsUtil.isVertical(p0, p1))) {
+ return true;
+ }
}
return false;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.bpmn2.modeler.core.features.BendpointConnectionRouter#calculateRoute()
*/
@@ -108,6 +108,9 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
if (isSelfConnection())
return super.calculateRoute();
+GraphicsUtil.debug = false;
+
+ boolean initialUpdate = (peService.getPropertyValue(ffc, GraphitiConstants.INITIAL_UPDATE) != null);
Point start = null;
Point end = null;
Point middle = null;
@@ -126,73 +129,83 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
// Calculate all possible routes: this iterates over every permutation
// of 4 sides for both source and target shape
+ AnchorSite sourceSite = AnchorSite.getSite(sourceAnchor);
+ AnchorSite targetSite = AnchorSite.getSite(targetAnchor);
+ AnchorSite initialSourceSite = sourceSite;
+ AnchorSite initialTargetSite = targetSite;
for (int i=0; i<16; ++i) {
- ConnectionRoute route = new ConnectionRoute(this, allRoutes.size()+1, source,target);
- route.setSourceAnchor(sourceAnchor);
- route.setTargetAnchor(targetAnchor);
-
- start = GraphicsUtil.createPoint(sourceAnchor);
- end = GraphicsUtil.createPoint(targetAnchor);
-
- // if either the source or target anchor is a "Pool" anchor (i.e. attached to a Pool)
- // then try to move it so it lines up either vertically or horizontally with the other
- // anchor.
- if (AnchorType.getType(sourceAnchor) == AnchorType.POOL) {
- AnchorUtil.moveAnchor(sourceAnchor, end);
+ if (shouldCalculate(sourceSite, targetSite)) {
+ AnchorSite.setSite(sourceAnchor, sourceSite);
+ AnchorUtil.adjustAnchors(source);
+ AnchorSite.setSite(targetAnchor, targetSite);
+ AnchorUtil.adjustAnchors(target);
+
+ ConnectionRoute route = new ConnectionRoute(this, allRoutes.size()+1, source,target);
+
+ // Introduce some hysteresis by favoring routes that do not have
+ // to change the Anchor Site. Changing Anchor Sites from
+ // one edge of an Activity shape to another may cause a relocation
+ // of existing anchors on the Activity which may result in having
+ // to recalculate the route for those connections.
+// if (sourceSite!=initialSourceSite) {
+// if (targetSite!=initialTargetSite)
+// route.setRank(1);
+// else
+// route.setRank(1);
+// }
+// else if (targetSite!=initialTargetSite) {
+// route.setRank(1);
+// }
+
+ // Get the starting and ending points on the (possibly relocated)
+ // source and target anchors.
start = GraphicsUtil.createPoint(sourceAnchor);
- }
- else if (AnchorType.getType(targetAnchor) == AnchorType.POOL) {
- AnchorUtil.moveAnchor(targetAnchor, start);
end = GraphicsUtil.createPoint(targetAnchor);
+
+ // If either the source or target anchor is a "Pool" anchor
+ // (i.e. attached to a Pool) then try to move it so it lines
+ // up either vertically or horizontally with the other anchor.
+ // This is only done for these conditions:
+ // 1. this is an initial update, i.e. the Connection has just been created
+ // 2. the Connection was manually moved
+ // 3. the edge to which the Connection was attached has changed
+ if (initialUpdate || middle!=null ||
+ sourceSite!=initialSourceSite || targetSite!=initialTargetSite) {
+ if (AnchorType.getType(sourceAnchor) == AnchorType.POOL) {
+ if (middle!=null)
+ AnchorUtil.moveAnchor(sourceAnchor, middle);
+ else
+ AnchorUtil.moveAnchor(sourceAnchor, targetAnchor);
+ start = GraphicsUtil.createPoint(sourceAnchor);
+ route.setRank(sourceSite!=initialSourceSite ? 3 : 0);
+ }
+ if (AnchorType.getType(targetAnchor) == AnchorType.POOL) {
+ if (middle!=null)
+ AnchorUtil.moveAnchor(targetAnchor, middle);
+ else
+ AnchorUtil.moveAnchor(targetAnchor, sourceAnchor);
+ end = GraphicsUtil.createPoint(targetAnchor);
+ route.setRank(targetSite!=initialTargetSite ? 3 : 0);
+ }
+ }
+ route.setSourceAnchor(sourceAnchor);
+ route.setTargetAnchor(targetAnchor);
+
+ calculateRoute(route, source,start,middle,target,end, orientation);
+
+ allRoutes.add(route);
}
-
- calculateRoute(route, source,start,middle,target,end, orientation);
- allRoutes.add(route);
if ((i % 4)==0) {
- switch (AnchorLocation.getLocation(sourceAnchor)) {
- case BOTTOM:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.LEFT);
- break;
- case CENTER:
- break;
- case LEFT:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.RIGHT);
- break;
- case RIGHT:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.TOP);
- break;
- case TOP:
- AnchorLocation.setLocation(sourceAnchor, AnchorLocation.BOTTOM);
- break;
- default:
- break;
- }
- AnchorUtil.relocateAnchors(source);
+ sourceSite = getNextAnchorSite(sourceSite);
}
else {
- switch (AnchorLocation.getLocation(targetAnchor)) {
- case BOTTOM:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.LEFT);
- break;
- case CENTER:
- break;
- case LEFT:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.RIGHT);
- break;
- case RIGHT:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.TOP);
- break;
- case TOP:
- AnchorLocation.setLocation(targetAnchor, AnchorLocation.BOTTOM);
- break;
- default:
- break;
- }
- AnchorUtil.relocateAnchors(target);
+ targetSite = getNextAnchorSite(targetSite);
}
}
+// System.out.println("# Routes="+allRoutes.size());
+
// pick the shortest route
ConnectionRoute route = null;
if (allRoutes.size()==1) {
@@ -214,7 +227,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
Point p1 = r.getPoints().get(0);
for (int i=1; i<r.getPoints().size(); ++i) {
Point p2 = r.getPoints().get(i);
- List<Connection> crossings = findCrossings(p1, p2);
+ List<Connection> crossings = findCrossings(connection, p1, p2);
for (Connection c : crossings) {
if (c!=this.connection)
r.addCrossing(c, p1, p2);
@@ -241,7 +254,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
return route;
}
-
+
/**
* Calculate route.
*
@@ -261,10 +274,16 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
List<Point> approach = calculateApproach(middle, target, end);
route.getPoints().addAll(departure);
- calculateEnroute(route, departure.get(departure.size()-1), middle, orientation);
- route.getPoints().add(middle);
- calculateEnroute(route, middle,approach.get(0),orientation);
- route.getPoints().addAll(approach);
+ if (calculateEnroute(route, departure.get(departure.size()-1), middle, orientation)) {
+ route.getPoints().add(middle);
+ if (calculateEnroute(route, middle,approach.get(0),orientation)) {
+ route.getPoints().addAll(approach);
+ }
+ else
+ route.getPoints().add(end);
+ }
+ else
+ route.getPoints().add(end);
}
else {
List<Point> departure = calculateDeparture(source, start, end);
@@ -307,7 +326,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
* @return the list
*/
protected List<Point> calculateDeparture(Shape source, Point start, Point end) {
- AnchorLocation sourceEdge = AnchorLocation.getNearestEdge(source, start);
+ AnchorSite sourceEdge = AnchorSite.getNearestEdge(source, start, end);
List<Point> points = new ArrayList<Point>();
Point p = GraphicsUtil.createPoint(start);
@@ -323,7 +342,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
if (shape==null || Math.abs(m.getY()-start.getY())<=offset) {
if (shape!=null) {
// still collision?
- if (sourceEdge==AnchorLocation.BOTTOM)
+ if (sourceEdge==AnchorSite.BOTTOM)
m.setY(start.getY() + offset);
else
m.setY(start.getY() - offset);
@@ -341,7 +360,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
if (shape==null || Math.abs(m.getX()-start.getX())<=offset) {
if (shape!=null) {
// still collision?
- if (sourceEdge==AnchorLocation.RIGHT)
+ if (sourceEdge==AnchorSite.RIGHT)
m.setX(start.getX() + offset);
else
m.setX(start.getX() - offset);
@@ -370,13 +389,13 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
* @return the list
*/
protected List<Point> calculateApproach(Point start, Shape target, Point end) {
- AnchorLocation targetEdge = AnchorLocation.getNearestEdge(target, end);
+ AnchorSite targetSite = AnchorSite.getNearestEdge(target, start, end);
List<Point> points = new ArrayList<Point>();
Point p = GraphicsUtil.createPoint(end);
Point m = start;
- switch (targetEdge) {
+ switch (targetSite) {
case TOP:
case BOTTOM:
for (;;) {
@@ -385,7 +404,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
if (shape==null || shape==target || Math.abs(m.getY()-end.getY())<=offset) {
if (shape!=null) {
// still collision?
- if (targetEdge==AnchorLocation.BOTTOM)
+ if (targetSite==AnchorSite.BOTTOM)
m.setY(end.getY() + offset);
else
m.setY(end.getY() - offset);
@@ -403,7 +422,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
if (shape==null || shape==target || Math.abs(m.getX()-end.getX())<=offset) {
if (shape!=null) {
// still collision?
- if (targetEdge==AnchorLocation.RIGHT)
+ if (targetSite==AnchorSite.RIGHT)
m.setX(end.getX() + offset);
else
m.setX(end.getX() - offset);
@@ -579,16 +598,10 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
if (!calculateEnroute(route,p,end,Orientation.NONE))
return false;
}
- else {
- return false;
- }
return route.isValid();
}
- /* (non-Javadoc)
- * @see org.eclipse.bpmn2.modeler.core.features.BendpointConnectionRouter#getDetourPoints(org.eclipse.graphiti.mm.pictograms.ContainerShape)
- */
protected DetourPoints getDetourPoints(ContainerShape shape) {
DetourPoints detour = new DetourPoints(shape, offset);
if (allShapes==null)
@@ -608,37 +621,6 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
return detour;
}
- /**
- * Finalize connection.
- */
- protected void finalizeConnection() {
- }
-
- /**
- * Fix collisions.
- *
- * @return true, if successful
- */
- protected boolean fixCollisions() {
- return false;
- }
-
- /**
- * Calculate anchors.
- *
- * @return true, if successful
- */
- protected boolean calculateAnchors() {
- return false;
- }
-
- /**
- * Update connection.
- */
- protected void updateConnection() {
- DIUtils.updateDIEdge(ffc);
- }
-
protected void optimize(ConnectionRoute route) {
route.addSpecial(movedBendpoint);
@@ -647,51 +629,60 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter {
int size = route.getPoints().size();
if (size>1) {
+ // Discourage routes containing starting or ending segments that touch
+ // the source or target shape - it just looks ugly.
+ LineSegment sourceEdges[] = GraphicsUtil.getEdges(source);
Point p0 = route.getPoints().get(0);
Point p1 = route.getPoints().get(1);
- AnchorLocation sourceEdge = AnchorLocation.getNearestEdge(source, p0);
- if (sourceEdge==AnchorLocation.LEFT || sourceEdge==AnchorLocation.RIGHT) {
- if (GraphicsUtil.isVertical(p0, p1))
- route.valid = false;
+ AnchorSite sourceSite = route.getSourceAnchorSite();
+ if (sourceSite==AnchorSite.LEFT || sourceSite==AnchorSite.RIGHT) {
+ int x = sourceEdges[sourceSite.ordinal()].getStart().getX();
+ if (GraphicsUtil.isVertical(p0, p1) && p0.getX()==x)
+ route.setRank(3);
}
else {
- if (GraphicsUtil.isHorizontal(p0, p1))
- route.valid = false;
+ int y = sourceEdges[sourceSite.ordinal()].getStart().getY();
+ if (GraphicsUtil.isHorizontal(p0, p1) && p0.getY()==y)
+ route.setRank(3);
}
if (size>2) {
if (GraphicsUtil.getLength(p0, p1) < offset) {
p0 = route.getPoints().get(1);
p1 = route.getPoints().get(2);
- if (sourceEdge==AnchorLocation.LEFT || sourceEdge==AnchorLocation.RIGHT) {
+ if (sourceSite==AnchorSite.LEFT || sourceSite==AnchorSite.RIGHT) {
if (GraphicsUtil.isVertical(p0, p1))
- route.valid = false;
+ route.setRank(3);
}
else {
if (GraphicsUtil.isHorizontal(p0, p1))
- route.valid = false;
+ route.setRank(3);
}
}
+ // Same as above, but for the target shape
+ LineSegment targetEdges[] = GraphicsUtil.getEdges(target);
p0 = route.getPoints().get(size-2);
p1 = route.getPoints().get(size-1);
- AnchorLocation targetEdge = AnchorLocation.getNearestEdge(target, p1);
- if (targetEdge==AnchorLocation.LEFT || targetEdge==AnchorLocation.RIGHT) {
- if (GraphicsUtil.isVertical(p0, p1))
- route.valid = false;
+ AnchorSite targetSite = route.getTargetAnchorSite();
+ if (targetSite==AnchorSite.LEFT || targetSite==AnchorSite.RIGHT) {
+ int x = targetEdges[targetSite.ordinal()].getStart().getX();
+ if (GraphicsUtil.isVertical(p0, p1) && p0.getX()==x)
+ route.setRank(3);
}
else {
- if (GraphicsUtil.isHorizontal(p0, p1))
- route.valid = false;
+ int y = targetEdges[targetSite.ordinal()].getStart().getY();
+ if (GraphicsUtil.isHorizontal(p0, p1) && p0.getY()==y)
+ route.setRank(3);
}
if (GraphicsUtil.getLength(p0, p1) < offset) {
p0 = route.getPoints().get(size-3);
p1 = route.getPoints().get(size-2);
- if (targetEdge==AnchorLocation.LEFT || targetEdge==AnchorLocation.RIGHT) {
+ if (targetSite==AnchorSite.LEFT || targetSite==AnchorSite.RIGHT) {
if (GraphicsUtil.isVertical(p0, p1))
- route.valid = false;
+ route.setRank(3);
}
else {
if (GraphicsUtil.isHorizontal(p0, p1))
- route.valid = false;
+ route.setRank(3);
}
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ReconnectBaseElementFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ReconnectBaseElementFeature.java
index 7070f448..97e7da0c 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ReconnectBaseElementFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ReconnectBaseElementFeature.java
@@ -31,19 +31,18 @@ import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
-// TODO: Auto-generated Javadoc
/**
* The Class ReconnectBaseElementFeature.
*/
public class ReconnectBaseElementFeature extends DefaultReconnectionFeature {
- /** The changes done. */
+ /** This flag will be set TRUE if changes were made and need to be committed. */
protected boolean changesDone = false;
/**
- * Instantiates a new reconnect base element feature.
+ * Instantiates a new Reconnect Feature.
*
- * @param fp the fp
+ * @param fp the FeatureProvider
*/
public ReconnectBaseElementFeature(IFeatureProvider fp) {
super(fp);
@@ -81,22 +80,23 @@ public class ReconnectBaseElementFeature extends DefaultReconnectionFeature {
Connection connection = context.getConnection();
FixPointAnchor newAnchor = null;
- AnchorContainer source = connection.getStart().getParent();
- AnchorContainer target = connection.getEnd().getParent();
- if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_TARGET)) {
- target = (AnchorContainer) context.getTargetPictogramElement();
- ILocation targetLoc = context.getTargetLocation();
- newAnchor = AnchorUtil.createAnchor(target, targetLoc.getX(), targetLoc.getY());
- }
- else {
- source = (AnchorContainer) context.getTargetPictogramElement();
- ILocation targetLoc = context.getTargetLocation();
- newAnchor = AnchorUtil.createAnchor(source, targetLoc.getX(), targetLoc.getY());
- }
-
- if (newAnchor!=null)
- ((ReconnectionContext)context).setNewAnchor(newAnchor);
-
+ if (!(context.getNewAnchor() instanceof FixPointAnchor)) {
+ AnchorContainer source = connection.getStart().getParent();
+ AnchorContainer target = connection.getEnd().getParent();
+ if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_TARGET)) {
+ target = (AnchorContainer) context.getTargetPictogramElement();
+ ILocation targetLoc = context.getTargetLocation();
+ newAnchor = AnchorUtil.createAnchor(target, targetLoc.getX(), targetLoc.getY());
+ }
+ else {
+ source = (AnchorContainer) context.getTargetPictogramElement();
+ ILocation targetLoc = context.getTargetLocation();
+ newAnchor = AnchorUtil.createAnchor(source, targetLoc.getX(), targetLoc.getY());
+ }
+
+ if (newAnchor!=null)
+ ((ReconnectionContext)context).setNewAnchor(newAnchor);
+ }
super.preReconnect(context);
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/ChoreographyUtil.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/ChoreographyUtil.java
index ac9f4bb8..7b720ac0 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/ChoreographyUtil.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/ChoreographyUtil.java
@@ -25,6 +25,8 @@ import org.eclipse.bpmn2.Participant;
import org.eclipse.bpmn2.di.BPMNShape;
import org.eclipse.bpmn2.modeler.core.adapters.ExtendedPropertiesProvider;
import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
import org.eclipse.dd.dc.Bounds;
@@ -37,9 +39,10 @@ import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.LayoutContext;
import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.mm.PropertyContainer;
-import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
@@ -57,7 +60,6 @@ public class ChoreographyUtil implements ChoreographyProperties {
public final static String INITIATING_PARTICIPANT_REF = "choreography.activity.initiating.participant.ref"; //$NON-NLS-1$
public final static String MESSAGE_VISIBLE = "choreography.activity.band.message.visible"; //$NON-NLS-1$
public final static String PARTICIPANT_BAND = "choreography.activity.band"; //$NON-NLS-1$
- public final static String MESSAGE_LINK = "choreography.messageLink"; //$NON-NLS-1$
public final static String MESSAGE_NAME = "choreography.messageName"; //$NON-NLS-1$
public final static String MESSAGE_REF_IDS = "choreography.message.ref.ids"; //$NON-NLS-1$
@@ -135,9 +137,9 @@ public class ChoreographyUtil implements ChoreographyProperties {
EObject o = BusinessObjectUtil.getFirstElementOfType(pe, BaseElement.class);
if (o instanceof MessageFlow && pe instanceof Connection) {
Connection c = (Connection)pe;
- if (c.getStart()!=null && peService.getPropertyValue(c.getStart().getParent(),ChoreographyUtil.MESSAGE_LINK) != null)
+ if (c.getStart()!=null && peService.getPropertyValue(c.getStart().getParent(),GraphitiConstants.MESSAGE_LINK) != null)
return true;
- if (c.getEnd()!=null && peService.getPropertyValue(c.getEnd().getParent(),ChoreographyUtil.MESSAGE_LINK) != null)
+ if (c.getEnd()!=null && peService.getPropertyValue(c.getEnd().getParent(),GraphitiConstants.MESSAGE_LINK) != null)
return true;
}
return false;
@@ -152,7 +154,7 @@ public class ChoreographyUtil implements ChoreographyProperties {
public static boolean isChoreographyMessage(PictogramElement pe) {
EObject o = BusinessObjectUtil.getFirstElementOfType(pe, BaseElement.class);
if (o instanceof Message && pe instanceof ContainerShape) {
- if (peService.getPropertyValue(pe,ChoreographyUtil.MESSAGE_LINK) != null)
+ if (peService.getPropertyValue(pe,GraphitiConstants.MESSAGE_LINK) != null)
return true;
}
return false;
@@ -232,31 +234,18 @@ public class ChoreographyUtil implements ChoreographyProperties {
Bounds bounds = bpmnShape.getBounds();
int x = (int) ((bounds.getX() + bounds.getWidth() / 2) - (ChoreographyUtil.ENV_W / 2));
-// Map<AnchorLocation, BoundaryAnchor> boundaryAnchors = AnchorUtil.getBoundaryAnchors(choreographyTaskShape);
-// BoundaryAnchor topBoundaryAnchor = boundaryAnchors.get(AnchorLocation.TOP);
-// BoundaryAnchor bottomBoundaryAnchor = boundaryAnchors.get(AnchorLocation.BOTTOM);
-
-// for (Connection connection : topBoundaryAnchor.anchor.getOutgoingConnections()) {
- for (Anchor anchor : choreographyTaskShape.getAnchors()) {
- for (Connection connection : anchor.getOutgoingConnections()) {
- EObject container = connection.getEnd().eContainer();
- if (container instanceof PropertyContainer) {
- String property = peService.getPropertyValue((PropertyContainer) container, ChoreographyUtil.MESSAGE_LINK);
- if (property != null && new Boolean(property)) {
- int y = (int) (bounds.getY() - ChoreographyUtil.ENVELOPE_HEIGHT_MODIFIER - ChoreographyUtil.ENV_H);
- gaService.setLocation(((ContainerShape) container).getGraphicsAlgorithm(), x, y);
- break;
- }
- }
- }
-
- for (Connection connection : anchor.getOutgoingConnections()) {
- EObject container = connection.getEnd().eContainer();
- if (container instanceof PropertyContainer) {
- String property = peService.getPropertyValue((PropertyContainer) container, ChoreographyUtil.MESSAGE_LINK);
- if (property != null && new Boolean(property)) {
- int y = (int) (bounds.getY() + bounds.getHeight() + ChoreographyUtil.ENVELOPE_HEIGHT_MODIFIER);
- gaService.setLocation(((ContainerShape) container).getGraphicsAlgorithm(), x, y);
+ for (FixPointAnchor anchor : AnchorUtil.getAnchors(choreographyTaskShape)) {
+ AnchorSite site = AnchorSite.getSite(anchor);
+ if (site == AnchorSite.TOP || site == AnchorSite.BOTTOM) {
+ for (Connection connection : anchor.getOutgoingConnections()) {
+ AnchorContainer container = connection.getEnd().getParent();
+ if (isChoreographyMessage(container)) {
+ int y;
+ if (site == AnchorSite.TOP)
+ y = (int) (bounds.getY() - ChoreographyUtil.ENVELOPE_HEIGHT_MODIFIER - ChoreographyUtil.ENV_H);
+ else
+ y = (int) (bounds.getY() + bounds.getHeight() + ChoreographyUtil.ENVELOPE_HEIGHT_MODIFIER);
+ gaService.setLocation(container.getGraphicsAlgorithm(), x, y);
break;
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/UpdateChoreographyParticipantRefsFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/UpdateChoreographyParticipantRefsFeature.java
index c499f4a1..5c6013be 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/UpdateChoreographyParticipantRefsFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/choreography/UpdateChoreographyParticipantRefsFeature.java
@@ -368,7 +368,6 @@ public class UpdateChoreographyParticipantRefsFeature extends AbstractBpmn2Updat
y += hAcc;
resizeParticipantBandChildren(container, w);
DIUtils.updateDIShape(container);
- AnchorUtil.relocateAnchors(container, w, (int) bounds.getHeight());
}
Collections.reverse(bottom); // start from bottom towards center
@@ -380,7 +379,6 @@ public class UpdateChoreographyParticipantRefsFeature extends AbstractBpmn2Updat
gaService.setLocationAndSize(container.getGraphicsAlgorithm(), x, y, w, (int) bounds.getHeight());
resizeParticipantBandChildren(container, w);
DIUtils.updateDIShape(container);
- AnchorUtil.relocateAnchors(container, w, (int) bounds.getHeight());
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractAddFlowFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractAddFlowFeature.java
index 47e3875a..3bf939ad 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractAddFlowFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractAddFlowFeature.java
@@ -15,18 +15,12 @@ package org.eclipse.bpmn2.modeler.core.features.flow;
import java.util.List;
import org.eclipse.bpmn2.BaseElement;
-import org.eclipse.bpmn2.EndEvent;
-import org.eclipse.bpmn2.EventDefinition;
-import org.eclipse.bpmn2.MessageEventDefinition;
-import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.modeler.core.di.DIImport;
import org.eclipse.bpmn2.modeler.core.features.AbstractBpmn2AddFeature;
import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
import org.eclipse.bpmn2.modeler.core.features.label.AddConnectionLabelFeature;
-import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.StyleUtil;
-import org.eclipse.bpmn2.modeler.core.utils.Tuple;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
@@ -34,9 +28,7 @@ import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
import org.eclipse.graphiti.mm.pictograms.Anchor;
-import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
-import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
@@ -55,7 +47,6 @@ public abstract class AbstractAddFlowFeature<T extends BaseElement>
@Override
public boolean canAdd(IAddContext context) {
if (context instanceof IAddConnectionContext) {
- IAddConnectionContext acc = (IAddConnectionContext) context;
return getBusinessObjectType().isAssignableFrom(getBusinessObject(context).getClass());
}
return false;
@@ -70,8 +61,6 @@ public abstract class AbstractAddFlowFeature<T extends BaseElement>
T businessObject = getBusinessObject(context);
IAddConnectionContext addContext = (IAddConnectionContext) context;
- AnchorContainer sourceContainer = addContext.getSourceAnchor().getParent();
- AnchorContainer targetContainer = addContext.getTargetAnchor().getParent();
FreeFormConnection connection = peService.createFreeFormConnection(getDiagram());
Anchor sourceAnchor = addContext.getSourceAnchor();
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractCreateFlowFeature.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractCreateFlowFeature.java
index da897aca..b301d95a 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractCreateFlowFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractCreateFlowFeature.java
@@ -92,40 +92,28 @@ public abstract class AbstractCreateFlowFeature<
Connection connection = null;
CONNECTION businessObject = createBusinessObject(context);
if (businessObject!=null) {
- IPeService peService = Graphiti.getPeService();
-
AnchorContainer source = (AnchorContainer) context.getSourcePictogramElement();
AnchorContainer target = (AnchorContainer) context.getTargetPictogramElement();
- FixPointAnchor sourceAnchor = null;
- FixPointAnchor targetAnchor = null;
+ Anchor sourceAnchor = context.getSourceAnchor();
+ Anchor targetAnchor = context.getTargetAnchor();
ILocation loc = context.getSourceLocation();
if (loc==null) {
- Anchor a = context.getSourceAnchor();
- if (a instanceof ChopboxAnchor) {
- Point p = GraphicsUtil.getShapeCenter(target);
+ if (sourceAnchor instanceof ChopboxAnchor) {
+ Point p = GraphicsUtil.createPoint(context.getTargetAnchor());
sourceAnchor = AnchorUtil.createAnchor(source, p);
}
- else if (a instanceof FixPointAnchor) {
- loc = peService.getLocationRelativeToDiagram(a);
- sourceAnchor = AnchorUtil.createAnchor(source, loc.getX(), loc.getY());
- }
}
- else
+ else if (sourceAnchor==null || sourceAnchor instanceof ChopboxAnchor)
sourceAnchor = AnchorUtil.createAnchor(source, loc.getX(), loc.getY());
loc = context.getTargetLocation();
if (loc==null) {
- Anchor a = context.getTargetAnchor();
- if (a instanceof ChopboxAnchor) {
- Point p = GraphicsUtil.getShapeCenter(source);
+ if (targetAnchor instanceof ChopboxAnchor) {
+ Point p = GraphicsUtil.createPoint(context.getSourceAnchor());
targetAnchor = AnchorUtil.createAnchor(target, p);
}
- else if (a instanceof FixPointAnchor) {
- loc = peService.getLocationRelativeToDiagram(a);
- targetAnchor = AnchorUtil.createAnchor(source, loc.getX(), loc.getY());
- }
}
- else
+ else if (targetAnchor==null || targetAnchor instanceof ChopboxAnchor)
targetAnchor = AnchorUtil.createAnchor(target, loc.getX(), loc.getY());
((CreateConnectionContext)context).setSourceAnchor(sourceAnchor);
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/messages.properties b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/messages.properties
index 92dadd29..e98f86a9 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/messages.properties
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/messages.properties
@@ -12,15 +12,15 @@ LifecycleEvent_Event_Prefix=Event:
ModelHandler_20=Cannot assign
ModelHandler_21=\ to
ModelHandler_Choreography=\ Choreography
-ModelHandler_Choreography_Task=\ Choreography Task
+ModelHandler_Choreography_Task=Choreography Task
ModelHandler_Collaboration=\ Collaboration
ModelHandler_Collaboration_Diagram=\ Collaboration Diagram
ModelHandler_Default=Default
-ModelHandler_Initiating_Participant=\ Initiating Participant
+ModelHandler_Initiating_Participant=Initiating Participant
ModelHandler_Initiating_Pool=Initiating Pool
ModelHandler_Initiating_Process=Initiating Process
ModelHandler_Lane_Set=Lane Set
-ModelHandler_Non_Initiating_Participant=\ Non-initiating Participant
+ModelHandler_Non_Initiating_Participant=Non-initiating Participant
ModelHandler_Non_Initiating_Pool=Non-initiating Pool
ModelHandler_Non_Initiating_Process=Non-initiating Process
ModelHandler_Process=\ Process
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/model/ModelHandler.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/model/ModelHandler.java
index 1d670a40..724dcc0e 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/model/ModelHandler.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/model/ModelHandler.java
@@ -355,14 +355,14 @@ public class ModelHandler {
choreography.setName(name+Messages.ModelHandler_Choreography);
Participant initiatingParticipant = create(Participant.class);
- initiatingParticipant.setName(name+Messages.ModelHandler_Initiating_Participant);
+ initiatingParticipant.setName(Messages.ModelHandler_Initiating_Participant);
// Process initiatingProcess = createProcess();
// initiatingProcess.setName(name+" Initiating Process");
// initiatingParticipant.setProcessRef(initiatingProcess);
Participant nonInitiatingParticipant = create(Participant.class);
- nonInitiatingParticipant.setName(name+Messages.ModelHandler_Non_Initiating_Participant);
+ nonInitiatingParticipant.setName(Messages.ModelHandler_Non_Initiating_Participant);
// Process nonInitiatingProcess = createProcess();
// nonInitiatingProcess.setName(name+" Non-initiating Process");
@@ -372,7 +372,7 @@ public class ModelHandler {
choreography.getParticipants().add(nonInitiatingParticipant);
ChoreographyTask task = create(ChoreographyTask.class);
- task.setName(name+Messages.ModelHandler_Choreography_Task);
+ task.setName(Messages.ModelHandler_Choreography_Task);
task.getParticipantRefs().add(initiatingParticipant);
task.getParticipantRefs().add(nonInitiatingParticipant);
task.setInitiatingParticipantRef(initiatingParticipant);
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorLocation.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorSite.java
index b014c3a7..5ad562b1 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorLocation.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorSite.java
@@ -21,12 +21,13 @@ import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
-public enum AnchorLocation {
+public enum AnchorSite {
+ /** These ordinals MUST have the same meanings as {@see GraphicsUtil#getEdges(Shape)} */
TOP("anchor.top"), BOTTOM("anchor.bottom"), LEFT("anchor.left"), RIGHT("anchor.right"), CENTER("anchor.center"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
private final String key;
- private AnchorLocation(String key) {
+ private AnchorSite(String key) {
this.key = key;
}
@@ -34,51 +35,80 @@ public enum AnchorLocation {
return key;
}
- public static AnchorLocation getLocation(String key) {
- for (AnchorLocation l : values()) {
+ public static AnchorSite getSite(String key) {
+ for (AnchorSite l : values()) {
if (l.getKey().equals(key)) {
return l;
}
}
- return null;
+
+ return CENTER;
+// throw new IllegalArgumentException("Cannot determine Anchor Site "+key);
}
- public static AnchorLocation getLocation(FixPointAnchor anchor) {
- return getLocation(Graphiti.getPeService().getPropertyValue(anchor, GraphitiConstants.ANCHOR_LOCATION));
+ public static AnchorSite getSite(FixPointAnchor anchor) {
+ return getSite(Graphiti.getPeService().getPropertyValue(anchor, GraphitiConstants.ANCHOR_LOCATION));
}
- public static void setLocation(FixPointAnchor anchor, AnchorLocation al) {
- Graphiti.getPeService().setPropertyValue(anchor, GraphitiConstants.ANCHOR_LOCATION, al.getKey());
- AnchorUtil.adjustAnchors(anchor.getParent());
-
+ public static void setSite(FixPointAnchor anchor, AnchorSite site) {
+ Graphiti.getPeService().setPropertyValue(anchor, GraphitiConstants.ANCHOR_LOCATION, site.getKey());
}
/**
- * Return the AnchorLocation value of the shape's edge that is nearest
+ * Return the AnchorSide value of the shape's edge that is nearest
* to the given point.
*
* @param shape
* @param p
* @return
*/
- public static AnchorLocation getNearestEdge(Shape shape, Point p) {
+ public static AnchorSite getNearestEdge(Shape shape, Point p) {
LineSegment edge = GraphicsUtil.findNearestEdge(shape, p);
ILocation loc = Graphiti.getPeService().getLocationRelativeToDiagram(shape);
- AnchorLocation al;
+ AnchorSite site;
+ if (edge.isHorizontal()) {
+ int y = edge.getStart().getY();
+ if (y==loc.getY())
+ site = TOP;
+ else
+ site = BOTTOM;
+ }
+ else {
+ int x = edge.getStart().getX();
+ if (x==loc.getX())
+ site = LEFT;
+ else
+ site = RIGHT;
+ }
+ return site;
+ }
+
+ /**
+ * Return the AnchorSide value of the shape's edge that is nearest
+ * to the given point.
+ *
+ * @param shape
+ * @param p
+ * @return
+ */
+ public static AnchorSite getNearestEdge(Shape shape, Point p1, Point p2) {
+ LineSegment edge = GraphicsUtil.findNearestEdge(shape, p1, p2);
+ ILocation loc = Graphiti.getPeService().getLocationRelativeToDiagram(shape);
+ AnchorSite site;
if (edge.isHorizontal()) {
int y = edge.getStart().getY();
if (y==loc.getY())
- al = TOP;
+ site = TOP;
else
- al = BOTTOM;
+ site = BOTTOM;
}
else {
int x = edge.getStart().getX();
if (x==loc.getX())
- al = LEFT;
+ site = LEFT;
else
- al = RIGHT;
+ site = RIGHT;
}
- return al;
+ return site;
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorType.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorType.java
index d78d319e..bbfaf8e5 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorType.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorType.java
@@ -22,10 +22,11 @@ import org.eclipse.bpmn2.SequenceFlow;
import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.services.Graphiti;
public enum AnchorType {
- ACTIVITY("activity"), POOL("pool"), GATEWAY("gateway"), CONNECTION("connection");
+ ACTIVITY("activity"), POOL("pool"), GATEWAY("gateway"), MESSAGELINK("messagelink"), CONNECTION("connection");
private final String key;
@@ -45,11 +46,17 @@ public enum AnchorType {
}
return null;
}
+
public static AnchorType getType(AnchorContainer ac) {
+ if (ac instanceof ConnectionDecorator)
+ return CONNECTION;
+
BaseElement be = BusinessObjectUtil.getFirstBaseElement(ac);
- if (be instanceof Participant) {
- if (FeatureSupport.isChoreographyParticipantBand(ac))
- return ACTIVITY;
+ String property = Graphiti.getPeService().getPropertyValue(ac, GraphitiConstants.MESSAGE_LINK);
+ if (Boolean.parseBoolean(property)) {
+ return MESSAGELINK;
+ }
+ else if (be instanceof Participant) {
return POOL;
}
else if (be instanceof Group) {
@@ -64,7 +71,7 @@ public enum AnchorType {
else if (be != null) {
return ACTIVITY;
}
- return null;
+ throw new IllegalArgumentException("Cannot determine Anchor Type for business object "+be);
}
public static AnchorType getType(Anchor anchor) {
@@ -73,6 +80,5 @@ public enum AnchorType {
public static void setType(Anchor anchor, AnchorType at) {
Graphiti.getPeService().setPropertyValue(anchor, GraphitiConstants.ANCHOR_TYPE, at.getKey());
-
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java
index 16aee2ff..e08b5413 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java
@@ -14,32 +14,31 @@ package org.eclipse.bpmn2.modeler.core.utils;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map.Entry;
+import java.util.TreeMap;
import org.eclipse.bpmn2.BaseElement;
-import org.eclipse.bpmn2.di.BPMNEdge;
-import org.eclipse.bpmn2.modeler.core.di.DIUtils;
import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil.LineSegment;
-import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.graphiti.datatypes.IDimension;
import org.eclipse.graphiti.datatypes.ILocation;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.mm.algorithms.Ellipse;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.PictogramLink;
+import org.eclipse.graphiti.mm.pictograms.PictogramsFactory;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.ICreateService;
import org.eclipse.graphiti.services.IGaService;
-import org.eclipse.graphiti.services.ILayoutService;
import org.eclipse.graphiti.services.IPeService;
public class AnchorUtil {
@@ -49,8 +48,86 @@ public class AnchorUtil {
private static final IPeService peService = Graphiti.getPeService();
private static final IGaService gaService = Graphiti.getGaService();
private static final ICreateService createService = Graphiti.getCreateService();
- private static final ILayoutService layoutService = Graphiti.getLayoutService();
+ /**
+ * This Connection Anchor Adapter listens for changes in the number of
+ * Connections on the given Anchor and deletes the AnchorContainer shape (an
+ * instance of ConnectionDecorator) when the incoming and outgoing
+ * connection count is zero.
+ */
+ private static class ConnectionAnchorAdapter extends AdapterImpl {
+ Anchor anchor;
+ private boolean deleting = false;
+
+ public static ConnectionAnchorAdapter adapt(Anchor anchor) {
+ return new ConnectionAnchorAdapter(anchor);
+ }
+
+ private ConnectionAnchorAdapter(Anchor anchor) {
+ this.anchor = anchor;
+ anchor.eAdapters().add(this);
+ setTarget(anchor);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ // if the connection is no longer connected to this shape
+ // then delete the Connection Point
+ if (!deleting) {
+ if (notification.getNotifier() == anchor) {
+ // something changed in the anchor
+ int et = notification.getEventType();
+ if (et==Notification.REMOVE) {
+ if (anchor.getIncomingConnections().isEmpty() && anchor.getOutgoingConnections().isEmpty()) {
+ // the anchor has no connections, so we need to delete it
+ deleting = true;
+ if (anchor.eContainer()!=null)
+ Graphiti.getPeService().deletePictogramElement(anchor.getParent());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static FixPointAnchor createAnchor(AnchorContainer ac, AnchorSite site) {
+ if (ac instanceof Shape) {
+ ILocation loc = peService.getLocationRelativeToDiagram((Shape)ac);
+ IDimension size = GraphicsUtil.calculateSize((Shape)ac);
+ int x = 0;
+ int y = 0;
+ switch (site) {
+ case BOTTOM:
+ x = loc.getX() + size.getWidth()/2;
+ y = loc.getY() + size.getHeight();
+ break;
+ case LEFT:
+ x = loc.getX();
+ y = loc.getY() + size.getHeight()/2;
+ break;
+ case RIGHT:
+ x = loc.getX() + size.getWidth();
+ y = loc.getY() + size.getHeight()/2;
+ break;
+ case TOP:
+ x = loc.getX() + size.getWidth()/2;
+ y = loc.getY();
+ break;
+ case CENTER:
+ x = loc.getX() + size.getWidth()/2;
+ y = loc.getY() + size.getHeight()/2;
+ break;
+ default:
+ break;
+ }
+ return createAnchor(ac, x, y);
+ }
+ return null;
+ }
+
public static FixPointAnchor createAnchor(AnchorContainer ac, int x, int y, AnchorType at) {
return createAnchor(ac, gaService.createPoint(x, y), at);
}
@@ -58,7 +135,6 @@ public class AnchorUtil {
public static FixPointAnchor createAnchor(AnchorContainer ac, Point p, AnchorType at) {
FixPointAnchor anchor = createBoundaryAnchor(ac, p);
AnchorType.setType(anchor, at);
- relocateAnchors(ac);
return anchor;
}
@@ -67,44 +143,69 @@ public class AnchorUtil {
}
public static FixPointAnchor createAnchor(AnchorContainer ac, Point p) {
+ if (isConnectionAnchorContainer(ac)) {
+ return (FixPointAnchor)ac.getAnchors().get(0);
+ }
+ else if (ac instanceof Connection) {
+ return createConnectionAnchor((Connection)ac);
+ }
FixPointAnchor anchor = createBoundaryAnchor(ac, p);
AnchorType at = AnchorType.getType(ac);
AnchorType.setType(anchor, at);
- relocateAnchors(ac);
return anchor;
}
- public static FixPointAnchor createBoundaryAnchor(AnchorContainer ac, Point p) {
- FixPointAnchor anchor = peService.createFixPointAnchor(ac);
- moveAnchor(anchor, p);
- gaService.createInvisibleRectangle(anchor);
-
- return anchor;
- }
-
- public static List<FixPointAnchor> getBoundaryAnchors(AnchorContainer ac, AnchorLocation al) {
+ public static List<FixPointAnchor> getAnchors(AnchorContainer ac, AnchorSite site) {
List<FixPointAnchor> result = new ArrayList<FixPointAnchor>();
for (Anchor anchor : ac.getAnchors()) {
if (peService.getPropertyValue(anchor, GraphitiConstants.ANCHOR_TYPE)!=null &&
- AnchorLocation.getLocation((FixPointAnchor)anchor)==al)
+ AnchorSite.getSite((FixPointAnchor)anchor)==site)
result.add((FixPointAnchor)anchor);
}
return result;
}
+
+ public static List<FixPointAnchor> getAnchors(AnchorContainer ac) {
+ List<FixPointAnchor> result = new ArrayList<FixPointAnchor>();
+ if (ac instanceof Connection) {
+ Connection connection = (Connection) ac;
+ for (ConnectionDecorator cd : connection.getConnectionDecorators()) {
+ if (isConnectionAnchorContainer(cd)) {
+ for (Anchor a : cd.getAnchors())
+ result.add((FixPointAnchor)a);
+ }
+ }
+ }
+ else if (ac != null) {
+ for (Anchor anchor : ac.getAnchors()) {
+ if (peService.getPropertyValue(anchor, GraphitiConstants.ANCHOR_TYPE)!=null)
+ result.add((FixPointAnchor)anchor);
+ }
+ }
+ return result;
+ }
+ public static void moveAnchor(FixPointAnchor anchor, int x, int y) {
+ moveAnchor(anchor, GraphicsUtil.createPoint(x,y));
+ }
+
public static void moveAnchor(FixPointAnchor anchor, Point p) {
- AnchorContainer ac = anchor.getParent();
- if (ac instanceof Shape) {
+ AnchorContainer parent = anchor.getParent();
+ if (isConnectionAnchorContainer(parent)) {
+ // these can't be moved
+ return;
+ }
+ if (parent instanceof Shape) {
p = GraphicsUtil.createPoint(p); // make a copy
- ILocation loc = peService.getLocationRelativeToDiagram((Shape)ac);
- LineSegment edge = GraphicsUtil.findNearestEdge((Shape)ac, p);
- AnchorLocation al;
+ ILocation loc = peService.getLocationRelativeToDiagram((Shape)parent);
+ LineSegment edge = GraphicsUtil.findNearestEdge((Shape)parent, p);
+ AnchorSite site;
if (edge.isHorizontal()) {
int y = edge.getStart().getY();
if (y==loc.getY())
- al = AnchorLocation.TOP;
+ site = AnchorSite.TOP;
else
- al = AnchorLocation.BOTTOM;
+ site = AnchorSite.BOTTOM;
p.setY(y - loc.getY());
int x = p.getX();
if (x < edge.getStart().getX())
@@ -116,9 +217,9 @@ public class AnchorUtil {
else {
int x = edge.getStart().getX();
if (x==loc.getX())
- al = AnchorLocation.LEFT;
+ site = AnchorSite.LEFT;
else
- al = AnchorLocation.RIGHT;
+ site = AnchorSite.RIGHT;
p.setX(x - loc.getX());
int y = p.getY();
if (y < edge.getStart().getY())
@@ -127,53 +228,232 @@ public class AnchorUtil {
y = edge.getEnd().getY();
p.setY(y - loc.getY());
}
- AnchorLocation.setLocation(anchor, al);
+ AnchorSite.setSite(anchor, site);
}
anchor.setLocation(p);
}
+
+ public static void moveAnchor(FixPointAnchor anchor, FixPointAnchor refAnchor) {
+ AnchorContainer parent = anchor.getParent();
+ if (isConnectionAnchorContainer(parent)) {
+ // these can't be moved
+ return;
+ }
+
+ AnchorContainer refParent = refAnchor.getParent();
+ AnchorSite refSite = AnchorSite.getSite(refAnchor);
+
+ Point p = GraphicsUtil.createPoint(refAnchor);
+
+ if (parent instanceof Shape && refParent instanceof Shape && refSite!=null) {
+ LineSegment refEdge = GraphicsUtil.getEdges((Shape)refParent)[refSite.ordinal()];
+ ILocation loc = peService.getLocationRelativeToDiagram((Shape)parent);
+ LineSegment edge = GraphicsUtil.findNearestEdge((Shape)parent, refEdge.getStart(), refEdge.getEnd());
+ AnchorSite site;
+ if (edge.isHorizontal()) {
+ int y = edge.getStart().getY();
+ if (y==loc.getY())
+ site = AnchorSite.TOP;
+ else
+ site = AnchorSite.BOTTOM;
+ p.setY(y - loc.getY());
+ int x = p.getX();
+ if (x < edge.getStart().getX())
+ x = edge.getStart().getX();
+ if (x > edge.getEnd().getX())
+ x = edge.getEnd().getX();
+ p.setX(x - loc.getX());
+ }
+ else {
+ int x = edge.getStart().getX();
+ if (x==loc.getX())
+ site = AnchorSite.LEFT;
+ else
+ site = AnchorSite.RIGHT;
+ p.setX(x - loc.getX());
+ int y = p.getY();
+ if (y < edge.getStart().getY())
+ y = edge.getStart().getY();
+ if (y > edge.getEnd().getY())
+ y = edge.getEnd().getY();
+ p.setY(y - loc.getY());
+ }
+ AnchorSite.setSite(anchor, site);
+ anchor.setLocation(p);
+ }
+ else
+ moveAnchor(anchor, p);
+ }
+
+ public static List<Connection> getConnections(AnchorContainer ac, AnchorSite site) {
+ List<Connection> connections = new ArrayList<Connection>();
+ for (Anchor a : ac.getAnchors()) {
+ if (peService.getPropertyValue(a, GraphitiConstants.ANCHOR_TYPE)!=null)
+ if (site==AnchorSite.getSite((FixPointAnchor)a)) {
+ connections.addAll(a.getIncomingConnections());
+ connections.addAll(a.getOutgoingConnections());
+ }
+ }
+ return connections;
+ }
+
+ public static void adjustAnchors(AnchorContainer ac) {
+ if (ac instanceof ConnectionDecorator) {
+ for (Anchor a : ac.getAnchors()) {
+ String property = peService.getPropertyValue(a, GraphitiConstants.ANCHOR_TYPE);
+ if ( property!=null &&
+ a.getIncomingConnections().isEmpty() &&
+ a.getOutgoingConnections().isEmpty()) {
+ peService.deletePictogramElement(ac);
+ return;
+ }
+ }
+ }
+ else if (ac!=null){
+ deleteUnusedAnchors(ac);
+ relocateAnchors(ac);
+ }
+ }
+
+ public static AnchorContainer getAnchorContainer(Anchor anchor) {
+ AnchorContainer ac = anchor.getParent();
+ return ac;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ // Private API
+ /////////////////////////////////////////////////////////////////////
+
+ private static FixPointAnchor createBoundaryAnchor(AnchorContainer ac, Point p) {
+ FixPointAnchor anchor = peService.createFixPointAnchor(ac);
+ moveAnchor(anchor, p);
+ gaService.createInvisibleRectangle(anchor);
+
+ return anchor;
+ }
+
+ private static FixPointAnchor createConnectionAnchor(Connection connection) {
+
+ Diagram diagram = peService.getDiagramForPictogramElement(connection);
+ // First create a Connection Decorator and set its location according to the given Point
+ // If the Point is not provided, use the coordinates of the Connection midpoint.
+ ConnectionDecorator decorator = createService.createConnectionDecorator(connection, true, 0.5, true);
+ peService.setPropertyValue(decorator, GraphitiConstants.CONNECTION_POINT, Boolean.TRUE.toString());
+ Rectangle rectangle = createService.createRectangle(decorator);
+ rectangle.setFilled(true);
+ rectangle.setForeground(Graphiti.getGaService().manageColor(diagram, StyleUtil.CLASS_FOREGROUND));
+ rectangle.setX(-CONNECTION_POINT_SIZE/2);
+ rectangle.setY(-CONNECTION_POINT_SIZE/2);
+ rectangle.setWidth(CONNECTION_POINT_SIZE);
+ rectangle.setHeight(CONNECTION_POINT_SIZE);
+
+ PictogramLink link = createPictogramLink(decorator);
+ BaseElement be = BusinessObjectUtil.getFirstBaseElement(connection);
+ link.getBusinessObjects().add(be);
+
+ FixPointAnchor anchor = createService.createFixPointAnchor(decorator);
+ AnchorSite.setSite(anchor, AnchorSite.CENTER);
+ AnchorType.setType(anchor, AnchorType.CONNECTION);
+ anchor.setLocation(GraphicsUtil.createPoint(CONNECTION_POINT_SIZE/2, CONNECTION_POINT_SIZE/2));
+ peService.setPropertyValue(anchor, GraphitiConstants.CONNECTION_POINT, Boolean.TRUE.toString());
+
+ // if the anchor doesn't have a GraphicsAlgorithm, GEF will throw a fit
+ // so create an invisible rectangle for it
+ createService.createInvisibleRectangle(anchor);
+
+ // add an adapter that will delete the Connection Decorator when the last
+ // connection on its Anchor is removed
+ ConnectionAnchorAdapter.adapt(anchor);
+
+ return anchor;
+ }
+
+ private static boolean isConnectionAnchorContainer(AnchorContainer ac) {
+ return Boolean.TRUE.toString().equals(peService.getPropertyValue(ac, GraphitiConstants.CONNECTION_POINT));
+ }
- public static void relocateAnchors(AnchorContainer ac) {
+ /**
+ * @param parent
+ */
+ private static void deleteUnusedAnchors(AnchorContainer ac) {
+ if (ac!=null) {
+ List<Anchor> deleted = new ArrayList<Anchor>();
+
+ for (Anchor a : ac.getAnchors()) {
+ String property = peService.getPropertyValue(a, GraphitiConstants.ANCHOR_TYPE);
+ if ( property!=null &&
+ a.getIncomingConnections().isEmpty() &&
+ a.getOutgoingConnections().isEmpty()) {
+ deleted.add(a);
+ }
+ }
+
+ for (Anchor a : deleted) {
+ peService.deletePictogramElement(a);
+ }
+ }
+ }
+
+ private static void relocateAnchors(AnchorContainer ac) {
IDimension size = GraphicsUtil.calculateSize(ac);
relocateAnchors(ac, size.getWidth(), size.getHeight());
}
- public static void relocateAnchors(AnchorContainer ac, int w, int h) {
+ private static void relocateAnchors(AnchorContainer ac, int w, int h) {
- if (ac==null)
+ if (ac==null || isConnectionAnchorContainer(ac))
return;
// These are the number of Activity Anchors along each
// edge of the Activity. These anchors are distributed
// evenly along an edge of the shape
- int topCount = 1;
- int bottomCount = 1;
- int leftCount = 1;
- int rightCount = 1;
+ int topCount = 0;
+ int bottomCount = 0;
+ int leftCount = 0;
+ int rightCount = 0;
// Calculated offsets for each Activity Anchor
int topOffset = 0;
int bottomOffset = 0;
int leftOffset = 0;
int rightOffset = 0;
+ // Connections attached to each anchor
+ List<FixPointAnchor> topAnchors = null;
+ List<FixPointAnchor> bottomAnchors = null;
+ List<FixPointAnchor> leftAnchors = null;
+ List<FixPointAnchor> rightAnchors = null;
+
for (Anchor a : ac.getAnchors()) {
AnchorType at = AnchorType.getType(a);
- if (at == AnchorType.ACTIVITY) {
+ if (at == AnchorType.ACTIVITY || at == AnchorType.MESSAGELINK) {
// Count all of the Activity Anchors
FixPointAnchor anchor = (FixPointAnchor) a;
- AnchorLocation al = AnchorLocation.getLocation(anchor);
- switch (al) {
+ AnchorSite site = AnchorSite.getSite(anchor);
+ switch (site) {
case BOTTOM:
++bottomCount;
+ if (bottomAnchors==null)
+ bottomAnchors = new ArrayList<FixPointAnchor>();
+ bottomAnchors.add(anchor);
break;
case CENTER:
break;
case LEFT:
++leftCount;
+ if (leftAnchors==null)
+ leftAnchors = new ArrayList<FixPointAnchor>();
+ leftAnchors.add(anchor);
break;
case RIGHT:
++rightCount;
+ if (rightAnchors==null)
+ rightAnchors = new ArrayList<FixPointAnchor>();
+ rightAnchors.add(anchor);
break;
case TOP:
++topCount;
+ if (topAnchors==null)
+ topAnchors = new ArrayList<FixPointAnchor>();
+ topAnchors.add(anchor);
break;
default:
break;
@@ -186,37 +466,54 @@ public class AnchorUtil {
AnchorType at = AnchorType.getType(a);
if (at == AnchorType.ACTIVITY) {
// adjust the Activity Anchors
+ int index;
FixPointAnchor anchor = (FixPointAnchor) a;
- AnchorLocation al = AnchorLocation.getLocation(anchor);
- switch (al) {
+ AnchorSite site = AnchorSite.getSite(anchor);
+ switch (site) {
case BOTTOM:
- bottomOffset += w/bottomCount;
+ index = calculateIndex(anchor, bottomAnchors);
+ if (index>=0)
+ bottomOffset = (index+1) * w/(bottomCount+1);
+ else
+ bottomOffset += w/(bottomCount+1);
anchor.setLocation(gaService.createPoint(bottomOffset, h));
break;
case CENTER:
break;
case LEFT:
- leftOffset += h/leftCount;
+ index = calculateIndex(anchor, leftAnchors);
+ if (index>=0)
+ leftOffset = (index+1) * w/(leftCount+1);
+ else
+ leftOffset += h/(leftCount+1);
anchor.setLocation(gaService.createPoint(0, leftOffset));
break;
case RIGHT:
- rightOffset += h/rightCount;
+ index = calculateIndex(anchor, rightAnchors);
+ if (index>=0)
+ rightOffset = (index+1) * w/(rightCount+1);
+ else
+ rightOffset += h/(rightCount+1);
anchor.setLocation(gaService.createPoint(w, rightOffset));
break;
case TOP:
- topOffset += w/topCount;
+ index = calculateIndex(anchor, topAnchors);
+ if (index>=0)
+ topOffset = (index+1) * w/(topCount+1);
+ else
+ topOffset += w/(topCount+1);
anchor.setLocation(gaService.createPoint(topOffset, 0));
break;
default:
break;
}
}
- else if (at == AnchorType.GATEWAY) {
+ else if (at == AnchorType.GATEWAY || at == AnchorType.MESSAGELINK) {
// adjust the Gateway and Event Anchors: all of these
// are attached to the middle of an edge
FixPointAnchor anchor = (FixPointAnchor) a;
- AnchorLocation al = AnchorLocation.getLocation(anchor);
- switch (al) {
+ AnchorSite site = AnchorSite.getSite(anchor);
+ switch (site) {
case BOTTOM:
anchor.setLocation(gaService.createPoint(w/2, h));
break;
@@ -245,8 +542,8 @@ public class AnchorUtil {
p.setX(w);
if (p.getY() > h)
p.setY(h);
- AnchorLocation al = AnchorLocation.getLocation(anchor);
- switch (al) {
+ AnchorSite site = AnchorSite.getSite(anchor);
+ switch (site) {
case BOTTOM:
anchor.setLocation(gaService.createPoint(p.getX(), h));
break;
@@ -268,260 +565,63 @@ public class AnchorUtil {
}
}
}
-
- public static int countAnchors(AnchorContainer ac, AnchorLocation al) {
- int count = 0;
- for (Anchor a : ac.getAnchors()) {
- if (peService.getPropertyValue(a, GraphitiConstants.ANCHOR_TYPE)!=null)
- if (al==AnchorLocation.getLocation((FixPointAnchor)a))
- ++count;
- }
- return count;
- }
-
- public static List<Connection> getConnections(AnchorContainer ac, AnchorLocation al) {
- List<Connection> connections = new ArrayList<Connection>();
- for (Anchor a : ac.getAnchors()) {
- if (peService.getPropertyValue(a, GraphitiConstants.ANCHOR_TYPE)!=null)
- if (al==AnchorLocation.getLocation((FixPointAnchor)a)) {
- connections.addAll(a.getIncomingConnections());
- connections.addAll(a.getOutgoingConnections());
- }
- }
- return connections;
- }
-
-// public static void rotateMovableAnchors(AnchorContainer ac, AnchorLocation al) {
-// for (Anchor a : ac.getAnchors()) {
-// String property = peService.getPropertyValue(a, GraphitiConstants.BOUNDARY_ANCHOR);
-// if (GraphitiConstants.ACTIVITY_ANCHOR.equals(property)) {
-// if (al==AnchorLocation.getLocation((FixPointAnchor)a)) {
-// ac.getAnchors().remove(a);
-// ac.getAnchors().add(a);
-// break;
-// }
-// }
-// }
-// }
- /**
- * @param parent
- */
- private static void deleteUnusedAnchors(AnchorContainer ac) {
- if (ac!=null && !AnchorUtil.isConnectionPoint(ac)) {
- List<Anchor> deleted = new ArrayList<Anchor>();
-
- for (Anchor a : ac.getAnchors()) {
- String property = peService.getPropertyValue(a, GraphitiConstants.ANCHOR_TYPE);
- if ( property!=null &&
- a.getIncomingConnections().isEmpty() &&
- a.getOutgoingConnections().isEmpty()) {
- deleted.add(a);
- }
- }
-
- for (Anchor a : deleted) {
- peService.deletePictogramElement(a);
- }
+ private static FixPointAnchor getOpposite(FixPointAnchor anchor) {
+ Anchor a = null;
+ if (anchor.getOutgoingConnections().isEmpty()) {
+ if (anchor.getIncomingConnections().isEmpty())
+ return null;
+ a = anchor.getIncomingConnections().get(0).getStart();
}
+ else
+ a = anchor.getOutgoingConnections().get(0).getEnd();
+
+ return a instanceof FixPointAnchor ? (FixPointAnchor)a : null;
}
-
- public static void adjustAnchors(AnchorContainer ac) {
- deleteUnusedAnchors(ac);
- relocateAnchors(ac);
- }
-
- // Connection points allow creation of anchors on FreeFormConnections
- private static class ConnectionPointShapeAdapter extends AdapterImpl {
- Connection connection;
- Shape shape;
- boolean deleting = false;
- double midpoint = 0.5;
-
- public static ConnectionPointShapeAdapter adapt(Connection connection, Shape shape) {
- return new ConnectionPointShapeAdapter(connection, shape);
- }
-
- private ConnectionPointShapeAdapter(Connection connection, Shape shape) {
- this.connection = connection;
- this.shape = shape;
- connection.eAdapters().add(this);
- shape.eAdapters().add(this);
- shape.getAnchors().get(0).eAdapters().add(this);
-
- setTarget(connection);
- int x = shape.getGraphicsAlgorithm().getX();
- int y = shape.getGraphicsAlgorithm().getY();
- int dx = Integer.MAX_VALUE;
- int dy = Integer.MAX_VALUE;
- for (double d=0; d<=1.0; d += 0.05) {
- ILocation loc = Graphiti.getPeService().getConnectionMidpoint(connection, d);
- if (Math.abs(x - loc.getX()) < dx || Math.abs(y - loc.getY()) < dy) {
- dx = Math.abs(x - loc.getX());
- dy = Math.abs(y - loc.getY());
- midpoint = d;
+ private static int calculateIndex(FixPointAnchor anchor, List<FixPointAnchor> all) {
+ // TODO: fix this: should probably look at the location of the closest bendboint,
+ // not the opposite anchor.
+ if (true) return -1;
+ TreeMap<Integer, FixPointAnchor> offsets = new TreeMap<Integer, FixPointAnchor>();
+ AnchorSite site = AnchorSite.getSite(anchor);
+ Connection c;
+ for (FixPointAnchor a : all) {
+ FixPointAnchor a2 = getOpposite(a);
+ if (a2!=null) {
+ ILocation loc = Graphiti.getPeService().getLocationRelativeToDiagram(a2);
+ if (site==AnchorSite.TOP || site==AnchorSite.BOTTOM) {
+ // collect the x coordinates of opposite anchor
+ offsets.put(loc.getX(), a);
}
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
- */
- @Override
- public void notifyChanged(Notification notification) {
- // if the connection is no longer connected to this shape
- // then delete the Connection Point
- if (!deleting) {
- Anchor a = shape.getAnchors().get(0);
- if (notification.getNotifier() == a) {
- // something changed in the anchor
- if (a.getIncomingConnections().isEmpty() && a.getOutgoingConnections().isEmpty()) {
- // the anchor has no connections, so we need to delete it
- deleting = true;
- deleteConnectionPoint(shape);
- return;
- }
- }
- else
- {
- ILocation loc = Graphiti.getPeService().getConnectionMidpoint(connection, midpoint);
- Graphiti.getGaService().setLocation(shape.getGraphicsAlgorithm(), loc.getX(), loc.getY());
+ else {
+ offsets.put(loc.getY(), a);
}
}
}
- }
-
- public static void deleteConnectionPoint(AnchorContainer shape) {
- if (isConnectionPoint(shape)) {
- Connection connection = getConnectionPointOwner(shape);
- if (connection!=null) {
- for (Adapter a : shape.eAdapters()) {
- if (a instanceof ConnectionPointShapeAdapter) {
- connection.eAdapters().remove(a);
- }
- }
- connection.getLink().getBusinessObjects().remove(shape);
- }
- Graphiti.getPeService().deletePictogramElement(shape);
+ int index = 0;
+ for (Entry<Integer, FixPointAnchor> entry : offsets.entrySet()) {
+ if (entry.getValue() == anchor)
+ return index;
+ ++index;
}
- }
-
- public static Shape createConnectionPoint(IFeatureProvider fp, Connection connection, ILocation location) {
-
- Shape connectionPointShape = null;
-
- Diagram diagram = fp.getDiagramTypeProvider().getDiagram();
- connectionPointShape = createConnectionPoint(location, diagram);
- fp.link(connectionPointShape, connection);
- connection.getLink().getBusinessObjects().add(connectionPointShape);
- BaseElement be = BusinessObjectUtil.getFirstBaseElement(connection);
- BPMNEdge bpmnEdge = DIUtils.findBPMNEdge(be);
- if (bpmnEdge!=null)
- fp.link(connectionPointShape, bpmnEdge);
-
- ConnectionPointShapeAdapter.adapt(connection, connectionPointShape);
- return connectionPointShape;
+ return -1;
}
- public static Shape createConnectionPoint(ILocation location, ContainerShape cs) {
-
- // create a circle for the connection point shape
- Shape connectionPointShape = createService.createShape(cs, true);
- peService.setPropertyValue(connectionPointShape, GraphitiConstants.CONNECTION_POINT_KEY, GraphitiConstants.CONNECTION_POINT);
- Ellipse ellipse = createService.createEllipse(connectionPointShape);
- int x = 0, y = 0;
- if (location != null) {
- x = location.getX();
- y = location.getY();
- }
- ellipse.setFilled(true);
- Diagram diagram = peService.getDiagramForPictogramElement(connectionPointShape);
- ellipse.setForeground(Graphiti.getGaService().manageColor(diagram, StyleUtil.CLASS_FOREGROUND));
- ellipse.setWidth(CONNECTION_POINT_SIZE);
- ellipse.setHeight(CONNECTION_POINT_SIZE);
+ private static PictogramLink createPictogramLink(PictogramElement pe) {
+ PictogramLink ret = null;
- // create the anchor
- getConnectionPointAnchor(connectionPointShape);
-
- // set the location
- setConnectionPointLocation(connectionPointShape, x, y);
-
- return connectionPointShape;
- }
-
- public static FixPointAnchor getConnectionPointAnchor(Shape connectionPointShape) {
- if (connectionPointShape.getAnchors().size()==0) {
- FixPointAnchor anchor = createService.createFixPointAnchor(connectionPointShape);
- peService.setPropertyValue(anchor, GraphitiConstants.CONNECTION_POINT_KEY, GraphitiConstants.CONNECTION_POINT);
-
- // if the anchor doesn't have a GraphicsAlgorithm, GEF will throw a fit
- // so create an invisible rectangle for it
- createService.createInvisibleRectangle(anchor);
- }
- return (FixPointAnchor)connectionPointShape.getAnchors().get(0);
- }
+ Diagram diagram = Graphiti.getPeService().getDiagramForPictogramElement(pe);
+ if (diagram != null) {
+ // create new link
+ ret = PictogramsFactory.eINSTANCE.createPictogramLink();
+ ret.setPictogramElement(pe);
- public static ILocation getConnectionPointLocation(Shape connectionPointShape) {
- ILocation location = ShapeDecoratorUtil.peService.getLocationRelativeToDiagram(connectionPointShape);
- int x = location.getX() + CONNECTION_POINT_SIZE / 2;
- int y = location.getY() + CONNECTION_POINT_SIZE / 2;
- location.setX(x);
- location.setY(y);
- return location;
- }
-
- public static void setConnectionPointLocation(Shape connectionPointShape, int x, int y) {
-
- if (connectionPointShape.getAnchors().size()==0) {
- // anchor has not been created yet - need to set both location AND size
- layoutService.setLocationAndSize(
- connectionPointShape.getGraphicsAlgorithm(),
- x - CONNECTION_POINT_SIZE / 2, y - CONNECTION_POINT_SIZE / 2,
- CONNECTION_POINT_SIZE, CONNECTION_POINT_SIZE);
- }
- else {
- // already created - just set the location
- layoutService.setLocation(
- connectionPointShape.getGraphicsAlgorithm(),
- x - CONNECTION_POINT_SIZE / 2, y - CONNECTION_POINT_SIZE / 2);
- }
-
- FixPointAnchor anchor = getConnectionPointAnchor(connectionPointShape);
- anchor.setLocation( Graphiti.getCreateService().createPoint(CONNECTION_POINT_SIZE / 2,CONNECTION_POINT_SIZE / 2) );
- layoutService.setLocation(
- anchor.getGraphicsAlgorithm(),
- CONNECTION_POINT_SIZE / 2,CONNECTION_POINT_SIZE / 2);
- }
-
- public static List<Shape> getConnectionPoints(Connection connection) {
- ArrayList<Shape> list = new ArrayList<Shape>();
- if (connection.getLink()!=null) {
- for (Object o : connection.getLink().getBusinessObjects()) {
- if (o instanceof Shape && isConnectionPoint((Shape)o)) {
- list.add((Shape)o);
- }
- }
+ // add new link to diagram
+ diagram.getPictogramLinks().add(ret);
}
- return list;
+ return ret;
}
- public static boolean isConnectionPoint(PictogramElement pe) {
- if (pe!=null) {
- String value =peService.getPropertyValue(pe, GraphitiConstants.CONNECTION_POINT_KEY);
- return GraphitiConstants.CONNECTION_POINT.equals(value);
- }
- return false;
- }
-
- public static Connection getConnectionPointOwner(AnchorContainer connectionPointShape) {
- if (isConnectionPoint(connectionPointShape) && connectionPointShape.getLink()!=null) {
- for (Object o : connectionPointShape.getLink().getBusinessObjects()) {
- if (o instanceof Connection)
- return (Connection) o;
- }
- }
- return null;
- }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/BusinessObjectUtil.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/BusinessObjectUtil.java
index 6dd0dcd5..43d6ee8f 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/BusinessObjectUtil.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/BusinessObjectUtil.java
@@ -53,9 +53,9 @@ public class BusinessObjectUtil {
return false;
}
// if this is a connection point, look at business objects of the connection
- if (AnchorUtil.isConnectionPoint(elem)) {
- elem = AnchorUtil.getConnectionPointOwner((Shape)elem);
- }
+// if (AnchorUtil.isConnectionPoint(elem)) {
+// elem = AnchorUtil.getConnectionPointOwner((Shape)elem);
+// }
EList<EObject> businessObjs = elem.getLink().getBusinessObjects();
for (EObject eObject : businessObjs) {
if (clazz.isInstance(eObject)) {
@@ -67,9 +67,9 @@ public class BusinessObjectUtil {
@SuppressWarnings("rawtypes")
public static boolean containsChildElementOfType(PictogramElement root, Class clazz) {
- if (AnchorUtil.isConnectionPoint(root)) {
- root = AnchorUtil.getConnectionPointOwner((Shape)root);
- }
+// if (AnchorUtil.isConnectionPoint(root)) {
+// root = AnchorUtil.getConnectionPointOwner((Shape)root);
+// }
if (root instanceof ContainerShape) {
ContainerShape rootContainer = (ContainerShape) root;
for (Shape currentShape : rootContainer.getChildren()) {
@@ -96,9 +96,9 @@ public class BusinessObjectUtil {
return null;
}
// if this is a connection point, look at business objects of the connection
- if (AnchorUtil.isConnectionPoint(elem)) {
- elem = AnchorUtil.getConnectionPointOwner((Shape)elem);
- }
+// if (AnchorUtil.isConnectionPoint(elem)) {
+// elem = AnchorUtil.getConnectionPointOwner((Shape)elem);
+// }
EList<EObject> businessObjs = elem.getLink().getBusinessObjects();
for (EObject eObject : businessObjs) {
if (clazz.isInstance(eObject)) {
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java
index 079130e3..17561c9d 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java
@@ -758,9 +758,9 @@ public class FeatureSupport {
FeatureSupport.updateLabel(fp, connection, null);
// also update any Connections that are connected to this Connection
- for (Shape shape : AnchorUtil.getConnectionPoints(connection)) {
- updateConnections(fp, shape);
- }
+// for (Shape shape : AnchorUtil.getConnectionPoints(connection)) {
+// updateConnections(fp, shape);
+// }
return layoutChanged || updateChanged;
}
@@ -806,7 +806,7 @@ public class FeatureSupport {
}
}
updateConnections(fp, ac, alreadyUpdated);
- AnchorUtil.relocateAnchors((Shape)ac);
+// AnchorUtil.relocateAnchors((Shape)ac);
}
public static void updateCategoryValues(IFeatureProvider fp, List<ContainerShape> shapes) {
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/GraphicsUtil.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/GraphicsUtil.java
index 4aff12f0..5caf25e4 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/GraphicsUtil.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/GraphicsUtil.java
@@ -323,7 +323,7 @@ public class GraphicsUtil {
p2End.getX(), p2End.getY()
);
}
-
+
/**
* Check if two line segments intersects. Integer domain.
*
@@ -548,13 +548,6 @@ public class GraphicsUtil {
ILocation loc = peService.getLocationRelativeToDiagram(anchor);
System.out.print(" at "+loc.getX()+", "+loc.getY()); //$NON-NLS-1$ //$NON-NLS-2$
GraphicsUtil.dump(" parent=", (ContainerShape)anchor.getParent()); //$NON-NLS-1$
-// if (AnchorUtil.isBoundaryAnchor(anchor)) {
-// String property = Graphiti.getPeService().getPropertyValue(
-// anchor, GraphitiConstants.BOUNDARY_FIXPOINT_ANCHOR);
-// if (property != null && anchor instanceof FixPointAnchor) {
-// System.out.println(" location="+AnchorLocation.getLocation(property)); //$NON-NLS-1$
-// }
-// }
}
}
@@ -605,29 +598,29 @@ public class GraphicsUtil {
}
}
- public static GraphicsUtil.LineSegment[] getEdges(Shape shape) {
+ public static LineSegment[] getEdges(Shape shape) {
ILocation loc = peService.getLocationRelativeToDiagram(shape);
IDimension size = calculateSize(shape);
- GraphicsUtil.LineSegment top = new GraphicsUtil.LineSegment(loc.getX(),loc.getY(),
+ LineSegment top = new LineSegment(loc.getX(),loc.getY(),
loc.getX()+size.getWidth(), loc.getY());
- GraphicsUtil.LineSegment left = new GraphicsUtil.LineSegment(loc.getX(),loc.getY(), loc.getX(),
+ LineSegment left = new LineSegment(loc.getX(),loc.getY(), loc.getX(),
loc.getY()+size.getHeight());
- GraphicsUtil.LineSegment bottom = new GraphicsUtil.LineSegment(loc.getX(), loc.getY()+size.getHeight(),
+ LineSegment bottom = new LineSegment(loc.getX(), loc.getY()+size.getHeight(),
loc.getX()+size.getWidth(), loc.getY()+size.getHeight());
- GraphicsUtil.LineSegment right = new GraphicsUtil.LineSegment(loc.getX()+size.getWidth(), loc.getY(),
+ LineSegment right = new LineSegment(loc.getX()+size.getWidth(), loc.getY(),
loc.getX()+size.getWidth(), loc.getY()+size.getHeight());
- return new GraphicsUtil.LineSegment[] {top, bottom, left, right};
+ return new LineSegment[] {top, bottom, left, right};
}
- public static GraphicsUtil.LineSegment findNearestEdge(Shape shape, Point p) {
- GraphicsUtil.LineSegment edges[] = getEdges(shape);
- GraphicsUtil.LineSegment top = edges[0];
- GraphicsUtil.LineSegment bottom = edges[1];
- GraphicsUtil.LineSegment left = edges[2];
- GraphicsUtil.LineSegment right = edges[3];
+ public static LineSegment findNearestEdge(Shape shape, Point p) {
+ LineSegment edges[] = getEdges(shape);
+ LineSegment top = edges[0];
+ LineSegment bottom = edges[1];
+ LineSegment left = edges[2];
+ LineSegment right = edges[3];
double minDist;
double dist;
- GraphicsUtil.LineSegment result;
+ LineSegment result;
minDist = top.getDistance(p);
result = top;
@@ -650,6 +643,37 @@ public class GraphicsUtil {
return result;
}
+ public static LineSegment findNearestEdge(Shape shape, Point p1, Point p2) {
+ LineSegment edges[] = getEdges(shape);
+ LineSegment top = edges[0];
+ LineSegment bottom = edges[1];
+ LineSegment left = edges[2];
+ LineSegment right = edges[3];
+ double minDist;
+ double dist;
+ LineSegment result;
+
+ minDist = top.getDistance(p1) + top.getDistance(p2);
+ result = top;
+
+ dist = bottom.getDistance(p1) + bottom.getDistance(p2);
+ if (dist<minDist) {
+ minDist = dist;
+ result = bottom;
+ }
+ dist = left.getDistance(p1) + left.getDistance(p2);
+ if (dist<minDist) {
+ minDist = dist;
+ result = left;
+ }
+ dist = right.getDistance(p1) + right.getDistance(p2);
+ if (dist<minDist) {
+ minDist = dist;
+ result = right;
+ }
+ return result;
+ }
+
public static void sendToFront(Shape shape) {
peService.sendToFront(shape);
BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(shape, BPMNShape.class);
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/diagram/BPMN2FeatureProvider.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/diagram/BPMN2FeatureProvider.java
index fd1b0798..9936d3a3 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/diagram/BPMN2FeatureProvider.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/diagram/BPMN2FeatureProvider.java
@@ -803,8 +803,10 @@ public class BPMN2FeatureProvider extends DefaultFeatureProvider implements IBpm
if (le!=null) {
((AbstractBpmn2AddFeature)addElementFeature).updatePictogramElement(context, pe);
- if (!DIImport.isImporting(context))
+ if (!DIImport.isImporting(context)) {
+ context.putProperty(GraphitiConstants.INITIAL_UPDATE, Boolean.TRUE);
((AbstractBpmn2AddFeature)addElementFeature).layoutPictogramElement(context, pe);
+ }
}
}
return pe;
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/ConnectionLayerClippingStrategy.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/ConnectionLayerClippingStrategy.java
index 0700cdda..93b87ffd 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/ConnectionLayerClippingStrategy.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/ConnectionLayerClippingStrategy.java
@@ -66,12 +66,6 @@ public class ConnectionLayerClippingStrategy implements IClippingStrategy {
Object model = part.getModel();
if (model instanceof Connection) {
Connection connection = (Connection)model;
- AnchorContainer source = connection.getStart().getParent();
- AnchorContainer target = connection.getEnd().getParent();
- if (source.eContainer() != target.eContainer()) {
- // don't clip the connection if source and target are not in the same container
- return new Rectangle[] {childFigure.getBounds()};
- }
BaseElement businessObject = BusinessObjectUtil.getFirstBaseElement(connection);
if (businessObject instanceof MessageFlow) {
ContainerShape messageShape = MessageFlowFeatureContainer.findMessageShape(connection);
@@ -82,6 +76,12 @@ public class ConnectionLayerClippingStrategy implements IClippingStrategy {
}
}
else if (businessObject!=null) {
+ AnchorContainer source = connection.getStart().getParent();
+ AnchorContainer target = connection.getEnd().getParent();
+ if (source.eContainer() != target.eContainer()) {
+ // don't clip the connection if source and target are not in the same container
+ return new Rectangle[] {childFigure.getBounds()};
+ }
EObject container = businessObject.eContainer();
if (container instanceof SubProcess) {
// don't clip if contents of SubProcess have been moved to a different
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/AddChoreographyMessageFeature.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/AddChoreographyMessageFeature.java
index 9990e81f..b54e0fb8 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/AddChoreographyMessageFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/AddChoreographyMessageFeature.java
@@ -18,20 +18,22 @@ import java.util.List;
import org.eclipse.bpmn2.Choreography;
import org.eclipse.bpmn2.ChoreographyTask;
+import org.eclipse.bpmn2.Definitions;
import org.eclipse.bpmn2.Message;
import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.Participant;
-import org.eclipse.bpmn2.RootElement;
import org.eclipse.bpmn2.di.BPMNShape;
-import org.eclipse.bpmn2.modeler.core.adapters.ExtendedPropertiesProvider;
import org.eclipse.bpmn2.modeler.core.features.choreography.ChoreographyUtil;
+import org.eclipse.bpmn2.modeler.core.model.Bpmn2ModelerFactory;
import org.eclipse.bpmn2.modeler.core.model.ModelHandler;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.ModelUtil;
import org.eclipse.bpmn2.modeler.ui.ImageProvider;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
@@ -48,7 +50,7 @@ import org.eclipse.swt.widgets.Display;
public class AddChoreographyMessageFeature extends AbstractCustomFeature {
protected boolean changesDone = false;
-
+
private static ILabelProvider labelProvider = new ILabelProvider() {
public void removeListener(ILabelProviderListener listener) {
@@ -67,7 +69,7 @@ public class AddChoreographyMessageFeature extends AbstractCustomFeature {
}
public String getText(Object element) {
- return ChoreographyUtil.getMessageName((Message)element);
+ return ChoreographyUtil.getMessageName((Message) element);
}
public Image getImage(Object element) {
@@ -82,15 +84,15 @@ public class AddChoreographyMessageFeature extends AbstractCustomFeature {
public AddChoreographyMessageFeature(IFeatureProvider fp) {
super(fp);
}
-
+
@Override
public String getName() {
- return Messages.AddChoreographyMessageFeature_Name;
+ return Messages.AddChoreographyMessageFeature_Name;
}
-
+
@Override
public String getDescription() {
- return Messages.AddChoreographyMessageFeature_Description;
+ return Messages.AddChoreographyMessageFeature_Description;
}
@Override
@@ -110,107 +112,101 @@ public class AddChoreographyMessageFeature extends AbstractCustomFeature {
PictogramElement pe = pes[0];
Object bo = getBusinessObjectForPictogramElement(pe);
if (pe instanceof ContainerShape && bo instanceof Participant) {
- Participant participant = (Participant)bo;
-
- Object parent = getBusinessObjectForPictogramElement(((ContainerShape)pe).getContainer());
+ Participant participant = (Participant) bo;
+
+ Object parent = getBusinessObjectForPictogramElement(((ContainerShape) pe).getContainer());
if (parent instanceof ChoreographyTask) {
-
- // Check if choreography task already associated with MessageFlow
- // with this participant as the source
- ChoreographyTask ct=(ChoreographyTask)parent;
-
- if (ct.getParticipantRefs().size() >= 2) {
- boolean canAdd=true;
-
- for (MessageFlow mf : ct.getMessageFlowRef()) {
- if (mf.getSourceRef() != null &&
- mf.getSourceRef().equals(participant)) {
- canAdd = false;
- break;
+
+ ChoreographyTask choreographyTask = (ChoreographyTask) parent;
+
+ // Check if choreography task already associated with
+ // MessageFlow with this Participant as the source
+ if (choreographyTask.getParticipantRefs().size() == 2) {
+ for (MessageFlow mf : choreographyTask.getMessageFlowRef()) {
+ if (mf.getSourceRef() != null && mf.getSourceRef().equals(participant)) {
+ return false;
}
}
-
- return (canAdd);
+ return true;
}
}
}
}
return false;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
*/
@Override
public void execute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- PictogramElement pe = pes[0];
- Object bo = getBusinessObjectForPictogramElement(pe);
- if (pe instanceof ContainerShape && bo instanceof Participant) {
- ModelHandler mh = ModelHandler.getInstance(getDiagram());
-
- ContainerShape containerShape = (ContainerShape)pe;
- Participant participant = (Participant)bo;
-
- Object parent = getBusinessObjectForPictogramElement(containerShape.getContainer());
- if (parent instanceof ChoreographyTask) {
- ChoreographyTask ct=(ChoreographyTask)parent;
-
- Message message = null;
- List<Message> messageList = new ArrayList<Message>();
- message = mh.create(Message.class);
- message.setName(message.getId());
-
- messageList.add(message);
- for (RootElement re : mh.getDefinitions().getRootElements()) {
- if (re instanceof Message) {
- messageList.add((Message)re);
- }
- }
-
- Message result = message;
-
- if (messageList.size()>1) {
- PopupMenu popupMenu = new PopupMenu(messageList, labelProvider);
- changesDone = popupMenu.show(Display.getCurrent().getActiveShell());
- if (changesDone) {
- result = (Message) popupMenu.getResult();
- }
- }
- else
- changesDone = true;
-
- if (changesDone) {
- if (result==message) { // the new one
- message.setName( ExtendedPropertiesProvider.getTextValue(message)); // ModelUtil.toDisplayName(message.getId()) );
-
- mh.getDefinitions().getRootElements().add(result);
- }
-
- java.util.List<Participant> parts=new java.util.ArrayList<Participant>(
- ct.getParticipantRefs());
- parts.remove(participant);
-
- if (parts.size() == 1) {
- MessageFlow mf=mh.createMessageFlow(participant, parts.get(0));
- mf.setName(ModelUtil.toCanonicalString(mf.getId()));
-
- Choreography choreography = (Choreography)ct.eContainer();
- choreography.getMessageFlows().add(mf);
-
- mf.setMessageRef(result);
- ct.getMessageFlowRef().add(mf);
-
- BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(containerShape, BPMNShape.class);
- bpmnShape.setIsMessageVisible(true);
-
- } else {
- // TODO: REPORT ERROR??
- }
- }
- }
+ PictogramElement pe = context.getPictogramElements()[0];
+ ContainerShape participantShape = (ContainerShape) pe;
+ ContainerShape choreographyTaskShape = (ContainerShape) participantShape.eContainer();
+ Participant participant = (Participant) getBusinessObjectForPictogramElement(participantShape);
+ ChoreographyTask choreographyTask = (ChoreographyTask) getBusinessObjectForPictogramElement(choreographyTaskShape);
+ Definitions definitions = ModelUtil.getDefinitions(choreographyTask);
+ ModelHandler mh = ModelHandler.getInstance(choreographyTask);
+
+ Message message = Bpmn2ModelerFactory.create(Message.class);
+ String oldName = message.getName();
+ message.setName(Messages.AddChoreographyMessageFeature_New);
+ message.setId(null);
+
+ List<Message> messageList = new ArrayList<Message>();
+ messageList.add(message);
+ messageList.addAll( ModelUtil.getAllRootElements(definitions, Message.class) );
+
+ Message result = message;
+ if (messageList.size() > 1) {
+ PopupMenu popupMenu = new PopupMenu(messageList, labelProvider);
+ changesDone = popupMenu.show(Display.getCurrent().getActiveShell());
+ if (changesDone) {
+ result = (Message) popupMenu.getResult();
+ } else {
+ EcoreUtil.delete(message);
+ message = null;
+ }
+ } else
+ changesDone = true;
+
+ if (changesDone) {
+ if (result == message) {
+ // the new one
+ definitions.getRootElements().add(message);
+ message.setId(null);
+ ModelUtil.setID(message);
+ message.setName(oldName);
+ } else {
+ // and existing one
+ message = result;
}
+
+ // get the other Participant to which this Participant will be sending the Message
+ // Note that we have already checked (in canExecute()) that this Choreography Task
+ // has only two Participants.
+ Participant otherParticipant;
+ if (choreographyTask.getParticipantRefs().get(0)==participant)
+ otherParticipant = choreographyTask.getParticipantRefs().get(1);
+ else
+ otherParticipant = choreographyTask.getParticipantRefs().get(0);
+
+ MessageFlow messageFlow = mh.createMessageFlow(participant, otherParticipant);
+ messageFlow.setName(ModelUtil.toCanonicalString(messageFlow.getId()));
+
+ Choreography choreography = (Choreography) choreographyTask.eContainer();
+ choreography.getMessageFlows().add(messageFlow);
+
+ messageFlow.setMessageRef(message);
+ choreographyTask.getMessageFlowRef().add(messageFlow);
+
+ BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(participantShape, BPMNShape.class);
+ bpmnShape.setIsMessageVisible(true);
+
+ UpdateContext updateContext = new UpdateContext(choreographyTaskShape);
+ getFeatureProvider().updateIfPossible(updateContext);
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyMessageLinkFeatureContainer.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyMessageLinkFeatureContainer.java
index bc0b9cae..1689d020 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyMessageLinkFeatureContainer.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyMessageLinkFeatureContainer.java
@@ -12,12 +12,24 @@
******************************************************************************/
package org.eclipse.bpmn2.modeler.ui.features.choreography;
+import java.util.List;
+
+import org.eclipse.bpmn2.ChoreographyActivity;
+import org.eclipse.bpmn2.ChoreographyTask;
+import org.eclipse.bpmn2.MessageFlow;
+import org.eclipse.bpmn2.di.BPMNShape;
import org.eclipse.bpmn2.modeler.core.features.DefaultDeleteBPMNShapeFeature;
import org.eclipse.bpmn2.modeler.core.features.DirectEditBaseElementFeature;
+import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
import org.eclipse.bpmn2.modeler.core.features.MultiUpdateFeature;
import org.eclipse.bpmn2.modeler.core.features.PropertyBasedFeatureContainer;
import org.eclipse.bpmn2.modeler.core.features.choreography.ChoreographyUtil;
import org.eclipse.bpmn2.modeler.core.features.label.UpdateLabelFeature;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
+import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
+import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
+import org.eclipse.bpmn2.modeler.core.utils.Tuple;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.ICreateFeature;
@@ -34,17 +46,20 @@ import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.IMoveConnectionDecoratorContext;
import org.eclipse.graphiti.features.context.IMoveShapeContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.features.impl.AbstractMoveShapeFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveConnectionDecoratorFeature;
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
public class ChoreographyMessageLinkFeatureContainer extends PropertyBasedFeatureContainer {
@Override
protected String getPropertyKey() {
- return ChoreographyUtil.MESSAGE_LINK;
+ return GraphitiConstants.MESSAGE_LINK;
}
@Override
@@ -148,53 +163,54 @@ public class ChoreographyMessageLinkFeatureContainer extends PropertyBasedFeatur
@Override
public void delete(IDeleteContext context) {
ContainerShape envelope = (ContainerShape) context.getPictogramElement();
-// Map<AnchorLocation, BoundaryAnchor> boundaryAnchors = AnchorUtil.getBoundaryAnchors(envelope);
-// BoundaryAnchor topBoundaryAnchor = boundaryAnchors.get(AnchorLocation.TOP);
-// BoundaryAnchor bottomBoundaryAnchor = boundaryAnchors.get(AnchorLocation.BOTTOM);
-// modifyAffectedBands(topBoundaryAnchor);
-// modifyAffectedBands(bottomBoundaryAnchor);
+ for (FixPointAnchor anchor : AnchorUtil.getAnchors(envelope))
+ modifyAffectedBands(anchor);
super.delete(context);
+
+
+ System.out.println();
}
-// private void modifyAffectedBands(BoundaryAnchor anchor) {
-//
-// for (Connection connection : anchor.anchor.getIncomingConnections()) {
-//
-// EObject start = connection.getStart().eContainer();
-//
-// if (!(start instanceof ContainerShape)) {
-// continue;
-// }
-//
-// ChoreographyActivity ca = BusinessObjectUtil.getFirstElementOfType((PictogramElement)start, ChoreographyActivity.class);
-// if (ca==null) {
-// continue;
-// }
-// MessageFlow mf = (MessageFlow)BusinessObjectUtil.getBusinessObjectForPictogramElement(connection);
-//
-// List<ContainerShape> bands = FeatureSupport
-// .getParticipantBandContainerShapes((ContainerShape) start);
-//
-// Tuple<List<ContainerShape>, List<ContainerShape>> topAndBottomBands = FeatureSupport
-// .getTopAndBottomBands(bands);
-//
-// List<ContainerShape> affectedBands = anchor.locationType == AnchorLocation.BOTTOM ? topAndBottomBands
-// .getFirst() : topAndBottomBands.getSecond();
-//
-// for (ContainerShape bottomBand : affectedBands) {
-// BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(bottomBand, BPMNShape.class);
-// bpmnShape.setIsMessageVisible(false);
-// }
-//
-// ChoreographyUtil.removeChoreographyMessageLink(connection);
-//
-// if (ca instanceof ChoreographyTask) {
-// ChoreographyTask ct = (ChoreographyTask) ca;
-// ct.getMessageFlowRef().remove(mf);
-// }
-// break;
-// }
-// }
+ private void modifyAffectedBands(FixPointAnchor anchor) {
+
+ for (Connection connection : anchor.getIncomingConnections()) {
+
+ AnchorContainer choreographyActivityShape = connection.getStart().getParent();
+
+ if (!(choreographyActivityShape instanceof ContainerShape)) {
+ continue;
+ }
+
+ ChoreographyActivity choreographyActivity = BusinessObjectUtil.getFirstElementOfType(choreographyActivityShape, ChoreographyActivity.class);
+ if (choreographyActivity==null) {
+ continue;
+ }
+ MessageFlow messageFlow = (MessageFlow)BusinessObjectUtil.getBusinessObjectForPictogramElement(connection);
+
+ List<ContainerShape> bands = FeatureSupport.getParticipantBandContainerShapes((ContainerShape) choreographyActivityShape);
+
+ Tuple<List<ContainerShape>, List<ContainerShape>> topAndBottomBands = FeatureSupport.getTopAndBottomBands(bands);
+
+ List<ContainerShape> affectedBands = AnchorSite.getSite(anchor) == AnchorSite.BOTTOM ?
+ topAndBottomBands.getFirst() :
+ topAndBottomBands.getSecond();
+
+ for (ContainerShape band : affectedBands) {
+ BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(band, BPMNShape.class);
+ bpmnShape.setIsMessageVisible(false);
+ }
+
+ ChoreographyUtil.removeChoreographyMessageLink(connection);
+
+ if (choreographyActivity instanceof ChoreographyTask) {
+ ChoreographyTask ct = (ChoreographyTask) choreographyActivity;
+ ct.getMessageFlowRef().remove(messageFlow);
+ UpdateContext updateContext = new UpdateContext(choreographyActivityShape);
+ getFeatureProvider().updateIfPossible(updateContext);
+ }
+ break;
+ }
+ }
};
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographySelectionBehavior.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographySelectionBehavior.java
index 000e8e02..66891ca2 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographySelectionBehavior.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographySelectionBehavior.java
@@ -13,10 +13,8 @@
package org.eclipse.bpmn2.modeler.ui.features.choreography;
import java.util.Collection;
-import java.util.Iterator;
-import org.eclipse.bpmn2.modeler.core.features.choreography.ChoreographyUtil;
-import org.eclipse.graphiti.mm.PropertyContainer;
+import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
@@ -26,16 +24,11 @@ import org.eclipse.graphiti.services.Graphiti;
public class ChoreographySelectionBehavior {
public static boolean canApplyTo(PictogramElement pe) {
- if (!(pe instanceof PropertyContainer)) {
- return false;
+ if (pe instanceof ContainerShape) {
+ String property = Graphiti.getPeService().getPropertyValue(pe, GraphitiConstants.MESSAGE_LINK);
+ return Boolean.parseBoolean(property);
}
-
- String property = Graphiti.getPeService().getPropertyValue(pe, ChoreographyUtil.MESSAGE_LINK);
- if (property == null) {
- return false;
- }
-
- return new Boolean(property);
+ return false;
}
public static GraphicsAlgorithm[] getClickArea(PictogramElement element) {
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyTaskFeatureContainer.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyTaskFeatureContainer.java
index 8f8386b4..2d1daeba 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyTaskFeatureContainer.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/ChoreographyTaskFeatureContainer.java
@@ -69,19 +69,6 @@ public class ChoreographyTaskFeatureContainer extends AbstractChoreographyFeatur
@Override
public IDeleteFeature getDeleteFeature(IFeatureProvider fp) {
return new AbstractDefaultDeleteFeature(fp) {
-
- @Override
- protected void deletePeEnvironment(PictogramElement pictogramElement){
- if (pictogramElement instanceof ContainerShape) {
- ContainerShape cShape = (ContainerShape) pictogramElement;
- EList<Anchor> anchors = cShape.getAnchors();
- for (Anchor anchor : anchors) {
- deleteConnections(getFeatureProvider(), anchor.getIncomingConnections());
- deleteConnections(getFeatureProvider(), anchor.getOutgoingConnections());
- }
- deleteContainer(getFeatureProvider(), cShape);
- }
- }
@Override
protected void deleteConnections(IFeatureProvider fp, List<Connection> connections) {
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/Messages.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/Messages.java
index 7d96af3d..3f0045d6 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/Messages.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/Messages.java
@@ -16,6 +16,7 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.bpmn2.modeler.ui.features.choreography.messages"; //$NON-NLS-1$
public static String AddChoreographyMessageFeature_Description;
public static String AddChoreographyMessageFeature_Name;
+ public static String AddChoreographyMessageFeature_New;
public static String AddChoreographyParticipantFeature_Description;
public static String AddChoreographyParticipantFeature_Name;
public static String AddChoreographyParticipantFeature_New_Participant;
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/RemoveChoreographyMessageFeature.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/RemoveChoreographyMessageFeature.java
index 47daffda..73905a17 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/RemoveChoreographyMessageFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/RemoveChoreographyMessageFeature.java
@@ -24,6 +24,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
@@ -43,15 +44,15 @@ public class RemoveChoreographyMessageFeature extends AbstractCustomFeature {
public RemoveChoreographyMessageFeature(IFeatureProvider fp) {
super(fp);
}
-
+
@Override
public String getName() {
- return Messages.RemoveChoreographyMessageFeature_Name;
+ return Messages.RemoveChoreographyMessageFeature_Name;
}
-
+
@Override
public String getDescription() {
- return Messages.RemoveChoreographyMessageFeature_Description;
+ return Messages.RemoveChoreographyMessageFeature_Description;
}
@Override
@@ -71,64 +72,62 @@ public class RemoveChoreographyMessageFeature extends AbstractCustomFeature {
PictogramElement pe = pes[0];
Object bo = getBusinessObjectForPictogramElement(pe);
if (pe instanceof ContainerShape && bo instanceof Participant) {
- Participant participant = (Participant)bo;
-
- Object parent = getBusinessObjectForPictogramElement(((ContainerShape)pe).getContainer());
+ Participant participant = (Participant) bo;
+
+ Object parent = getBusinessObjectForPictogramElement(((ContainerShape) pe).getContainer());
if (parent instanceof ChoreographyTask) {
-
- // Check if choreography task is not associated with MessageFlow
- // with this participant as the source
- ChoreographyTask ct=(ChoreographyTask)parent;
- boolean canRemove=false;
-
+
+ // Check if choreography task is not associated with
+ // MessageFlow with this participant as the source
+ ChoreographyTask ct = (ChoreographyTask) parent;
+ boolean canRemove = false;
+
for (MessageFlow mf : ct.getMessageFlowRef()) {
if (participant.equals(mf.getSourceRef())) {
canRemove = true;
break;
}
}
-
+
return (canRemove);
}
}
}
return false;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext)
*/
@Override
public void execute(ICustomContext context) {
- PictogramElement[] pes = context.getPictogramElements();
- if (pes != null && pes.length == 1) {
- PictogramElement pe = pes[0];
- Object bo = getBusinessObjectForPictogramElement(pe);
- if (pe instanceof ContainerShape && bo instanceof Participant) {
- ContainerShape containerShape = (ContainerShape)pe;
- Participant participant = (Participant)bo;
-
- Object parent = getBusinessObjectForPictogramElement(containerShape.getContainer());
- if (parent instanceof ChoreographyTask) {
- ChoreographyTask ct=(ChoreographyTask)parent;
- Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram();
-
- for (MessageFlow mf : ct.getMessageFlowRef()) {
- if (participant.equals(mf.getSourceRef())) {
- // remove the visuals first
- Connection connection = (Connection)Graphiti.getLinkService().getPictogramElements(diagram, mf).get(0);
- if (ChoreographyUtil.removeChoreographyMessageLink(connection)) {
- // now remove the MessageFlow from the ChoreographyTask
- ct.getMessageFlowRef().remove(mf);
- EcoreUtil.delete(mf);
-
- BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(containerShape, BPMNShape.class);
- bpmnShape.setIsMessageVisible(false);
- }
- break;
- }
- }
+ PictogramElement pe = context.getPictogramElements()[0];
+ ContainerShape participantShape = (ContainerShape) pe;
+ ContainerShape choreographyTaskShape = (ContainerShape) participantShape.getContainer();
+ Participant participant = (Participant) getBusinessObjectForPictogramElement(participantShape);
+ ChoreographyTask choreographyTask = (ChoreographyTask) getBusinessObjectForPictogramElement(choreographyTaskShape);
+ Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram();
+
+ for (MessageFlow mf : choreographyTask.getMessageFlowRef()) {
+ if (participant.equals(mf.getSourceRef())) {
+ // remove the visuals first
+ Connection connection = (Connection) Graphiti.getLinkService()
+ .getPictogramElements(diagram, mf).get(0);
+ if (ChoreographyUtil.removeChoreographyMessageLink(connection)) {
+ // now remove the MessageFlow from the ChoreographyTask
+ choreographyTask.getMessageFlowRef().remove(mf);
+ EcoreUtil.delete(mf);
+
+ BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(participantShape, BPMNShape.class);
+ bpmnShape.setIsMessageVisible(false);
+
+ UpdateContext updateContext = new UpdateContext(choreographyTaskShape);
+ getFeatureProvider().updateIfPossible(updateContext);
}
+ break;
}
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/UpdateChoreographyMessageLinkFeature.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/UpdateChoreographyMessageLinkFeature.java
index 46ce929d..6cb26594 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/UpdateChoreographyMessageLinkFeature.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/UpdateChoreographyMessageLinkFeature.java
@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.eclipse.bpmn2.BaseElement;
import org.eclipse.bpmn2.ChoreographyActivity;
@@ -27,10 +26,12 @@ import org.eclipse.bpmn2.Participant;
import org.eclipse.bpmn2.di.BPMNShape;
import org.eclipse.bpmn2.di.ParticipantBandKind;
import org.eclipse.bpmn2.modeler.core.features.AbstractUpdateBaseElementFeature;
+import org.eclipse.bpmn2.modeler.core.features.GraphitiConstants;
import org.eclipse.bpmn2.modeler.core.features.choreography.ChoreographyUtil;
import org.eclipse.bpmn2.modeler.core.features.choreography.Messages;
import org.eclipse.bpmn2.modeler.core.model.Bpmn2ModelerFactory;
-import org.eclipse.bpmn2.modeler.core.utils.AnchorLocation;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorSite;
+import org.eclipse.bpmn2.modeler.core.utils.AnchorType;
import org.eclipse.bpmn2.modeler.core.utils.AnchorUtil;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
@@ -40,8 +41,6 @@ import org.eclipse.bpmn2.modeler.core.utils.ShapeDecoratorUtil.Envelope;
import org.eclipse.bpmn2.modeler.core.utils.StyleUtil;
import org.eclipse.bpmn2.modeler.core.utils.Tuple;
import org.eclipse.dd.dc.Bounds;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.datatypes.IDimension;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IReason;
@@ -53,6 +52,7 @@ import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
@@ -133,48 +133,38 @@ public class UpdateChoreographyMessageLinkFeature extends AbstractUpdateBaseElem
Tuple<List<ContainerShape>, List<ContainerShape>> topAndBottom = FeatureSupport.getTopAndBottomBands(bandShapes);
List<ContainerShape> shapesWithVisibleMessages = new ArrayList<ContainerShape>();
- List<FixPointAnchor> topBoundaryAnchors = AnchorUtil.getBoundaryAnchors(choreographyTaskShape, AnchorLocation.TOP);
- List<FixPointAnchor> bottomBoundaryAnchors = AnchorUtil.getBoundaryAnchors(choreographyTaskShape, AnchorLocation.BOTTOM);
- FixPointAnchor topBoundaryAnchor = null;
- FixPointAnchor bottomBoundaryAnchor = null;
- int topConnectionIndex = 0;
- int bottomConnectionIndex = 0;
-
- boolean hasTopMessage = false;
- List<Connection> topConnections = new ArrayList<Connection>();
- for (FixPointAnchor anchor : topBoundaryAnchors)
- topConnections.addAll(anchor.getOutgoingConnections());
- for (int i = 0; i < topConnections.size(); i++) {
- Connection connection = topConnections.get(i);
- EObject container = connection.getEnd().eContainer();
- if (container instanceof PropertyContainer) {
- String property = peService.getPropertyValue((PropertyContainer) container, ChoreographyUtil.MESSAGE_LINK);
- if (Boolean.parseBoolean(property)) {
- topConnectionIndex = i;
- hasTopMessage = true;
- topBoundaryAnchor = (FixPointAnchor) connection.getEnd();
- break;
- }
+ FixPointAnchor topAnchor = null;
+ FixPointAnchor bottomAnchor = null;
+ Connection topConnection = null;
+ Connection bottomConnection = null;
+
+ for (Connection connection : AnchorUtil.getConnections(choreographyTaskShape, AnchorSite.TOP)) {
+ AnchorContainer container = connection.getEnd().getParent();
+ String property = peService.getPropertyValue((PropertyContainer) container, GraphitiConstants.MESSAGE_LINK);
+ if (Boolean.parseBoolean(property)) {
+ topConnection = connection;
+ topAnchor = (FixPointAnchor) connection.getEnd();
+ break;
}
}
-
- boolean hasBottomMessage = false;
- List<Connection> bottomConnections = new ArrayList<Connection>();
- for (FixPointAnchor anchor : bottomBoundaryAnchors)
- topConnections.addAll(anchor.getOutgoingConnections());
- for (int i = 0; i < bottomConnections.size(); i++) {
- Connection connection = bottomConnections.get(i);
- EObject container = connection.getEnd().eContainer();
- if (container instanceof PropertyContainer) {
- String property = peService.getPropertyValue((PropertyContainer) container, ChoreographyUtil.MESSAGE_LINK);
- if (Boolean.parseBoolean(property)) {
- bottomConnectionIndex = i;
- hasBottomMessage = true;
- bottomBoundaryAnchor = (FixPointAnchor) connection.getEnd();
- break;
- }
+ if (topAnchor==null)
+ topAnchor = AnchorUtil.createAnchor(choreographyTaskShape, AnchorSite.TOP);
+ // this prevents any of the routers from moving this anchor
+ AnchorType.setType(topAnchor, AnchorType.MESSAGELINK);
+
+ for (Connection connection : AnchorUtil.getConnections(choreographyTaskShape, AnchorSite.BOTTOM)) {
+ AnchorContainer container = connection.getEnd().getParent();
+ String property = peService.getPropertyValue((PropertyContainer) container, GraphitiConstants.MESSAGE_LINK);
+ if (Boolean.parseBoolean(property)) {
+ bottomConnection = connection;
+ bottomAnchor = (FixPointAnchor) connection.getEnd();
+ break;
}
}
+ if (bottomAnchor==null)
+ bottomAnchor = AnchorUtil.createAnchor(choreographyTaskShape, AnchorSite.BOTTOM);
+ // this prevents any of the routers from moving this anchor
+ AnchorType.setType(bottomAnchor, AnchorType.MESSAGELINK);
for (ContainerShape bandShape : bandShapes) {
BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(bandShape, BPMNShape.class);
@@ -214,19 +204,19 @@ public class UpdateChoreographyMessageLinkFeature extends AbstractUpdateBaseElem
MessageFlow flow = getMessageFlow(messageFlows, topAndBottom.getFirst());
envelope = null;
- if (!hasTopMessage && shouldDrawTopMessage && flow!=null) {
+ if (topConnection==null && shouldDrawTopMessage && flow!=null) {
int y = (int) (bounds.getY() - ChoreographyUtil.ENVELOPE_HEIGHT_MODIFIER - ChoreographyUtil.ENV_H);
- envelope = drawMessageLink(topMessageName, topBoundaryAnchor, x, y, isFilled(topAndBottom.getFirst()));
- if (topMessage!=null)
- fp.link(envelope, topMessage);
+ envelope = drawMessageLink(topMessage, topMessageName, topAnchor, x, y, isFilled(topAndBottom.getFirst()));
peService.setPropertyValue(envelope, ChoreographyUtil.MESSAGE_NAME, topMessageName);
- } else if (hasTopMessage && !shouldDrawTopMessage) {
- envelope = (ContainerShape) topConnections.get(topConnectionIndex).getEnd().eContainer();
- peService.deletePictogramElement(topConnections.get(topConnectionIndex));
+ }
+ else if (topConnection!=null && !shouldDrawTopMessage) {
+ envelope = (ContainerShape) topConnection.getEnd().getParent();
+ peService.deletePictogramElement(topConnection);
peService.deletePictogramElement(envelope);
envelope = null;
- } else if (hasTopMessage && shouldDrawTopMessage && flow!=null) {
- envelope = (ContainerShape) topConnections.get(topConnectionIndex).getEnd().eContainer();
+ }
+ else if (topConnection!=null && shouldDrawTopMessage && flow!=null) {
+ envelope = (ContainerShape) topConnection.getEnd().getParent();
setMessageLabel(topMessageName, envelope);
}
if (envelope!=null) {
@@ -236,23 +226,22 @@ public class UpdateChoreographyMessageLinkFeature extends AbstractUpdateBaseElem
envelope = null;
flow = getMessageFlow(messageFlows, topAndBottom.getSecond());
- if (!hasBottomMessage && shouldDrawBottomMessage && flow!=null) {
+ if (bottomConnection==null && shouldDrawBottomMessage && flow!=null) {
int y = (int) (bounds.getY() + bounds.getHeight() + ChoreographyUtil.ENVELOPE_HEIGHT_MODIFIER);
- envelope = drawMessageLink(bottomMessageName, bottomBoundaryAnchor, x, y, isFilled(topAndBottom.getSecond()));
- if (bottomMessage!=null)
- fp.link(envelope, bottomMessage);
+ envelope = drawMessageLink(bottomMessage, bottomMessageName, bottomAnchor, x, y, isFilled(topAndBottom.getSecond()));
peService.setPropertyValue(envelope, ChoreographyUtil.MESSAGE_NAME, bottomMessageName);
- } else if (hasBottomMessage && !shouldDrawBottomMessage) {
- envelope = (ContainerShape) bottomConnections.get(bottomConnectionIndex).getEnd()
- .eContainer();
- peService.deletePictogramElement(bottomConnections.get(bottomConnectionIndex));
+ }
+ else if (bottomConnection!=null && !shouldDrawBottomMessage) {
+ envelope = (ContainerShape) bottomConnection.getEnd().getParent();
+ peService.deletePictogramElement(bottomConnection);
peService.deletePictogramElement(envelope);
envelope = null;
- } else if (hasBottomMessage && shouldDrawBottomMessage && flow!=null) {
- envelope = (ContainerShape) bottomConnections.get(bottomConnectionIndex).getEnd()
- .eContainer();
+ }
+ else if (bottomConnection!=null && shouldDrawBottomMessage && flow!=null) {
+ envelope = (ContainerShape) bottomConnection.getEnd().getParent();
setMessageLabel(bottomMessageName, envelope);
}
+
if (envelope!=null) {
// link up the message flow
linkMessageFlow(fp, flow, envelope);
@@ -264,6 +253,7 @@ public class UpdateChoreographyMessageLinkFeature extends AbstractUpdateBaseElem
Boolean.toString(bpmnShape.isIsMessageVisible()));
}
+ AnchorUtil.adjustAnchors(choreographyTaskShape);
return true;
}
@@ -357,19 +347,22 @@ public class UpdateChoreographyMessageLinkFeature extends AbstractUpdateBaseElem
return null;
}
- private ContainerShape drawMessageLink(String name, FixPointAnchor boundaryAnchor, int x, int y, boolean filled) {
- Diagram diagram = peService.getDiagramForAnchor(boundaryAnchor);
+ private ContainerShape drawMessageLink(Message message, String name, FixPointAnchor choreographyTaskAnchor, int x, int y, boolean filled) {
+ Diagram diagram = peService.getDiagramForAnchor(choreographyTaskAnchor);
FreeFormConnection connection = peService.createFreeFormConnection(diagram);
Polyline connectionLine = gaService.createPolyline(connection);
connectionLine.setForeground(gaService.manageColor(diagram, StyleUtil.CLASS_FOREGROUND));
connectionLine.setLineStyle(LineStyle.DOT);
connectionLine.setLineWidth(2);
+ peService.setPropertyValue(connection, GraphitiConstants.MESSAGE_LINK, Boolean.toString(true));
ContainerShape envelope = peService.createContainerShape(diagram, true);
Rectangle invisibleRectangle = gaService.createInvisibleRectangle(envelope);
gaService.setLocation(invisibleRectangle, x, y);
- gaService.setSize(invisibleRectangle, ChoreographyUtil.ENV_W + 50, ChoreographyUtil.ENV_H);
+ gaService.setSize(invisibleRectangle, ChoreographyUtil.ENV_W, ChoreographyUtil.ENV_H);
+ getFeatureProvider().link(envelope, message);
+ peService.setPropertyValue(envelope, GraphitiConstants.MESSAGE_LINK, Boolean.toString(true));
Shape envelopeShape = peService.createShape(envelope, false);
Envelope envelopeGa = ShapeDecoratorUtil.createEnvelope(envelopeShape, 0, 0, ChoreographyUtil.ENV_W, ChoreographyUtil.ENV_H);
@@ -387,16 +380,18 @@ public class UpdateChoreographyMessageLinkFeature extends AbstractUpdateBaseElem
gaService.setSize(invisibleRectangle, ChoreographyUtil.ENV_W + size.getWidth() + 3, ChoreographyUtil.ENV_H);
- AnchorLocation envelopeAnchorLoc = null;
-// if (boundaryAnchor.locationType == AnchorLocation.TOP) {
-// envelopeAnchorLoc = AnchorLocation.BOTTOM;
-// } else {
-// envelopeAnchorLoc = AnchorLocation.TOP;
-// }
+ FixPointAnchor envelopeAnchor;
+ if (AnchorSite.getSite(choreographyTaskAnchor) == AnchorSite.TOP) {
+ envelopeAnchor = AnchorUtil.createAnchor(envelope, AnchorSite.BOTTOM);
+ AnchorUtil.moveAnchor(envelopeAnchor, x + ChoreographyUtil.ENV_W/2, y + ChoreographyUtil.ENV_H);
+ } else {
+ envelopeAnchor = AnchorUtil.createAnchor(envelope, AnchorSite.TOP);
+ AnchorUtil.moveAnchor(envelopeAnchor, x + ChoreographyUtil.ENV_W/2, y);
+ }
+
+ connection.setStart(choreographyTaskAnchor);
+ connection.setEnd(envelopeAnchor);
- connection.setStart(boundaryAnchor);
-// connection.setEnd(AnchorUtil.getBoundaryAnchors(envelope).get(envelopeAnchorLoc).anchor);
- peService.setPropertyValue(envelope, ChoreographyUtil.MESSAGE_LINK, Boolean.toString(true));
return envelope;
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/messages.properties b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/messages.properties
index d2cd7275..928abfc2 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/messages.properties
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/choreography/messages.properties
@@ -10,6 +10,7 @@
#-------------------------------------------------------------------------------
AddChoreographyMessageFeature_Description=Add a Message definition to this Choreography Participant
AddChoreographyMessageFeature_Name=Add Message
+AddChoreographyMessageFeature_New=Create a new Message
AddChoreographyParticipantFeature_Description=Add a new Participant to this Choreography Task
AddChoreographyParticipantFeature_Name=Add Participant
AddChoreographyParticipantFeature_New_Participant=New Participant
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/MessageFeatureContainer.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/MessageFeatureContainer.java
index e512fb7d..706d7e75 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/MessageFeatureContainer.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/MessageFeatureContainer.java
@@ -302,8 +302,7 @@ public class MessageFeatureContainer extends BaseElementFeatureContainer {
public Message createBusinessObject(ICreateContext context) {
changesDone = true;
- Message message = null;
- message = Bpmn2ModelerFactory.create(Message.class);
+ Message message = Bpmn2ModelerFactory.create(Message.class);
String oldName = message.getName();
message.setName(Messages.MessageFeatureContainer_New);
message.setId(null);
@@ -336,7 +335,8 @@ public class MessageFeatureContainer extends BaseElementFeatureContainer {
message.setId(null);
ModelUtil.setID(message);
message.setName(oldName);
- } else {
+ }
+ else {
// and existing one
message = result;
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/AssociationFeatureContainer.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/AssociationFeatureContainer.java
index bc5ee527..0fc56e7c 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/AssociationFeatureContainer.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/AssociationFeatureContainer.java
@@ -52,8 +52,10 @@ import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
@@ -69,8 +71,6 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
public static final String ASSOCIATION_DIRECTION = "association.direction"; //$NON-NLS-1$
public static final String ARROWHEAD_DECORATOR = "arrowhead.decorator"; //$NON-NLS-1$
- protected CreateConnectionContext createContext;
-
@Override
public boolean canApplyTo(Object o) {
return super.canApplyTo(o) && o instanceof Association;
@@ -98,21 +98,7 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
@Override
public IDeleteFeature getDeleteFeature(IFeatureProvider fp) {
- return new DefaultDeleteBPMNShapeFeature(fp) {
-
- @Override
- public void delete(IDeleteContext context) {
- PictogramElement pe = context.getPictogramElement();
- if (pe instanceof Connection) {
- Connection c = (Connection) pe;
- if (c.getStart()!=null)
- AnchorUtil.deleteConnectionPoint(c.getStart().getParent());
- if (c.getEnd()!=null)
- AnchorUtil.deleteConnectionPoint(c.getEnd().getParent());
- }
- super.delete(context);
- }
- };
+ return new DefaultDeleteBPMNShapeFeature(fp);
}
public class AddAssociationFeature extends AbstractAddFlowFeature<Association> {
@@ -121,59 +107,6 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
}
@Override
- public PictogramElement add(IAddContext context) {
- AddConnectionContext addConContext = (AddConnectionContext)context;
- Anchor sourceAnchor = addConContext.getSourceAnchor();
- Anchor targetAnchor = addConContext.getTargetAnchor();
- PictogramElement source = sourceAnchor==null ? null : sourceAnchor.getParent();
- PictogramElement target = targetAnchor==null ? null : targetAnchor.getParent();
- boolean anchorChanged = false;
-
- if (createContext!=null) {
- if (source==null) {
- source = createContext.getSourcePictogramElement();
- sourceAnchor = createContext.getSourceAnchor();
- }
- if (target==null) {
- target = createContext.getTargetPictogramElement();
- targetAnchor = createContext.getTargetAnchor();
- }
- }
-
- if (sourceAnchor==null && source instanceof FreeFormConnection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(getFeatureProvider(),
- (FreeFormConnection)source,
- Graphiti.getPeLayoutService().getConnectionMidpoint((FreeFormConnection)source, 0.5));
- sourceAnchor = AnchorUtil.getConnectionPointAnchor(connectionPointShape);
- anchorChanged = true;
- }
- if (targetAnchor==null && target instanceof FreeFormConnection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(getFeatureProvider(),
- (FreeFormConnection)target,
- Graphiti.getPeLayoutService().getConnectionMidpoint((FreeFormConnection)target, 0.5));
- targetAnchor = AnchorUtil.getConnectionPointAnchor(connectionPointShape);
- anchorChanged = true;
- }
-
- // this is silly! why are there no setters for sourceAnchor and targetAnchor in AddConnectionContext???
- if (anchorChanged) {
- AddConnectionContext newContext = new AddConnectionContext(sourceAnchor, targetAnchor);
- newContext.setSize(addConContext.getHeight(), addConContext.getWidth());
- newContext.setLocation(addConContext.getX(), addConContext.getY());
- newContext.setNewObject(getBusinessObject(addConContext));
- newContext.setTargetConnection(addConContext.getTargetConnection());
- newContext.setTargetConnectionDecorator(addConContext.getTargetConnectionDecorator());
- newContext.setTargetContainer(addConContext.getTargetContainer());
-
- context = newContext;
- }
- // we're done with this
- createContext = null;
-
- return super.add(context);
- }
-
- @Override
protected Polyline createConnectionLine(Connection connection) {
Polyline connectionLine = super.createConnectionLine(connection);
connectionLine.setLineWidth(2);
@@ -214,11 +147,6 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
if (!super.canCreate(context))
return false;
- if ( context.getTargetPictogramElement() instanceof FreeFormConnection ) {
- // TODO: fix this so it works with Manhattan router
- return true;
- }
-
BaseElement source = getSourceBo(context);
BaseElement target = getTargetBo(context);
if (source!=null && target!=null) {
@@ -233,28 +161,6 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
@Override
public Connection create(ICreateConnectionContext context) {
- // save the CreateContext because we'll need it in AddFeature
- createContext = (CreateConnectionContext)context;
- Anchor sourceAnchor = createContext.getSourceAnchor();
- Anchor targetAnchor = createContext.getTargetAnchor();
- PictogramElement source = createContext.getSourcePictogramElement();
- PictogramElement target = createContext.getTargetPictogramElement();
-
- if (sourceAnchor==null && source instanceof FreeFormConnection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(getFeatureProvider(),
- (FreeFormConnection)source,
- Graphiti.getPeLayoutService().getConnectionMidpoint((FreeFormConnection)source, 0.5));
- sourceAnchor = AnchorUtil.getConnectionPointAnchor(connectionPointShape);
- createContext.setSourceAnchor(sourceAnchor);
- }
- if (targetAnchor==null && target instanceof FreeFormConnection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(getFeatureProvider(),
- (FreeFormConnection)target,
- Graphiti.getPeLayoutService().getConnectionMidpoint((FreeFormConnection)target, 0.5));
- targetAnchor = AnchorUtil.getConnectionPointAnchor(connectionPointShape);
- createContext.setTargetAnchor(targetAnchor);
- }
-
Connection connection = super.create(context);
Association association = getBusinessObject(context);
if (association.getSourceRef() instanceof BoundaryEvent && association.getTargetRef() instanceof Activity) {
@@ -283,10 +189,6 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
Anchor anchor = getSourceAnchor(context);
if (anchor != null && anchor.getParent() instanceof Shape) {
Shape shape = (Shape) anchor.getParent();
- Connection connection = AnchorUtil.getConnectionPointOwner(shape);
- if (connection!=null) {
- return BusinessObjectUtil.getFirstElementOfType(connection, getTargetClass());
- }
return BusinessObjectUtil.getFirstElementOfType(shape, getTargetClass());
}
else if (context.getSourcePictogramElement() instanceof Connection) {
@@ -301,10 +203,6 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
Anchor anchor = getTargetAnchor(context);
if (anchor != null && anchor.getParent() instanceof Shape) {
Shape shape = (Shape) anchor.getParent();
- Connection connection = AnchorUtil.getConnectionPointOwner(shape);
- if (connection!=null) {
- return BusinessObjectUtil.getFirstElementOfType(connection, getTargetClass());
- }
return BusinessObjectUtil.getFirstElementOfType(shape, getTargetClass());
}
else if (context.getTargetPictogramElement() instanceof Connection) {
@@ -446,6 +344,10 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
return false;
PictogramElement targetPictogramElement = context.getTargetPictogramElement();
if (targetPictogramElement instanceof FreeFormConnection) {
+ // can't reconnect to the same Connection
+ AnchorContainer ac = context.getConnection().getEnd().getParent();
+ if (BusinessObjectUtil.getBusinessObjectForPictogramElement(ac) == targetElement)
+ return false;
return true;
}
return super.canReconnect(context);
@@ -462,26 +364,8 @@ public class AssociationFeatureContainer extends BaseElementConnectionFeatureCon
}
@Override
- public void preReconnect(IReconnectionContext context) {
- PictogramElement targetPictogramElement = context.getTargetPictogramElement();
- if (targetPictogramElement instanceof Connection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(
- getFeatureProvider(),
- (Connection)targetPictogramElement,
- context.getTargetLocation());
-
- ReconnectionContext rc = (ReconnectionContext) context;
- rc.setNewAnchor(AnchorUtil.getConnectionPointAnchor(connectionPointShape));
- rc.setTargetPictogramElement(connectionPointShape);
- }
- super.preReconnect(context);
- }
-
- @Override
public void postReconnect(IReconnectionContext context) {
- if (AnchorUtil.isConnectionPoint(context.getOldAnchor().getParent())) {
- AnchorUtil.deleteConnectionPoint(context.getOldAnchor().getParent());
- }
+ AnchorUtil.adjustAnchors(context.getOldAnchor().getParent());
super.postReconnect(context);
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/DataAssociationFeatureContainer.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/DataAssociationFeatureContainer.java
index 0feaad9e..60b7271a 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/DataAssociationFeatureContainer.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/DataAssociationFeatureContainer.java
@@ -79,6 +79,7 @@ import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
@@ -511,10 +512,6 @@ public class DataAssociationFeatureContainer extends BaseElementConnectionFeatur
Anchor anchor = getSourceAnchor(context);
if (anchor != null && anchor.getParent() instanceof Shape) {
Shape shape = (Shape) anchor.getParent();
- Connection conn = AnchorUtil.getConnectionPointOwner(shape);
- if (conn!=null) {
- return BusinessObjectUtil.getFirstElementOfType(conn, getTargetClass());
- }
return BusinessObjectUtil.getFirstElementOfType(shape, getTargetClass());
}
return null;
@@ -525,10 +522,6 @@ public class DataAssociationFeatureContainer extends BaseElementConnectionFeatur
Anchor anchor = getTargetAnchor(context);
if (anchor != null && anchor.getParent() instanceof Shape) {
Shape shape = (Shape) anchor.getParent();
- Connection conn = AnchorUtil.getConnectionPointOwner(shape);
- if (conn!=null) {
- return BusinessObjectUtil.getFirstElementOfType(conn, getTargetClass());
- }
return BusinessObjectUtil.getFirstElementOfType(shape, getTargetClass());
}
return null;
@@ -845,20 +838,6 @@ public class DataAssociationFeatureContainer extends BaseElementConnectionFeatur
@Override
public void preReconnect(IReconnectionContext context) {
startTransaction();
-
- PictogramElement targetPictogramElement = context.getTargetPictogramElement();
- if (targetPictogramElement instanceof FreeFormConnection) {
- Shape connectionPointShape = AnchorUtil.createConnectionPoint(
- getFeatureProvider(),
- (FreeFormConnection)targetPictogramElement,
- context.getTargetLocation());
-
- if (context instanceof ReconnectionContext) {
- ReconnectionContext rc = (ReconnectionContext) context;
- rc.setNewAnchor(AnchorUtil.getConnectionPointAnchor(connectionPointShape));
- rc.setTargetPictogramElement(connectionPointShape);
- }
- }
super.preReconnect(context);
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/MessageFlowFeatureContainer.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/MessageFlowFeatureContainer.java
index ee811f43..436f5777 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/MessageFlowFeatureContainer.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/flow/MessageFlowFeatureContainer.java
@@ -30,8 +30,10 @@ import org.eclipse.bpmn2.ServiceTask;
import org.eclipse.bpmn2.StartEvent;
import org.eclipse.bpmn2.modeler.core.adapters.ExtendedPropertiesAdapter;
import org.eclipse.bpmn2.modeler.core.di.DIImport;
+import org.eclipse.bpmn2.modeler.core.features.AbstractBpmn2UpdateFeature;
import org.eclipse.bpmn2.modeler.core.features.BaseElementConnectionFeatureContainer;
import org.eclipse.bpmn2.modeler.core.features.DefaultDeleteBPMNShapeFeature;
+import org.eclipse.bpmn2.modeler.core.features.DefaultLayoutBPMNConnectionFeature;
import org.eclipse.bpmn2.modeler.core.features.MultiUpdateFeature;
import org.eclipse.bpmn2.modeler.core.features.choreography.ChoreographyUtil;
import org.eclipse.bpmn2.modeler.core.features.flow.AbstractAddFlowFeature;
@@ -53,6 +55,7 @@ import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.ILayoutFeature;
import org.eclipse.graphiti.features.IMoveShapeFeature;
import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.IReconnectionFeature;
@@ -62,6 +65,7 @@ import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.features.context.IPictogramElementContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
@@ -131,6 +135,22 @@ public class MessageFlowFeatureContainer extends BaseElementConnectionFeatureCon
}
@Override
+ public ILayoutFeature getLayoutFeature(IFeatureProvider fp) {
+ return new DefaultLayoutBPMNConnectionFeature(fp) {
+ @Override
+ public boolean layout(ILayoutContext context) {
+ if (super.layout(context)) {
+// PictogramElement pe = context.getPictogramElement();
+// if (pe instanceof Connection)
+// adjustMessageDecorator(getFeatureProvider(), (Connection)pe);
+ return true;
+ }
+ return false;
+ }
+ };
+ }
+
+ @Override
public IReconnectionFeature getReconnectionFeature(IFeatureProvider fp) {
return new ReconnectMessageFlowFeature(fp);
}
@@ -611,19 +631,22 @@ public class MessageFlowFeatureContainer extends BaseElementConnectionFeatureCon
}
- public static class UpdateMessageFlowFeature extends UpdateLabelFeature {
+ public static class UpdateMessageFlowFeature extends AbstractBpmn2UpdateFeature {
- boolean isUpdating = false;
-
public UpdateMessageFlowFeature(IFeatureProvider fp) {
super(fp);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.func.IUpdate#canUpdate(org.eclipse.graphiti.features.context.IUpdateContext)
+ */
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ return true;
+ }
+
@Override
public IReason updateNeeded(IUpdateContext context) {
- if (isUpdating)
- return Reason.createFalseReason();
-
if (context.getPictogramElement() instanceof Connection) {
Connection connection = (Connection) context.getPictogramElement();
MessageFlow messageFlow = (MessageFlow) BusinessObjectUtil.getFirstBaseElement(connection);
@@ -647,35 +670,29 @@ public class MessageFlowFeatureContainer extends BaseElementConnectionFeatureCon
@Override
public boolean update(IUpdateContext context) {
- try {
- isUpdating = true;
- Connection connection = (Connection) context.getPictogramElement();
- MessageFlow messageFlow = (MessageFlow) BusinessObjectUtil.getFirstBaseElement(connection);
- Message message = messageFlow.getMessageRef();
- String oldMessageRef = peService.getPropertyValue(connection, MESSAGE_REF);
- if (oldMessageRef==null)
- oldMessageRef = ""; //$NON-NLS-1$
-
- String newMessageRef = messageToString(messageFlow.getMessageRef());
-
- if (!oldMessageRef.equals(newMessageRef)) {
- removeMessageDecorator(getFeatureProvider(), connection);
- if (message!=null) {
- Shape messageShape = (Shape) context.getProperty(MESSAGE_REF);
- addMessageDecorator(getFeatureProvider(), connection, message, messageShape);
- }
- peService.setPropertyValue(connection, MESSAGE_REF, newMessageRef);
- }
- else {
- // move the message decorator
- adjustMessageDecorator(getFeatureProvider(), connection);
+ Connection connection = (Connection) context.getPictogramElement();
+ MessageFlow messageFlow = (MessageFlow) BusinessObjectUtil.getFirstBaseElement(connection);
+ Message message = messageFlow.getMessageRef();
+ String oldMessageRef = peService.getPropertyValue(connection, MESSAGE_REF);
+ if (oldMessageRef==null)
+ oldMessageRef = ""; //$NON-NLS-1$
+
+ String newMessageRef = messageToString(messageFlow.getMessageRef());
+
+ if (!oldMessageRef.equals(newMessageRef)) {
+ removeMessageDecorator(getFeatureProvider(), connection);
+ if (message!=null) {
+ Shape messageShape = (Shape) context.getProperty(MESSAGE_REF);
+ addMessageDecorator(getFeatureProvider(), connection, message, messageShape);
}
-
- return super.update(context);
+ peService.setPropertyValue(connection, MESSAGE_REF, newMessageRef);
}
- finally {
- isUpdating = false;
+ else {
+ // move the message decorator
+ adjustMessageDecorator(getFeatureProvider(), connection);
}
+
+ return true;
}
}

Back to the top