diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java')
-rw-r--r-- | plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java index af43273a6..d9315526d 100644 --- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java @@ -49,6 +49,7 @@ import org.eclipse.etrice.ui.behavior.fsm.support.StateSupport; import org.eclipse.etrice.ui.behavior.fsm.support.TrPointSupport; import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider.Pos; import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider.PosAndSize; +import org.eclipse.etrice.ui.behavior.fsm.support.IStateGraphContext; import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; import org.eclipse.graphiti.datatypes.ILocation; import org.eclipse.graphiti.features.IFeatureProvider; @@ -92,7 +93,7 @@ public class DiagramEditingUtil { return instance; } - public void updateStateGraph(StateGraph sg, StateGraphContext ctx, ContainerShape sgShape, + public void updateStateGraph(StateGraph sg, IStateGraphContext ctx, ContainerShape sgShape, IFeatureProvider fp) { HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>(); @@ -253,7 +254,7 @@ public class DiagramEditingUtil { } } - public ContainerShape addStateGraph(StateGraphContext ctx, Diagram diagram, IFeatureProvider fp) { + public ContainerShape addStateGraph(IStateGraphContext ctx, Diagram diagram, IFeatureProvider fp) { AddContext addContext = new AddContext(); addContext.setNewObject(ctx.getStateGraph()); addContext.setTargetContainer(diagram); @@ -284,7 +285,7 @@ public class DiagramEditingUtil { addStateGraphNodes(ctx.getStates(), ctx.getPositionProvider(), sgShape, fp, node2anchor); addStateGraphNodes(ctx.getChPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor); - for (StateGraphContext sub : ctx.getChildren()) { + for (IStateGraphContext sub : ctx.getChildren()) { addStateGraph(sub, diagram, fp); } @@ -378,7 +379,7 @@ public class DiagramEditingUtil { } } - private void addInitialPointIff(StateGraphContext ctx, IPositionProvider positionProvider, ContainerShape sgShape, + private void addInitialPointIff(IStateGraphContext ctx, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { // model @@ -455,11 +456,56 @@ public class DiagramEditingUtil { } } } + + private <T extends StateGraphNode> List<PosAndSize> getPositions(List<T> nodes, IPositionProvider positionProvider, double scaleX) { + ArrayList<PosAndSize> result = new ArrayList<PosAndSize>(nodes.size()); + + if (nodes.isEmpty()) + return result; + + int n = 0; + for (T node : nodes) { + PosAndSize pt = positionProvider.getPosition(node); + result.add(pt); + if (pt==null) + n++; + } + + int delta = (int) (scaleX * (n+1)); + int pos = delta; + + int h = StateGraphSupport.MARGIN; + if (nodes.get(0) instanceof State) + h = StateGraphSupport.MARGIN + StateGraphSupport.DEFAULT_SIZE_Y/4; + else if (nodes.get(0) instanceof ChoicePoint) + h = StateGraphSupport.MARGIN + StateGraphSupport.DEFAULT_SIZE_Y/2; + else if (nodes.get(0) instanceof TrPoint) + h = StateGraphSupport.MARGIN; + else { + assert(false): "unexpected sub type"; + } + + for (int i=0; i<nodes.size(); ++i) { + if (result.get(i)==null) { + PosAndSize pt = new PosAndSize( + pos, + h, + 0, + 0 + ); + result.set(i, pt); + + pos += delta; + } + } + + return result; + } private void addStateGraphNodes(List<? extends StateGraphNode> nodes, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { - List<PosAndSize> positions = positionProvider.getPositions(nodes); + List<PosAndSize> positions = getPositions(nodes, positionProvider, sgShape.getGraphicsAlgorithm().getX()); int idx = 0; for (StateGraphNode node : nodes) { |