Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-03-09 15:52:30 +0000
committerHenrik Rentz-Reichert2011-03-09 15:52:30 +0000
commitd20daed30c77339b77effbeedd05086e8d7168bc (patch)
treeb9429e3b30ba31074ceaabd46e1cb9139e99b329
parentfb6a5ede22c0ef8fcdac7296c984db5d38a01781 (diff)
downloadorg.eclipse.etrice-d20daed30c77339b77effbeedd05086e8d7168bc.tar.gz
org.eclipse.etrice-d20daed30c77339b77effbeedd05086e8d7168bc.tar.xz
org.eclipse.etrice-d20daed30c77339b77effbeedd05086e8d7168bc.zip
ui.behavior: on save empty (and thus invalid) sub state graphs are
removed as well as their diagram parts. This solves https://bugs.eclipse.org/bugs/show_bug.cgi?id=338798
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java63
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java19
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java94
3 files changed, 136 insertions, 40 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
index 454b6d0bc..e92ee4027 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
@@ -8,8 +8,22 @@
package org.eclipse.etrice.ui.behavior.editor;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.ui.behavior.Activator;
+import org.eclipse.etrice.ui.behavior.support.ContextSwitcher;
+import org.eclipse.etrice.ui.behavior.support.StateSupport;
import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.swt.graphics.Image;
@@ -25,4 +39,53 @@ public class BehaviorEditor extends RoomDiagramEditor {
public Image getDefaultImage() {
return Activator.getImage("icons/Behavior.gif");
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @SuppressWarnings("restriction")
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ getEditingDomain().getCommandStack().execute(new RecordingCommand(getEditingDomain()) {
+ protected void doExecute() {
+ removeEmptySubgraphs();
+ }
+ });
+
+ super.doSave(monitor);
+ }
+
+ @SuppressWarnings("restriction")
+ protected void removeEmptySubgraphs() {
+ Diagram diagram = getDiagramTypeProvider().getDiagram();
+
+ // if our current context is an empty state graph we go one level up
+ StateGraph current = ContextSwitcher.getCurrentStateGraph(diagram);
+ if (current.eContainer() instanceof State) {
+ State s = (State) current.eContainer();
+ if (!StateSupport.hasSubStructure(s)) {
+ ContextSwitcher.goUp(diagram, current);
+ }
+ }
+
+ ArrayList<Shape> toBeRemoved = new ArrayList<Shape>();
+ for (Shape ctxShape : diagram.getChildren()) {
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(ctxShape);
+ assert(bo instanceof StateGraph): "expected state graph";
+
+ StateGraph sg = (StateGraph) bo;
+ if (sg.eContainer() instanceof State) {
+ State s = (State) sg.eContainer();
+ if (!StateSupport.hasSubStructure(s)) {
+ EcoreUtil.delete(sg);
+ toBeRemoved.add(ctxShape);
+ }
+ }
+ }
+
+ // need to recursively delete the shapes to avoid dangling HREFs
+ for (Shape shape : toBeRemoved) {
+ EcoreUtil.delete(shape, true);
+ }
+ }
}
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 b6e606e8a..87d45efe9 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
@@ -6,6 +6,7 @@ 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.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
@@ -50,6 +51,19 @@ public class ContextSwitcher {
activateTransitions(diagram);
}
+ public static StateGraph getCurrentStateGraph(Diagram diagram) {
+ for (Shape ctxShape : diagram.getChildren()) {
+ if (ctxShape instanceof ContainerShape && ctxShape.isVisible()) {
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(ctxShape);
+ assert(bo instanceof StateGraph): "expected state graph";
+
+ if (bo instanceof StateGraph)
+ return (StateGraph) bo;
+ }
+ }
+ return null;
+ }
+
public static ContainerShape getContext(Diagram diagram, StateGraph sg) {
for (Shape ctxShape : diagram.getChildren()) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(ctxShape);
@@ -78,6 +92,11 @@ public class ContextSwitcher {
EObject obj = it.next();
if (obj instanceof Shape) {
((Shape) obj).setVisible(activate);
+ EObject eobj = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement((Shape)obj);
+ if (eobj instanceof State) {
+ GraphicsAlgorithm border = ((Shape)obj).getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+ StateSupport.updateSubStructureHint((State)eobj, border);
+ }
}
}
}
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 1aa54d973..559799d7e 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
@@ -270,20 +270,20 @@ public class StateSupport {
if (containerGa.getGraphicsAlgorithmChildren().size()>=1) {
// the visible border
- GraphicsAlgorithm ga = containerGa.getGraphicsAlgorithmChildren().get(0);
+ GraphicsAlgorithm borderGA = containerGa.getGraphicsAlgorithmChildren().get(0);
int nw = w-2*MARGIN;
int nh = h-2*MARGIN;
- ga.setWidth(nw);
- ga.setHeight(nh);
+ borderGA.setWidth(nw);
+ borderGA.setHeight(nh);
Object bo = getBusinessObjectForPictogramElement(containerShape);
if (bo instanceof State) {
State s = (State) bo;
- ga.getGraphicsAlgorithmChildren().clear();
+ borderGA.getGraphicsAlgorithmChildren().clear();
Color lineColor = manageColor(isInherited(getDiagram(), s)?INHERITED_COLOR:LINE_COLOR);
- addSubStructureHint(s, (RoundedRectangle) ga, lineColor);
+ addSubStructureHint(s, (RoundedRectangle) borderGA, lineColor);
}
if (!containerShape.getChildren().isEmpty()) {
@@ -451,9 +451,7 @@ public class StateSupport {
PictogramElement subGraphShape = getFeatureProvider().addIfPossible(addContext);
if (subGraphShape!=null) {
RoundedRectangle borderRect = (RoundedRectangle) container.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
- boolean inherited = isInherited(getDiagram(), s);
- Color lineColor = manageColor(inherited?INHERITED_COLOR:LINE_COLOR);
- addSubStructureHint(s, borderRect, lineColor);
+ updateSubStructureHint(s, borderRect);
}
ContextSwitcher.switchTo(getDiagram(), s.getSubgraph());
@@ -507,10 +505,13 @@ public class StateSupport {
GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(0);
- if (hasSubStruct && borderRect.getGraphicsAlgorithmChildren().isEmpty())
- return Reason.createTrueReason("Ref has sub structure now");
- if (!hasSubStruct && !borderRect.getGraphicsAlgorithmChildren().isEmpty())
- return Reason.createTrueReason("Ref has no sub structure anymore");
+ if (!borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
+ GraphicsAlgorithm hint = borderRect.getGraphicsAlgorithmChildren().get(0);
+ if (hasSubStruct && !hint.getLineVisible())
+ return Reason.createTrueReason("state has sub structure now");
+ if (!hasSubStruct && hint.getLineVisible())
+ return Reason.createTrueReason("state has no sub structure anymore");
+ }
}
}
@@ -549,18 +550,10 @@ public class StateSupport {
State s = (State) bo;
{
- boolean hasSubStruct = hasSubStructure(s);
-
GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm();
if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) {
GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(0);
- if (hasSubStruct && borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
- Color lineColor = manageColor(isInherited(getDiagram(), s)?INHERITED_COLOR:LINE_COLOR);
- addSubStructureHint(s, (RoundedRectangle) borderRect, lineColor);
- }
- else if (!hasSubStruct && !borderRect.getGraphicsAlgorithmChildren().isEmpty()) {
- containerShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().clear();
- }
+ updateSubStructureHint(s, (RoundedRectangle) borderRect);
}
}
@@ -743,25 +736,6 @@ public class StateSupport {
assert(false): "no parent actor class found";
return false;
}
-
- private static boolean hasSubStructure(State acr) {
- return (acr.getSubgraph()!=null);
- }
-
- private static void addSubStructureHint(State s,
- RoundedRectangle rect, Color lineColor) {
-
- if (hasSubStructure(s)) {
- int x = rect.getWidth()-25;
- int y = 3;
- IGaService gaService = Graphiti.getGaService();
- RoundedRectangle hint1 = gaService.createRoundedRectangle(rect, HINT_CORNER_WIDTH, HINT_CORNER_WIDTH);
- hint1.setForeground(lineColor);
- hint1.setFilled(false);
- hint1.setLineWidth(LINE_WIDTH);
- gaService.setLocationAndSize(hint1, x, y, 15, 8);
- }
- }
}
private class BehaviorProvider extends DefaultToolBehaviorProvider {
@@ -840,4 +814,44 @@ public class StateSupport {
public IToolBehaviorProvider getToolBehaviorProvider() {
return tbp;
}
+
+ public static boolean hasSubStructure(State s) {
+ if (s.getSubgraph()==null)
+ return false;
+
+ StateGraph sg = s.getSubgraph();
+ if (!sg.getStates().isEmpty())
+ return true;
+ if (!sg.getTransitions().isEmpty())
+ return true;
+ if (!sg.getTrPoints().isEmpty())
+ return true;
+ if (!sg.getChPoints().isEmpty())
+ return true;
+
+ return false;
+ }
+
+ private static void addSubStructureHint(State s,
+ RoundedRectangle border, Color lineColor) {
+
+ int x = border.getWidth()-25;
+ int y = 3;
+ IGaService gaService = Graphiti.getGaService();
+ RoundedRectangle hint = gaService.createRoundedRectangle(border, HINT_CORNER_WIDTH, HINT_CORNER_WIDTH);
+ hint.setForeground(lineColor);
+ hint.setFilled(false);
+ hint.setLineWidth(LINE_WIDTH);
+ gaService.setLocationAndSize(hint, x, y, 15, 8);
+
+ if (!hasSubStructure(s)) {
+ hint.setLineVisible(false);
+ }
+ }
+
+ protected static void updateSubStructureHint(State s, GraphicsAlgorithm border) {
+
+ GraphicsAlgorithm hint = border.getGraphicsAlgorithmChildren().get(0);
+ hint.setLineVisible(hasSubStructure(s));
+ }
}

Back to the top