Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-03-28 12:51:19 +0000
committerHenrik Rentz-Reichert2013-03-28 12:51:19 +0000
commitcf476d9d80ce7c49296096912f9e88fe723bc7af (patch)
tree8199a780577415f4f8eb5fc417edc29e297bf165 /plugins/org.eclipse.etrice.ui.behavior
parent60b19b8b5efbe936d66e63f95a1d1bbf71361a2c (diff)
parent85c43d2aaaabebd25cd6d9b0b74f56864df30ab7 (diff)
downloadorg.eclipse.etrice-cf476d9d80ce7c49296096912f9e88fe723bc7af.tar.gz
org.eclipse.etrice-cf476d9d80ce7c49296096912f9e88fe723bc7af.tar.xz
org.eclipse.etrice-cf476d9d80ce7c49296096912f9e88fe723bc7af.zip
Merge branch 'change/11538/1'
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.behavior')
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java8
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java71
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java13
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java3
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java169
5 files changed, 222 insertions, 42 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java
index d9daa357c..399369b9d 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java
@@ -6,6 +6,7 @@ import java.util.HashMap;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ChoicePoint;
+import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.SimpleState;
@@ -261,4 +262,11 @@ public class StateGraphContext {
public StateGraphContext getContext(StateGraphItem item) {
return obj2ctx.get(item);
}
+
+ public StateGraph getInitialPoint(){
+ for(Transition t : transitions)
+ if(t instanceof InitialTransition)
+ return (StateGraph) t.eContainer();
+ return null;
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java
index 2ba2f8e46..6eaa3810d 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java
@@ -54,6 +54,7 @@ public class DefaultPositionProvider implements IPositionProvider {
private HashMap<String, Position> obj2pos = new HashMap<String, Position>();
private HashMap<String, ArrayList<Position>> trans2points = new HashMap<String, ArrayList<Position>>();
+ private HashMap<String, StateGraph> initialPointObj = new HashMap<String, StateGraph>();
private double scaleX;
private double scaleY;
@@ -85,6 +86,27 @@ public class DefaultPositionProvider implements IPositionProvider {
return pt;
}
+ @Override
+ public PosAndSize getPosition(StateGraph graph) {
+ EObject container = graph.eContainer();
+ String path = "#init";
+ if(container instanceof StateGraphNode)
+ path = RoomNameProvider.getFullPath((StateGraphNode)container) + path;
+ Position pos = obj2pos.get(path);
+
+ if (pos==null)
+ return null;
+
+ int margin = getMargin(graph);
+ PosAndSize pt = new PosAndSize(
+ (int) (pos.x * scaleX) + margin,
+ (int) (pos.y * scaleY) + margin,
+ (int) (pos.sx * scaleX),
+ (int) (pos.sy * scaleY)
+ );
+ return pt;
+ }
+
public List<Pos> getPoints(Transition trans) {
ArrayList<Pos> result = new ArrayList<Pos>();
@@ -187,19 +209,34 @@ public class DefaultPositionProvider implements IPositionProvider {
for (Shape sgItemShape : ((ContainerShape)sgShape).getChildren()) {
// this is the level of States, TrPoints and ChoicePoints
obj = linkService.getBusinessObjectForLinkedPictogramElement(sgItemShape);
+ GraphicsAlgorithm ga = sgItemShape.getGraphicsAlgorithm();
+ if(ga==null)
+ continue;
+ int margin = 0;
+ String path = null;
if (obj instanceof StateGraphNode) {
- GraphicsAlgorithm ga = sgItemShape.getGraphicsAlgorithm();
- if (ga!=null) {
- int margin = getMargin((StateGraphNode) obj);
- Position pos = new Position();
- pos.x = ga.getX() / width;
- pos.y = ga.getY() / height;
- pos.sx = (ga.getWidth() - 2*margin) / width;
- pos.sy = (ga.getHeight()- 2*margin) / height;
- obj2pos.put(RoomNameProvider.getFullPath((StateGraphItem) obj), pos);
- }
- // Entry and Exit Points on State borders are treated by the insertion of the State
+ StateGraphNode node = (StateGraphNode)obj;
+ margin = getMargin(node);
+ path = RoomNameProvider.getFullPath((StateGraphItem) obj);
+ } else if(obj instanceof StateGraph){
+ StateGraph graph = (StateGraph)obj;
+ margin = getMargin(graph);
+ EObject container = graph.eContainer();
+ path = "#init";
+ if(container instanceof StateGraphNode)
+ path = RoomNameProvider.getFullPath((StateGraphNode)container) + path;
+ initialPointObj.put(path, graph);
+ }
+ if(path != null){
+ Position pos = new Position();
+ pos.x = ga.getX() / width;
+ pos.y = ga.getY() / height;
+ pos.sx = (ga.getWidth() - 2*margin) / width;
+ pos.sy = (ga.getHeight()- 2*margin) / height;
+ obj2pos.put(path, pos);
}
+
+ // Entry and Exit Points on State borders are treated by the insertion of the State
}
}
}
@@ -248,4 +285,16 @@ public class DefaultPositionProvider implements IPositionProvider {
return 0;
}
+
+ private int getMargin(StateGraph graph) {
+ return 0;
+ }
+
+ public StateGraph getInitialPoint(StateGraph graph){
+ EObject container = graph.eContainer();
+ String path = "#init";
+ if(container instanceof StateGraphNode)
+ path = RoomNameProvider.getFullPath((StateGraphNode)container) + path;
+ return initialPointObj.get(path);
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java
index 62362f2b8..10f3de13b 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java
@@ -14,6 +14,7 @@ package org.eclipse.etrice.ui.behavior.support;
import java.util.List;
+import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateGraphNode;
import org.eclipse.etrice.core.room.Transition;
@@ -86,4 +87,16 @@ public interface IPositionProvider {
public PosAndSize getPosition(StateGraphNode node);
public <T extends StateGraphNode> List<PosAndSize> getPositions(List<T> items);
public List<Pos> getPoints(Transition trans);
+ /**
+ *
+ * @param graph
+ * @return position of inital point
+ */
+ public PosAndSize getPosition(StateGraph graph);
+
+ /**
+ * @param graph
+ * @return BO of initial point's shape. A super graph or given graph itself.
+ */
+ public StateGraph getInitialPoint(StateGraph graph);
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java
index 99b4926be..74fc8ddc3 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java
@@ -17,6 +17,7 @@ import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.Transition;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.behavior.ImageProvider;
import org.eclipse.etrice.ui.common.support.CommonSupportUtil;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
@@ -119,7 +120,7 @@ public class InitialPointSupport {
ContainerShape parent = context.getTargetContainer().getContainer();
if (! (parent instanceof StateGraph)) {
StateGraph sg = (StateGraph) obj;
- for (Transition t : sg.getTransitions()) {
+ for (Transition t : RoomHelpers.getAllTransitions(sg)) {
if (t instanceof InitialTransition)
return false;
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java
index 3c3d6c41f..6419820a6 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java
@@ -13,6 +13,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
@@ -416,6 +417,16 @@ public class SupportUtil {
return transitions;
}
+ private static Map<Transition, Connection> getTransitionsMap(Diagram diagram, IFeatureProvider fp) {
+ Map<Transition, Connection> transitions = new HashMap<Transition, Connection>();
+ for (Connection conn : diagram.getConnections()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(conn);
+ if (bo instanceof Transition)
+ transitions.put((Transition) bo, conn);
+ }
+ return transitions;
+ }
+
/**
* @param sgShape
* @param node2anchor
@@ -444,7 +455,7 @@ public class SupportUtil {
GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight());
- addInitialPointIff(ctx.getTransitions(), sgShape, fp, node2anchor);
+ addInitialPointIff(ctx, ctx.getPositionProvider(), sgShape, fp, node2anchor);
addStateGraphNodes(ctx.getTrPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor);
addStateGraphNodes(ctx.getStates(), ctx.getPositionProvider(), sgShape, fp, node2anchor);
addStateGraphNodes(ctx.getChPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor);
@@ -460,6 +471,39 @@ public class SupportUtil {
return sgShape;
}
+ private static void addInitialPointIff(StateGraphContext ctx, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp,
+ HashMap<String, Anchor> node2anchor) {
+
+ // model
+ StateGraph sg = ctx.getInitialPoint();
+ if(sg==null)
+ // (super class) diagram
+ sg = positionProvider.getInitialPoint(ctx.getStateGraph());
+ if(sg==null)
+ return;
+
+ PosAndSize pos = positionProvider.getPosition(sg);
+ AddContext addContext = new AddContext();
+ addContext.setNewObject(sg);
+ addContext.setTargetContainer(sgShape);
+ if(pos != null){
+ addContext.setX(pos.getX());
+ addContext.setY(pos.getY());
+ if (pos.getWidth()>0 && pos.getHeight()>0) {
+ addContext.setWidth(pos.getWidth());
+ addContext.setHeight(pos.getHeight());
+ }
+ } else {
+ addContext.setX(3*StateGraphSupport.MARGIN);
+ addContext.setY(3*StateGraphSupport.MARGIN);
+ }
+
+ ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
+ assert(pe!=null): "initial point should have been created";
+ assert(!pe.getAnchors().isEmpty()): "initial point should have an anchor";
+ node2anchor.put(INITIAL, pe.getAnchors().get(0));
+ }
+
public static void updateStateGraph(StateGraph sg, StateGraphContext ctx, ContainerShape sgShape, IFeatureProvider fp) {
HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>();
@@ -523,16 +567,38 @@ public class SupportUtil {
SupportUtil.getSubTpAnchors(sgShape, node2anchor);
+ // initial point
+ {
+ // exists in this diagram ?
+ Shape present = null;
+ for (Shape ch : sgShape.getChildren()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(ch);
+ if (bo instanceof StateGraph)
+ present = ch;
+ }
+ if(present != null)
+ node2anchor.put(INITIAL, present.getAnchors().get(0));
+ // exists in model ?
+ StateGraph expected = ctx.getInitialPoint();
+ if(expected == null)
+ // exists in (super class) diagram ?
+ expected = ctx.getPositionProvider().getInitialPoint(ctx.getStateGraph());
+ if(expected != null && present == null)
+ addInitialPointIff(ctx, ctx.getPositionProvider(), sgShape, fp, node2anchor);
+ else
+ SupportUtil.updateInitialPoint(present, ctx.getPositionProvider(), fp);
+ }
// transitions
{
- List<Transition> present = SupportUtil.getTransitions((Diagram) sgShape.eContainer(), fp);
+ Map<Transition, Connection> present = SupportUtil.getTransitionsMap((Diagram) sgShape.eContainer(), fp);
List<Transition> expected = ctx.getTransitions();
- List<Transition> items = new ArrayList<Transition>();
- for (Transition trans : expected) {
- if (!present.contains(trans))
- items.add(trans);
- }
- SupportUtil.addTransitions(items, ctx.getPositionProvider(), sgShape, fp, node2anchor);
+ List<Transition> toAdd = new ArrayList<Transition>();
+ for (Transition trans : expected)
+ if (!present.containsKey(trans))
+ toAdd.add(trans);
+
+ SupportUtil.addTransitions(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor);
+ SupportUtil.updateTransitions(present, ctx.getPositionProvider(), sgShape, fp, node2anchor);
}
}
@@ -624,6 +690,29 @@ public class SupportUtil {
node2anchor.put(getKey(tp), pe.getAnchors().get(0));
}
+ private static void updateInitialPoint(Shape shape,
+ IPositionProvider positionProvider, IFeatureProvider fp) {
+ StateGraph sg = (StateGraph) fp.getBusinessObjectForPictogramElement(shape);
+ PosAndSize ps = positionProvider.getPosition(sg);
+ if (ps==null)
+ return;
+
+ // relocate and resize the invisible rectangle
+ GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
+
+ Graphiti.getLayoutService().setLocationAndSize(
+ ga,
+ ps.getX(),
+ ps.getY(),
+ ps.getWidth(),
+ ps.getHeight()
+ );
+
+ // have to call the layout to adjust the visible border
+ LayoutContext lc = new LayoutContext(shape);
+ fp.layoutIfPossible(lc);
+ }
+
private static void updateStateGraphNodes(List<? extends StateGraphNode> nodes, List<Shape> shapes, IPositionProvider positionProvider, IFeatureProvider fp) {
ILinkService linkService = Graphiti.getLinkService();
@@ -665,30 +754,50 @@ public class SupportUtil {
}
}
}
-
- private static void addInitialPointIff(List<Transition> transitions, ContainerShape sgShape, IFeatureProvider fp,
- HashMap<String, Anchor> node2anchor) {
-
- StateGraph sg = null;
- for (Transition t : transitions) {
- if (t instanceof InitialTransition) {
- sg = (StateGraph) t.eContainer();
- break;
+
+ private static void updateTransitions(Map<Transition, Connection> transitions, IPositionProvider positionProvider, ContainerShape sgShape,
+ IFeatureProvider fp, HashMap<String, Anchor> node2anchor) {
+
+ for(Entry<Transition, Connection> e: transitions.entrySet()){
+ Transition trans = e.getKey();
+ Connection conn = e.getValue();
+
+ String from = (trans instanceof InitialTransition)? INITIAL:getKey(((NonInitialTransition)trans).getFrom());
+ String to = getKey(trans.getTo());
+ Anchor newSrc = node2anchor.get(from);
+ Anchor newDst = node2anchor.get(to);
+
+ assert(newSrc!=null && newDst!=null): "transition endpoints must be present";
+
+ if(conn.getStart()!=newSrc)
+ conn.setStart(newSrc);
+ if(conn.getEnd()!=newDst)
+ conn.setEnd(newDst);
+
+ List<Pos> points = positionProvider.getPoints(trans);
+ Iterator<Pos> it = points.iterator();
+ if (points==null || points.isEmpty())
+ continue;
+
+ // first is label position
+ Pos pos = it.next();
+ ConnectionDecorator cd = conn.getConnectionDecorators().get(1);
+ Graphiti.getGaService().setLocation(cd.getGraphicsAlgorithm(), pos.getX(), pos.getY());
+
+ if (conn instanceof FreeFormConnection) {
+ FreeFormConnection fconn = (FreeFormConnection) conn;
+
+ // remaining are bend points
+ fconn.getBendpoints().clear();
+ List<Point> bendpoints = new ArrayList<Point>();
+ while (it.hasNext()) {
+ pos = it.next();
+ Point pt = Graphiti.getGaService().createPoint(pos.getX(), pos.getY());
+ bendpoints.add(pt);
+ }
+ fconn.getBendpoints().addAll(bendpoints);
}
}
- if (sg==null)
- return;
-
- AddContext addContext = new AddContext();
- addContext.setNewObject(sg);
- addContext.setTargetContainer(sgShape);
- addContext.setX(3*StateGraphSupport.MARGIN);
- addContext.setY(3*StateGraphSupport.MARGIN);
-
- ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
- assert(pe!=null): "initial point should have been created";
- assert(!pe.getAnchors().isEmpty()): "initial point should have an anchor";
- node2anchor.put(INITIAL, pe.getAnchors().get(0));
}
private static void getAnchors(State state, PictogramElement stateShape,

Back to the top