summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-03-21 17:28:59 (EDT)
committer Juergen Haug2013-03-28 05:54:14 (EDT)
commitf484584d54ffd72f3255c040a4d2d1608c2ff13b (patch)
tree37e0769b3471ea1658abcce3a7590a4b44d5949b
parente61c380b5daf0eaeced1e6cd60877d02606fce4c (diff)
downloadorg.eclipse.etrice-f484584d54ffd72f3255c040a4d2d1608c2ff13b.zip
org.eclipse.etrice-f484584d54ffd72f3255c040a4d2d1608c2ff13b.tar.gz
org.eclipse.etrice-f484584d54ffd72f3255c040a4d2d1608c2ff13b.tar.bz2
[ui.behavior] inherited initial point updaterefs/changes/83/11383/5
-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.java10
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java104
5 files changed, 162 insertions, 44 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 d9daa35..399369b 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 2ba2f8e..6eaa381 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 62362f2..10f3de1 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 0f1e13a..74fc8dd 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;
}
@@ -155,12 +156,7 @@ public class InitialPointSupport {
ContainerShape sgShape = context.getTargetContainer();
StateGraph sg = (StateGraph) context.getNewObject();
- boolean inherited = false;
- for (Transition tr : sg.getTransitions()) {
- if (tr instanceof InitialTransition) {
- inherited = SupportUtil.isInherited(tr, sgShape);
- }
- }
+ boolean inherited = SupportUtil.isInherited(getDiagram(), sg);
// CONTAINER SHAPE WITH RECTANGLE
IPeCreateService peCreateService = Graphiti.getPeCreateService();
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 3c3d6c4..b9b28c7 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
@@ -444,7 +444,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 +460,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,6 +556,27 @@ 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);
@@ -624,6 +678,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();
@@ -666,31 +743,6 @@ 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;
- }
- }
- 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,
final HashMap<String, Anchor> node2anchor) {