Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-02-01 16:33:57 +0000
committerHenrik Rentz-Reichert2011-02-01 16:33:57 +0000
commit406f133d324fac033fce7cfed1b30545cfd1e282 (patch)
tree79c898c8e554c6f659a8605a67157f416347738c
parent47739edf4433775ddbe289789a99c5b27c66ff25 (diff)
downloadorg.eclipse.etrice-406f133d324fac033fce7cfed1b30545cfd1e282.tar.gz
org.eclipse.etrice-406f133d324fac033fce7cfed1b30545cfd1e282.tar.xz
org.eclipse.etrice-406f133d324fac033fce7cfed1b30545cfd1e282.zip
ui.behavior: some things that got lost during conflict resolution
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java48
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java3
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java28
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java15
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java40
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java110
6 files changed, 181 insertions, 63 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java
index 3c22705cd..72ede8152 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java
@@ -20,6 +20,8 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ChoicePoint;
import org.eclipse.etrice.core.room.ChoicepointTerminal;
+import org.eclipse.etrice.core.room.EntryPoint;
+import org.eclipse.etrice.core.room.ExitPoint;
import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.NonInitialTransition;
import org.eclipse.etrice.core.room.State;
@@ -72,6 +74,8 @@ public class PopulateDiagramCommand extends RecordingCommand {
@Override
protected void doExecute() {
+ fp.link(diagram, ac);
+
// we use a temporary structure to create the whole tree
StateGraphContext tree = StateGraphContext.createContextTree(ac);
@@ -81,12 +85,9 @@ public class PopulateDiagramCommand extends RecordingCommand {
}
private void activateTopLevel() {
- // if the container shape tree doesn't work we place all state graphs directly in the diagram
- // might also be easier to switch context - but not traversing the tree since the room model
- // doesn't reflect our context hierarchy
-
if (!diagram.getChildren().isEmpty()) {
- Shape shape = diagram.getChildren().get(0);
+ // since we made a depth first recursion the top level state graph appears last
+ Shape shape = diagram.getChildren().get(diagram.getChildren().size()-1);
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
if (bo instanceof StateGraph) {
ContextSwitcher.switchTo(diagram, (StateGraph) bo);
@@ -98,6 +99,11 @@ public class PopulateDiagramCommand extends RecordingCommand {
}
private void addStateGraph(StateGraphContext ctx, ContainerShape parent) {
+ // depth first recursion to have sub transition points in place
+ for (StateGraphContext sub : ctx.getChildren()) {
+ addStateGraph(sub, parent);
+ }
+
AddContext addContext = new AddContext();
addContext.setNewObject(ctx.getStateGraph());
addContext.setTargetContainer(parent);
@@ -114,11 +120,6 @@ public class PopulateDiagramCommand extends RecordingCommand {
addChoicePoints(ctx.getStateGraph(), sgShape, node2anchor);
addTransitions(ctx.getStateGraph(), sgShape, node2anchor);
-
- // recursion
- for (StateGraphContext sub : ctx.getChildren()) {
- addStateGraph(sub, parent);
- }
}
}
@@ -195,8 +196,10 @@ public class PopulateDiagramCommand extends RecordingCommand {
addContext.setY(StateGraphSupport.DEFAULT_SIZE_Y/4);
ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
+ assert(pe!=null): "state should have been created";
assert(!pe.getAnchors().isEmpty()): "state should have an anchor";
- node2anchor.put(getKey(s, sg), pe.getAnchors().get(0));
+
+ getAnchors(s, pe, node2anchor);
}
private void addChoicePoints(StateGraph sg, ContainerShape sgShape,
@@ -222,6 +225,7 @@ public class PopulateDiagramCommand extends RecordingCommand {
addContext.setY(StateGraphSupport.DEFAULT_SIZE_Y/2);
ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
+ assert(pe!=null): "choice point should have been created";
assert(!pe.getAnchors().isEmpty()): "choice point should have an anchor";
node2anchor.put(getKey(cp, sg), pe.getAnchors().get(0));
}
@@ -246,10 +250,32 @@ public class PopulateDiagramCommand extends RecordingCommand {
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 void getAnchors(State state, PictogramElement stateShape,
+ final HashMap<String, Anchor> node2anchor) {
+
+ if (stateShape instanceof ContainerShape) {
+ node2anchor.put(getKey(state, null), ((ContainerShape)stateShape).getAnchors().get(0));
+ for (Shape child : ((ContainerShape) stateShape).getChildren()) {
+ if (child instanceof ContainerShape) {
+ ContainerShape childShape = (ContainerShape) child;
+ if (!childShape.getAnchors().isEmpty()) {
+ if (!childShape.getLink().getBusinessObjects().isEmpty()) {
+ EObject obj = childShape.getLink().getBusinessObjects().get(0);
+ if (obj instanceof EntryPoint || obj instanceof ExitPoint) {
+ node2anchor.put(getKey(obj, null), childShape.getAnchors().get(0));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
private static String getKey(EObject obj, StateGraph sg) {
if (obj instanceof TrPoint) {
TrPoint tp = (TrPoint) obj;
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 50b9745da..82568f14f 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
@@ -26,6 +26,9 @@ class StateGraphContext {
static HashMap<EObject, StateGraphContext> obj2ctx = new HashMap<EObject, StateGraphContext>();
static StateGraphContext createContextTree(ActorClass ac) {
+
+ // TODOHRR: should we have the top level state graph always be the one of our actor class?
+
ArrayList<ActorClass> classes = new ArrayList<ActorClass>();
{
ActorClass a = ac;
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java
index 87c6f3c92..8c67f8080 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java
@@ -2,15 +2,32 @@ package org.eclipse.etrice.ui.behavior.support;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.RefinedState;
+import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
public class ContextSwitcher {
+ public static void goUp(Diagram diagram, StateGraph sg) {
+ if (sg.eContainer() instanceof State) {
+ State s = (State) sg.eContainer();
+
+ // we follow the chain of base states
+ while (s instanceof RefinedState)
+ s = ((RefinedState)s).getBase();
+
+ // and finally go up
+ StateGraph superSG = (StateGraph) s.eContainer();
+ ContextSwitcher.switchTo(diagram, superSG);
+ }
+ }
+
public static void switchTo(Diagram diagram, StateGraph sg) {
for (Shape ctxShape : diagram.getChildren()) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(ctxShape);
@@ -25,6 +42,17 @@ public class ContextSwitcher {
activateTransitions(diagram);
}
+ public static ContainerShape getContext(Diagram diagram, StateGraph sg) {
+ for (Shape ctxShape : diagram.getChildren()) {
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(ctxShape);
+ assert(bo instanceof StateGraph): "expected state graph";
+
+ if (bo instanceof StateGraph && bo==sg)
+ return (ContainerShape) ctxShape;
+ }
+ return null;
+ }
+
private static void activateTransitions(Diagram diagram) {
for (Connection conn : diagram.getConnections()) {
boolean visible = conn.getStart().getParent().isVisible();
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
index a6dc776b2..958c045da 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
@@ -16,8 +16,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.naming.RoomNameProvider;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StructureClass;
@@ -130,10 +128,6 @@ public class StateGraphSupport {
// create link and wire it
link(containerShape, sg);
-
- if (sg.eContainer() instanceof ActorClass) {
- link(getDiagram(), sg.eContainer());
- }
}
{
@@ -247,14 +241,7 @@ public class StateGraphSupport {
Object bo = getBusinessObjectForPictogramElement(container);
if (bo instanceof StateGraph) {
StateGraph sg = (StateGraph) bo;
- if (sg.eContainer() instanceof State) {
- State s = (State) sg.eContainer();
- while (s instanceof RefinedState)
- s = ((RefinedState)s).getBase();
-
- StateGraph superSG = (StateGraph) s.eContainer();
- ContextSwitcher.switchTo(getDiagram(), superSG);
- }
+ ContextSwitcher.goUp(getDiagram(), sg);
}
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
index f29e921f9..40fe3964a 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
@@ -124,13 +124,15 @@ public class StateSupport {
StateGraph sg = (StateGraph) context.getTargetContainer().getLink().getBusinessObjects().get(0);
- ActorClass ac = (ActorClass) getDiagram().getLink().getBusinessObjects().get(0);
- boolean inherited = isInherited(sg, ac);
+ boolean inherited = isInherited(sg);
if (inherited) {
+ // TODOHRR: handling of refined state - also consider refining action codes
+
// we have to insert a refined state first
RefinedState rs = RoomFactory.eINSTANCE.createRefinedState();
rs.setBase((BaseState) sg.eContainer());
+ ActorClass ac = getActorClass();
ac.getStateMachine().getStates().add(rs);
// now we change the context
@@ -193,8 +195,7 @@ public class StateSupport {
int width = context.getWidth() <= 0 ? DEFAULT_SIZE_X : context.getWidth();
int height = context.getHeight() <= 0 ? DEFAULT_SIZE_Y : context.getHeight();
- ActorClass ac = (ActorClass) getDiagram().getLink().getBusinessObjects().get(0);
- boolean inherited = isInherited(s, ac);
+ boolean inherited = isInherited(s);
Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
IGaService gaService = Graphiti.getGaService();
{
@@ -211,13 +212,10 @@ public class StateSupport {
// create link and wire it
link(containerShape, s);
- // TODOHRR-B create TrPoints of State
-// if (inherited) {
-// TrPointSupport.createInheritedRefItems(s, containerShape, fp);
-// }
-// else {
-// TrPointSupport.createRefItems(s, containerShape, fp);
-// }
+ TrPointSupport.createSubTrPoints(s, containerShape, fp);
+ if (inherited || s instanceof RefinedState) {
+ TrPointSupport.createInheritedSubTrPoints(s, containerShape, fp);
+ }
}
{
@@ -282,8 +280,7 @@ public class StateSupport {
if (bo instanceof State) {
State s = (State) bo;
ga.getGraphicsAlgorithmChildren().clear();
- ActorClass ac = (ActorClass) getDiagram().getLink().getBusinessObjects().get(0);
- Color lineColor = manageColor(isInherited(s, ac)?INHERITED_COLOR:LINE_COLOR);
+ Color lineColor = manageColor(isInherited(s)?INHERITED_COLOR:LINE_COLOR);
addSubStructureHint(s, (RoundedRectangle) ga, lineColor);
}
@@ -453,8 +450,8 @@ public class StateSupport {
PictogramElement subGraphShape = getFeatureProvider().addIfPossible(addContext);
if (subGraphShape!=null) {
RoundedRectangle borderRect = (RoundedRectangle) subGraphShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
- ActorClass ac = (ActorClass) getDiagram().getLink().getBusinessObjects().get(0);
- Color lineColor = manageColor(isInherited(s, ac)?INHERITED_COLOR:LINE_COLOR);
+ boolean inherited = ((FeatureProvider)getFeatureProvider()).isInherited(s);
+ Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
addSubStructureHint(s, borderRect, lineColor);
}
@@ -557,8 +554,7 @@ public class StateSupport {
if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(0);
if (hasSubStruct && borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
- ActorClass ac = (ActorClass) getDiagram().getLink().getBusinessObjects().get(0);
- Color lineColor = manageColor(isInherited(s, ac)?INHERITED_COLOR:LINE_COLOR);
+ Color lineColor = manageColor(isInherited(s)?INHERITED_COLOR:LINE_COLOR);
addSubStructureHint(s, (RoundedRectangle) borderRect, lineColor);
}
else if (!hasSubStruct && !borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
@@ -595,11 +591,10 @@ public class StateSupport {
if (bo instanceof State) {
State s = (State) bo;
//ContainerShape sgShape = context.getTargetContainer();
- ActorClass ac = (ActorClass) getDiagram().getLink().getBusinessObjects().get(0);
// TODOHRR: also check coordinates (no overlap with state graph boundaries)
- return !isInherited(s, ac);
+ return !isInherited(s);
}
}
@@ -716,6 +711,10 @@ public class StateSupport {
return new ICustomFeature[] { new PropertyFeature(fp), new GoDownFeature(fp), new CreateSubGraphFeature(fp) };
}
+ private ActorClass getActorClass() {
+ return (ActorClass) getDiagramTypeProvider().getDiagram().getLink().getBusinessObjects().get(0);
+ }
+
protected static String getLabel(ActorContainerRef acr) {
String className = "<unknown>";
if (acr instanceof ActorRef) {
@@ -729,7 +728,8 @@ public class StateSupport {
return acr.getName()+"\n("+className+")";
}
- protected static boolean isInherited(EObject obj, ActorClass parent) {
+ protected boolean isInherited(EObject obj) {
+ ActorClass parent = getActorClass();
while (obj!=null) {
if (obj instanceof ActorClass)
return obj!=parent;
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
index 8c09ac8fd..6067801bd 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
@@ -48,6 +48,7 @@ import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.context.ITargetContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
@@ -70,6 +71,7 @@ import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
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;
@@ -90,7 +92,7 @@ import org.eclipse.ui.PlatformUI;
public class TrPointSupport {
public static final int ITEM_SIZE = StateGraphSupport.MARGIN;
- public static final int ITEM_SIZE_SMALL = StateSupport.MARGIN;
+ public static final int ITEM_SIZE_SMALL = StateSupport.MARGIN/2;
protected static final int LINE_WIDTH = 2;
protected static final IColorConstant DARK_COLOR = new ColorConstant(0, 0, 0);
@@ -196,6 +198,9 @@ public class TrPointSupport {
if (obj instanceof StateGraph) {
return true;
}
+ if (obj instanceof State) {
+ return true;
+ }
}
}
return false;
@@ -209,7 +214,7 @@ public class TrPointSupport {
boolean inherited = isInherited(tp, bo, acShape);
boolean subtp = (bo instanceof State);
- int margin = subtp?ITEM_SIZE_SMALL:ITEM_SIZE;
+ int margin = subtp?StateSupport.MARGIN:StateGraphSupport.MARGIN;
int size = subtp?ITEM_SIZE_SMALL:ITEM_SIZE;
// CONTAINER SHAPE WITH RECTANGLE
@@ -250,7 +255,7 @@ public class TrPointSupport {
IGaService gaService = Graphiti.getGaService();
{
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
- gaService.setLocationAndSize(invisibleRectangle, x, y, 2*size, 2*size);
+ gaService.setLocationAndSize(invisibleRectangle, x, y, 2*margin, 2*margin);
createFigure(tp, subtp,
containerShape,
@@ -269,7 +274,7 @@ public class TrPointSupport {
label.setBackground(dark);
label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
- gaService.setLocationAndSize(label, 0, 3*size/2, 2*size, size/2);
+ gaService.setLocationAndSize(label, 0, 3*margin/2, 2*margin, margin/2);
adjustLabel(label, x, y, width, margin, size);
}
@@ -558,6 +563,7 @@ public class TrPointSupport {
ContainerShape containerShape,
GraphicsAlgorithm invisibleRectangle, Color darkColor, Color brightColor) {
+ int margin = subtp?StateSupport.MARGIN:StateGraphSupport.MARGIN;
int size = subtp?ITEM_SIZE_SMALL:ITEM_SIZE;
int line = subtp?LINE_WIDTH/2:LINE_WIDTH;
@@ -569,7 +575,8 @@ public class TrPointSupport {
circle.setBackground(brightColor);
circle.setLineWidth(line);
int s2 = size/2;
- gaService.setLocationAndSize(circle, s2, s2, size, size);
+ int offset = margin-s2;
+ gaService.setLocationAndSize(circle, offset, offset, size, size);
if (tp instanceof TransitionPoint) {
if (((TransitionPoint) tp).isHandler())
@@ -581,15 +588,15 @@ public class TrPointSupport {
diamond.setForeground(darkColor);
diamond.setBackground(brightColor);
diamond.setLineWidth(line);
- gaService.setLocation(diamond, s2, s2);
+ gaService.setLocation(diamond, offset, offset);
}
else if (tp instanceof EntryPoint) {
int sq = (int) (0.707106*s2);
- int l1[] = new int[] { size-sq, size+sq, size+sq, size-sq };
+ int l1[] = new int[] { margin-sq, margin+sq, margin+sq, margin-sq };
Polyline line1 = gaService.createPolyline(invisibleRectangle, l1);
line1.setLineWidth(line);
line1.setForeground(darkColor);
- int l2[] = new int[] { size-sq, size-sq, size+sq, size+sq };
+ int l2[] = new int[] { margin-sq, margin-sq, margin+sq, margin+sq };
Polyline line2 = gaService.createPolyline(invisibleRectangle, l2);
line2.setLineWidth(line);
line2.setForeground(darkColor);
@@ -704,24 +711,30 @@ public class TrPointSupport {
}
protected static void adjustLabel(Text label, int x, int y, int width, int margin, int size) {
- Orientation align = Orientation.ALIGNMENT_CENTER;
- label.setHorizontalAlignment(align);
+ Orientation halign = Orientation.ALIGNMENT_CENTER;
+ Orientation valign = Orientation.ALIGNMENT_CENTER;
- int pos = 3*size/2;
+ int pos = 0;
if (x<=margin)
- align = Orientation.ALIGNMENT_LEFT;
+ halign = Orientation.ALIGNMENT_LEFT;
else if ((width-margin)<=x)
- align = Orientation.ALIGNMENT_RIGHT;
- if (y<=margin)
+ halign = Orientation.ALIGNMENT_RIGHT;
+ if (y<=margin) {
pos = 0;
-
- if (align!=label.getHorizontalAlignment()) {
- label.setHorizontalAlignment(align);
+ valign = Orientation.ALIGNMENT_BOTTOM;
+ }
+ else {
+ pos = 5*margin/4;
+ valign = Orientation.ALIGNMENT_TOP;
}
+
+ label.setHorizontalAlignment(halign);
+ label.setVerticalAlignment(valign);
+
if (pos!=label.getY()) {
IGaService gaService = Graphiti.getGaService();
- gaService.setLocationAndSize(label, 0, pos, 2*size, size/2);
+ gaService.setLocationAndSize(label, 0, pos, 2*margin, 3*margin/4);
}
}
@@ -803,4 +816,65 @@ public class TrPointSupport {
public IToolBehaviorProvider getToolBehaviorProvider() {
return tbp;
}
+
+ public static void createSubTrPoints(State s, ContainerShape stateShape, IFeatureProvider fp) {
+ if (s.getSubgraph()==null)
+ return;
+
+ ContainerShape diag = stateShape;
+ while (diag!=null) {
+ if (diag instanceof Diagram)
+ break;
+ diag = diag.getContainer();
+ }
+ assert(diag!=null): "Diagram expected";
+ ContainerShape subGraphShape = ContextSwitcher.getContext((Diagram) diag, s.getSubgraph());
+ assert(subGraphShape!=null): "sub graph should be present";
+
+ GraphicsAlgorithm invisibleRect = stateShape.getGraphicsAlgorithm();
+ GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(0);
+ GraphicsAlgorithm invisibleSubRect = subGraphShape.getGraphicsAlgorithm();
+ GraphicsAlgorithm borderSubRect = invisibleSubRect.getGraphicsAlgorithmChildren().get(0);
+ double scaleX = borderRect.getWidth() /(double)borderSubRect.getWidth();
+ double scaleY = borderRect.getHeight()/(double)borderSubRect.getHeight();
+
+ for (TrPoint tp : s.getSubgraph().getTrPoints()) {
+ if (!(tp instanceof TransitionPoint)) {
+ int x=0, y=0;
+ for (Shape childShape : subGraphShape.getChildren()) {
+ Object bo = fp.getBusinessObjectForPictogramElement(childShape);
+ if (bo==tp) {
+ x = (int) (childShape.getGraphicsAlgorithm().getX()*scaleX);
+ y = (int) (childShape.getGraphicsAlgorithm().getY()*scaleY);
+ break;
+ }
+ }
+ addItem(tp, x, y, stateShape, fp);
+ }
+ }
+ }
+
+ public static void createInheritedSubTrPoints(State s, ContainerShape containerShape, IFeatureProvider fp) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private static void addItem(EObject ownObject, int x, int y,
+ ContainerShape stateShape, IFeatureProvider fp) {
+ AddContext addContext = new AddContext();
+ addContext.setNewObject(ownObject);
+ addContext.setTargetContainer(stateShape);
+ addContext.setX(x + ITEM_SIZE_SMALL);
+ addContext.setY(y + ITEM_SIZE_SMALL);
+ ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext);
+ assert(pe!=null): "transition point should have been created";
+ assert(!pe.getAnchors().isEmpty()): "transition point must have an anchor";
+ }
+
+// private static EObject getOwnObject(EObject obj, ResourceSet rs) {
+// URI uri = EcoreUtil.getURI(obj);
+// EObject own = rs.getEObject(uri, true);
+// assert(own!=null): "own object must exist";
+// return own;
+// }
}

Back to the top