Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2017-08-02 04:46:14 -0400
committerJuergen Haug2017-08-02 04:46:14 -0400
commitfb37813c37540fa744ddbb7bd6b3e040390de1f6 (patch)
tree325f9a9d69ce42b4062187ad292c5739078e9fe4
parent90b071921bc2e56b63adae1721164832f7d57fca (diff)
downloadorg.eclipse.etrice-fb37813c37540fa744ddbb7bd6b3e040390de1f6.tar.gz
org.eclipse.etrice-fb37813c37540fa744ddbb7bd6b3e040390de1f6.tar.xz
org.eclipse.etrice-fb37813c37540fa744ddbb7bd6b3e040390de1f6.zip
[ui.behavior] stategraphcontext and positionprovider based on newfsmgen
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java356
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java3
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java20
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMDiagramTypeProvider.java12
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.xtend61
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.xtend14
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.xtend161
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.xtend75
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java34
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.xtend87
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IStateGraphContext.java45
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java4
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java6
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java3
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramEditingUtil.java56
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.java115
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.java117
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.java386
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.java151
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.java182
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramExtensions.java31
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ProviderDispatcher.java43
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java48
25 files changed, 1829 insertions, 187 deletions
diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java
new file mode 100644
index 000000000..5bbb53340
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/BasicFsmGenBuilder.java
@@ -0,0 +1,356 @@
+/**
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.core.genmodel.fsm;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.fsm.fSM.ChoicePoint;
+import org.eclipse.etrice.core.fsm.fSM.ChoicepointTerminal;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.fsm.fSM.NonInitialTransition;
+import org.eclipse.etrice.core.fsm.fSM.RefinedState;
+import org.eclipse.etrice.core.fsm.fSM.RefinedTransition;
+import org.eclipse.etrice.core.fsm.fSM.SimpleState;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.fsm.fSM.StateTerminal;
+import org.eclipse.etrice.core.fsm.fSM.SubStateTrPointTerminal;
+import org.eclipse.etrice.core.fsm.fSM.TrPoint;
+import org.eclipse.etrice.core.fsm.fSM.TrPointTerminal;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.core.fsm.fSM.TransitionTerminal;
+import org.eclipse.etrice.core.fsm.util.FSMHelpers;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.FsmGenFactory;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+
+@SuppressWarnings("all")
+public class BasicFsmGenBuilder {
+ @Inject
+ @Extension
+ protected FSMHelpers fsmHelpers;
+
+ protected final FsmGenFactory factory = FsmGenFactory.eINSTANCE;
+
+ public BasicFsmGenBuilder(final Injector injector) {
+ injector.injectMembers(this);
+ }
+
+ protected BasicFsmGenBuilder() {
+ }
+
+ public GraphContainer createTransformedModel(final ModelComponent mc) {
+ return this.createContainer(mc);
+ }
+
+ private GraphContainer createContainer(final ModelComponent mc) {
+ final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(mc);
+ final GraphContainer _result;
+ synchronized (_createCache_createContainer) {
+ if (_createCache_createContainer.containsKey(_cacheKey)) {
+ return _createCache_createContainer.get(_cacheKey);
+ }
+ GraphContainer _createGraphContainer = this.factory.createGraphContainer();
+ _result = _createGraphContainer;
+ _createCache_createContainer.put(_cacheKey, _result);
+ }
+ _init_createContainer(_result, mc);
+ return _result;
+ }
+
+ private final HashMap<ArrayList<?>, GraphContainer> _createCache_createContainer = CollectionLiterals.newHashMap();
+
+ private void _init_createContainer(final GraphContainer it, final ModelComponent mc) {
+ it.setComponent(mc);
+ Graph _createStateMachine = this.createStateMachine(mc);
+ it.setGraph(_createStateMachine);
+ }
+
+ private Graph createStateMachine(final ModelComponent mc) {
+ Graph _xblockexpression = null;
+ {
+ final StateGraph superFSM = this.fsmHelpers.getSuperStateMachine(mc);
+ Graph _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(superFSM, null));
+ if (_notEquals) {
+ Graph _xblockexpression_1 = null;
+ {
+ ModelComponent _modelComponent = this.fsmHelpers.getModelComponent(superFSM);
+ final Graph baseGraph = this.createStateMachine(_modelComponent);
+ StateGraph _actualStateMachine = this.fsmHelpers.getActualStateMachine(mc);
+ _xblockexpression_1 = this.mergeGraph(baseGraph, _actualStateMachine);
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ StateGraph _actualStateMachine = this.fsmHelpers.getActualStateMachine(mc);
+ Graph _createGraph = null;
+ if (_actualStateMachine!=null) {
+ _createGraph=this.createGraph(_actualStateMachine);
+ }
+ _xifexpression = _createGraph;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ private Graph mergeGraph(final Graph graph, final StateGraph sg) {
+ EList<Node> _nodes = graph.getNodes();
+ final Consumer<Node> _function = new Consumer<Node>() {
+ @Override
+ public void accept(final Node it) {
+ it.setInherited(true);
+ }
+ };
+ _nodes.forEach(_function);
+ EList<Link> _links = graph.getLinks();
+ final Consumer<Link> _function_1 = new Consumer<Link>() {
+ @Override
+ public void accept(final Link it) {
+ it.setInherited(true);
+ }
+ };
+ _links.forEach(_function_1);
+ this.createContents(graph, sg);
+ graph.setStateGraph(sg);
+ return graph;
+ }
+
+ private Graph createGraph(final StateGraph sg) {
+ final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(sg);
+ final Graph _result;
+ synchronized (_createCache_createGraph) {
+ if (_createCache_createGraph.containsKey(_cacheKey)) {
+ return _createCache_createGraph.get(_cacheKey);
+ }
+ Graph _createGraph = this.factory.createGraph();
+ _result = _createGraph;
+ _createCache_createGraph.put(_cacheKey, _result);
+ }
+ _init_createGraph(_result, sg);
+ return _result;
+ }
+
+ private final HashMap<ArrayList<?>, Graph> _createCache_createGraph = CollectionLiterals.newHashMap();
+
+ private void _init_createGraph(final Graph it, final StateGraph sg) {
+ it.setStateGraph(sg);
+ this.createContents(it, sg);
+ }
+
+ private void createContents(final Graph graph, final StateGraph sg) {
+ EList<Node> _nodes = graph.getNodes();
+ EList<ChoicePoint> _chPoints = sg.getChPoints();
+ final Function1<ChoicePoint, Node> _function = new Function1<ChoicePoint, Node>() {
+ @Override
+ public Node apply(final ChoicePoint it) {
+ return BasicFsmGenBuilder.this.createNode(it);
+ }
+ };
+ List<Node> _map = ListExtensions.<ChoicePoint, Node>map(_chPoints, _function);
+ _nodes.addAll(_map);
+ EList<Node> _nodes_1 = graph.getNodes();
+ EList<TrPoint> _trPoints = sg.getTrPoints();
+ final Function1<TrPoint, Node> _function_1 = new Function1<TrPoint, Node>() {
+ @Override
+ public Node apply(final TrPoint it) {
+ return BasicFsmGenBuilder.this.createNode(it);
+ }
+ };
+ List<Node> _map_1 = ListExtensions.<TrPoint, Node>map(_trPoints, _function_1);
+ _nodes_1.addAll(_map_1);
+ EList<Node> _nodes_2 = graph.getNodes();
+ EList<State> _states = sg.getStates();
+ Iterable<SimpleState> _filter = Iterables.<SimpleState>filter(_states, SimpleState.class);
+ final Function1<SimpleState, Node> _function_2 = new Function1<SimpleState, Node>() {
+ @Override
+ public Node apply(final SimpleState it) {
+ return BasicFsmGenBuilder.this.createNode(it);
+ }
+ };
+ Iterable<Node> _map_2 = IterableExtensions.<SimpleState, Node>map(_filter, _function_2);
+ Iterables.<Node>addAll(_nodes_2, _map_2);
+ EList<Link> _links = graph.getLinks();
+ EList<Transition> _transitions = sg.getTransitions();
+ final Function1<Transition, Link> _function_3 = new Function1<Transition, Link>() {
+ @Override
+ public Link apply(final Transition it) {
+ return BasicFsmGenBuilder.this.createLink(it);
+ }
+ };
+ List<Link> _map_3 = ListExtensions.<Transition, Link>map(_transitions, _function_3);
+ _links.addAll(_map_3);
+ EList<State> _states_1 = sg.getStates();
+ Iterable<RefinedState> _filter_1 = Iterables.<RefinedState>filter(_states_1, RefinedState.class);
+ final Consumer<RefinedState> _function_4 = new Consumer<RefinedState>() {
+ @Override
+ public void accept(final RefinedState it) {
+ BasicFsmGenBuilder.this.handleRefinedState(it);
+ }
+ };
+ _filter_1.forEach(_function_4);
+ EList<RefinedTransition> _refinedTransitions = sg.getRefinedTransitions();
+ final Consumer<RefinedTransition> _function_5 = new Consumer<RefinedTransition>() {
+ @Override
+ public void accept(final RefinedTransition it) {
+ BasicFsmGenBuilder.this.handleRefinedTransition(it);
+ }
+ };
+ _refinedTransitions.forEach(_function_5);
+ }
+
+ private void handleRefinedState(final RefinedState s) {
+ StateGraph _subgraph = s.getSubgraph();
+ boolean _notEquals = (!Objects.equal(_subgraph, null));
+ if (_notEquals) {
+ State _target = s.getTarget();
+ StateGraph _subgraph_1 = _target.getSubgraph();
+ boolean _notEquals_1 = (!Objects.equal(_subgraph_1, null));
+ if (_notEquals_1) {
+ State _target_1 = s.getTarget();
+ StateGraph _subgraph_2 = _target_1.getSubgraph();
+ final Graph targetGraph = this.createGraph(_subgraph_2);
+ StateGraph _subgraph_3 = s.getSubgraph();
+ this.mergeGraph(targetGraph, _subgraph_3);
+ } else {
+ State _target_2 = s.getTarget();
+ Node _createNode = this.createNode(_target_2);
+ StateGraph _subgraph_4 = s.getSubgraph();
+ Graph _createGraph = this.createGraph(_subgraph_4);
+ _createNode.setSubgraph(_createGraph);
+ }
+ }
+ State _target_3 = s.getTarget();
+ final Node target = this.createNode(_target_3);
+ target.setStateGraphNode(s);
+ }
+
+ private void handleRefinedTransition(final RefinedTransition t) {
+ Transition _target = t.getTarget();
+ Link _createLink = this.createLink(_target);
+ _createLink.setTransition(t);
+ }
+
+ private Link createLink(final Transition tr) {
+ final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(tr);
+ final Link _result;
+ synchronized (_createCache_createLink) {
+ if (_createCache_createLink.containsKey(_cacheKey)) {
+ return _createCache_createLink.get(_cacheKey);
+ }
+ Link _createLink = this.factory.createLink();
+ _result = _createLink;
+ _createCache_createLink.put(_cacheKey, _result);
+ }
+ _init_createLink(_result, tr);
+ return _result;
+ }
+
+ private final HashMap<ArrayList<?>, Link> _createCache_createLink = CollectionLiterals.newHashMap();
+
+ private void _init_createLink(final Link it, final Transition tr) {
+ it.setTransition(tr);
+ Node _xifexpression = null;
+ if ((tr instanceof NonInitialTransition)) {
+ TransitionTerminal _from = ((NonInitialTransition)tr).getFrom();
+ _xifexpression = this.createNode(_from);
+ }
+ it.setSource(_xifexpression);
+ TransitionTerminal _to = tr.getTo();
+ Node _createNode = this.createNode(_to);
+ it.setTarget(_createNode);
+ }
+
+ private Node _createNode(final StateGraphNode s) {
+ final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(s);
+ final Node _result;
+ synchronized (_createCache_createNode) {
+ if (_createCache_createNode.containsKey(_cacheKey)) {
+ return _createCache_createNode.get(_cacheKey);
+ }
+ Node _createNode = this.factory.createNode();
+ _result = _createNode;
+ _createCache_createNode.put(_cacheKey, _result);
+ }
+ _init_createNode(_result, s);
+ return _result;
+ }
+
+ private final HashMap<ArrayList<?>, Node> _createCache_createNode = CollectionLiterals.newHashMap();
+
+ private void _init_createNode(final Node it, final StateGraphNode s) {
+ it.setStateGraphNode(s);
+ Graph _xifexpression = null;
+ if ((s instanceof State)) {
+ StateGraph _subgraph = ((State)s).getSubgraph();
+ Graph _createGraph = null;
+ if (_subgraph!=null) {
+ _createGraph=this.createGraph(_subgraph);
+ }
+ _xifexpression = _createGraph;
+ }
+ it.setSubgraph(_xifexpression);
+ }
+
+ private Node _createNode(final ChoicepointTerminal tt) {
+ ChoicePoint _cp = tt.getCp();
+ return this.createNode(_cp);
+ }
+
+ private Node _createNode(final TrPointTerminal tt) {
+ TrPoint _trPoint = tt.getTrPoint();
+ return this.createNode(_trPoint);
+ }
+
+ private Node _createNode(final StateTerminal tt) {
+ State _state = tt.getState();
+ return this.createNode(_state);
+ }
+
+ private Node _createNode(final SubStateTrPointTerminal tt) {
+ TrPoint _trPoint = tt.getTrPoint();
+ return this.createNode(_trPoint);
+ }
+
+ private Node createNode(final EObject tt) {
+ if (tt instanceof ChoicepointTerminal) {
+ return _createNode((ChoicepointTerminal)tt);
+ } else if (tt instanceof StateGraphNode) {
+ return _createNode((StateGraphNode)tt);
+ } else if (tt instanceof StateTerminal) {
+ return _createNode((StateTerminal)tt);
+ } else if (tt instanceof SubStateTrPointTerminal) {
+ return _createNode((SubStateTrPointTerminal)tt);
+ } else if (tt instanceof TrPointTerminal) {
+ return _createNode((TrPointTerminal)tt);
+ } else {
+ throw new IllegalArgumentException("Unhandled parameter types: " +
+ Arrays.<Object>asList(tt).toString());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF
index d1e859f90..7b4338cf0 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF
@@ -5,10 +5,10 @@ Bundle-SymbolicName: org.eclipse.etrice.ui.behavior.fsm;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.etrice.ui.behavior.fsm.Activator
Bundle-Vendor: eTrice
-Require-Bundle: org.eclipse.etrice.core.genmodel.fsm2;bundle-version="1.0.0",
- org.eclipse.etrice.core.common.ui;bundle-version="1.1.0",
+Require-Bundle: org.eclipse.etrice.core.common.ui;bundle-version="1.1.0",
org.eclipse.etrice.ui.common.base;bundle-version="1.1.0",
org.eclipse.etrice.core.fsm;bundle-version="1.1.0",
+ org.eclipse.etrice.core.genmodel.fsm;bundle-version="1.1.0",
org.eclipse.etrice.core.fsm.ui;bundle-version="1.1.0",
org.eclipse.graphiti;bundle-version="0.8.0",
org.eclipse.graphiti.ui;bundle-version="0.8.0",
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java
index 907066327..7edc726d5 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java
@@ -40,6 +40,9 @@ public class PopulateDiagramCommand extends RecordingCommand {
IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, providerId); //$NON-NLS-1$
dtp.getFeatureProvider().link(diagram, mc);
+
+ //IStateGraphContext tree = new GenModelStateGraphContext((AbstractFSMDiagramTypeProvider)dtp);
+ //DiagramEditingUtil.getInstance().addStateGraph(tree, diagram, dtp.getFeatureProvider());
UpdateContext ctx = new UpdateContext(diagram);
dtp.getFeatureProvider().getUpdateFeature(ctx).update(ctx);
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java
index 01b3a1a2f..c6a5ed4db 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java
@@ -2,6 +2,7 @@ package org.eclipse.etrice.ui.behavior.fsm.commands;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.fsm.fSM.ChoicePoint;
@@ -17,11 +18,12 @@ import org.eclipse.etrice.core.fsm.fSM.TrPoint;
import org.eclipse.etrice.core.fsm.fSM.Transition;
import org.eclipse.etrice.ui.behavior.fsm.support.DefaultPositionProvider;
import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider;
+import org.eclipse.etrice.ui.behavior.fsm.support.IStateGraphContext;
import org.eclipse.etrice.ui.behavior.fsm.support.util.FSMSupportUtil;
import com.google.inject.Injector;
-public class StateGraphContext {
+public class StateGraphContext implements IStateGraphContext {
private ArrayList<StateGraphContext> children = new ArrayList<StateGraphContext>();
private StateGraph stateGraph;
@@ -143,7 +145,7 @@ public class StateGraphContext {
// merge sub contexts
if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(base)) {
StateGraphContext basesub = null;
- for (StateGraphContext bs : ctx.getChildren()) {
+ for (StateGraphContext bs : ctx.children) {
if (bs.getParentState()==base) {
basesub = bs;
break;
@@ -172,7 +174,7 @@ public class StateGraphContext {
* @param tree
*/
private static void makePositionsAvailableToChildrenContexts(StateGraphContext tree) {
- for (StateGraphContext child : tree.getChildren()) {
+ for (StateGraphContext child : tree.children) {
child.positionProvider = tree.positionProvider;
makePositionsAvailableToChildrenContexts(child);
}
@@ -185,15 +187,15 @@ public class StateGraphContext {
return null;
}
- public ArrayList<StateGraphContext> getChildren() {
- return children;
+ public List<IStateGraphContext> getChildren() {
+ return new ArrayList<IStateGraphContext>(children);
}
- public ArrayList<State> getStates() {
+ public List<State> getStates() {
return states;
}
- public ArrayList<ChoicePoint> getChPoints() {
+ public List<ChoicePoint> getChPoints() {
return chPoints;
}
@@ -201,11 +203,11 @@ public class StateGraphContext {
return stateGraph;
}
- public ArrayList<TrPoint> getTrPoints() {
+ public List<TrPoint> getTrPoints() {
return trPoints;
}
- public ArrayList<Transition> getTransitions() {
+ public List<Transition> getTransitions() {
return transitions;
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMDiagramTypeProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMDiagramTypeProvider.java
index 94cd2fdbb..4e6fcd9e2 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMDiagramTypeProvider.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMDiagramTypeProvider.java
@@ -25,14 +25,12 @@ import org.eclipse.graphiti.platform.IDiagramContainer;
*/
public abstract class AbstractFSMDiagramTypeProvider extends AbstractDiagramTypeProvider implements IInjectorProvider {
- protected GenModelProvider genModelProvider;
-
- public AbstractFSMDiagramTypeProvider(){
- genModelProvider = new GenModelProvider(this);
- }
-
public GenModelProvider getGenModelProvider() {
- return genModelProvider;
+ // create always new one for now
+// Stopwatch timer = Stopwatch.createStarted();
+// GenModelProvider genModelProvider = new GenModelProvider(this);
+// System.out.println(timer.stop().elapsed(TimeUnit.MILLISECONDS));
+ return new GenModelProvider(this);
}
/* (non-Javadoc)
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.xtend b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.xtend
new file mode 100644
index 000000000..cb62d9e4a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.xtend
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.provider
+
+import com.google.common.collect.ArrayListMultimap
+import com.google.common.collect.Multimap
+import java.util.Collection
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.util.EcoreUtil
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider
+import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase
+import org.eclipse.graphiti.mm.pictograms.Diagram
+import org.eclipse.graphiti.mm.pictograms.PictogramElement
+import org.eclipse.graphiti.mm.pictograms.PictogramLink
+import org.eclipse.graphiti.services.Graphiti
+
+/**
+ * Provides the {@linkplain PictogramElement} objects of the base class diagram.
+ * This is a reverse mapping from room business objects to linked base diagram pictograms.
+ */
+class BaseDiagramProvider {
+
+ val Diagram baseDiagram
+ val Multimap<EObject, PictogramElement> baseDiagramBusinessObjs = ArrayListMultimap.create
+
+ new(AbstractFSMDiagramTypeProvider diagramTypeProvider) {
+ val diagramAccess = diagramTypeProvider.injector.getInstance(DiagramAccessBase)
+ val mc = Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(diagramTypeProvider.diagram) as ModelComponent
+ val rs = diagramTypeProvider.diagram.eResource.resourceSet
+
+ // open base diagram => causes full recursive update or creation of all base diagrams
+ baseDiagram = if(mc.base != null) diagramAccess.getDiagram(mc.base, rs)
+ if(baseDiagram != null) {
+ // create mapping from business object to pictogram elements
+ EcoreUtil.ExternalCrossReferencer.find(baseDiagram).forEach [ targetEObj, eFeatureSetting |
+ eFeatureSetting.map[getEObject].filter(PictogramLink).map[pictogramElement].forEach [ pe |
+ baseDiagramBusinessObjs.put(targetEObj, pe)
+ ]
+ ]
+
+ // base diagram resource not needed anymore
+ rs.resources.remove(baseDiagram.eResource)
+ }
+ }
+
+ def Collection<PictogramElement> getPictograms(EObject roomObj) {
+ if(roomObj == null) emptyList else baseDiagramBusinessObjs.get(roomObj)
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.xtend b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.xtend
index 0f0d874eb..5503e3f53 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.xtend
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.xtend
@@ -23,12 +23,13 @@ import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider
import org.eclipse.graphiti.dt.IDiagramTypeProvider
import org.eclipse.graphiti.services.Graphiti
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.FSMGenElement
class GenModelProvider {
val BasicFsmGenBuilder builder
val IDiagramTypeProvider fsmDiagramProvider
- var Map<EObject, EObject> graphMap = newHashMap
+ var Map<EObject, FSMGenElement> graphMap = newHashMap
var GraphContainer modelInstance = null
@@ -42,11 +43,12 @@ class GenModelProvider {
modelInstance = if(it instanceof ModelComponent) builder.createTransformedModel(it) else null
]
if (modelInstance != null) {
- graphMap = modelInstance.eAllContents.toMap [
+ graphMap.clear
+ modelInstance.eAllContents.forEach [
switch (it) {
- Graph: stateGraph
- Node: stateGraphNode
- Link: transition
+ Graph: graphMap.put(stateGraph, it)
+ Node: graphMap.put(stateGraphNode, it)
+ Link: graphMap.put(transition, it)
}
]
}
@@ -60,7 +62,7 @@ class GenModelProvider {
return modelInstance;
}
- def <T extends EObject> getCasted(EObject roomObj) {
+ def <T extends FSMGenElement> getCasted(EObject roomObj) {
return graphMap.get(roomObj) as T
}
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.xtend b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.xtend
new file mode 100644
index 000000000..33bbdf199
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.xtend
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.support
+
+import java.util.List
+import org.eclipse.etrice.core.fsm.fSM.InitialTransition
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent
+import org.eclipse.etrice.core.fsm.fSM.RefinedState
+import org.eclipse.etrice.core.fsm.fSM.RefinedTransition
+import org.eclipse.etrice.core.fsm.fSM.State
+import org.eclipse.etrice.core.fsm.fSM.StateGraph
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode
+import org.eclipse.etrice.core.fsm.fSM.TrPoint
+import org.eclipse.etrice.core.fsm.fSM.Transition
+import org.eclipse.etrice.ui.behavior.fsm.provider.BaseDiagramProvider
+import org.eclipse.graphiti.mm.algorithms.Text
+import org.eclipse.graphiti.mm.pictograms.Connection
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection
+import org.eclipse.graphiti.mm.pictograms.PictogramElement
+import org.eclipse.graphiti.services.Graphiti
+import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
+
+/**
+ * IPositionProvider based on {@linkplain BaseDiagramProvider}
+ * Logic copied from DefaultPositionProvider
+ */
+@FinalFieldsConstructor
+class BaseDiagramPositionProvider implements IPositionProvider {
+
+ val BaseDiagramProvider baseDiagram
+
+ // TODO: positions should not rely on graphics internals
+ def getMargin(StateGraphNode node) {
+ switch node {
+ State: StateSupport.MARGIN
+ TrPoint: TrPointSupport.MARGIN
+ default: 0
+ }
+ }
+
+ // TODO: positions should not rely on graphics internals
+ def getMargin(StateGraph graph){
+ return 0
+ }
+
+ def private toPosAndSize(PictogramElement pe, int margin){
+ val borderGa = (pe.eContainer as PictogramElement).graphicsAlgorithm.graphicsAlgorithmChildren.head
+ val ga = pe.graphicsAlgorithm
+
+ val x = (ga.getX() / borderGa.width as double) * sx + margin
+ val y = (ga.getY() / borderGa.height as double) * sy + margin
+ val width = ((ga.getWidth() - 2 * margin) / borderGa.width as double) * sx
+ val height = ((ga.getHeight() - 2 * margin) / borderGa.height as double) * sy
+
+ new PosAndSize(x as int, y as int, width as int, height as int)
+ }
+
+ override getGraphPosAndSize(StateGraph sg) {
+ // graph is child of border shape, see initial point
+ val pe = baseDiagram.getPictograms(sg).findFirst[parentBo instanceof ModelComponent]
+ if(pe != null){
+ val visibleGa = pe.graphicsAlgorithm.graphicsAlgorithmChildren.head
+ new PosAndSize(pe.graphicsAlgorithm.x, pe.graphicsAlgorithm.y, visibleGa.width, visibleGa.height)
+ }
+ }
+
+ override getPoints(Transition trans) {
+ val pe = {
+ if (trans instanceof RefinedTransition)
+ baseDiagram.getPictograms(trans.target).head
+ else
+ baseDiagram.getPictograms(trans).head
+ }
+ newArrayList => [ pointList |
+ if(pe instanceof Connection){
+ val graphPosAndSize = getGraphPosAndSize(trans.eContainer as StateGraph)
+ val text = pe.connectionDecorators.map[graphicsAlgorithm].filter(Text).head
+ if(text != null){
+ pointList += new Pos(
+ ((text.x / graphPosAndSize.width as double) * sx) as int,
+ ((text.y / graphPosAndSize.height as double) * sy) as int
+ )
+ if(pe instanceof FreeFormConnection){
+ pointList += pe.bendpoints.map[new Pos(
+ ((text.x / graphPosAndSize.width as double) * sx + x) as int,
+ ((text.y / graphPosAndSize.height as double) * sy + y) as int
+ )]
+ }
+ }
+ }
+ ]
+ }
+
+ override getPosition(StateGraphNode node) {
+ if(node instanceof RefinedState){
+ baseDiagram.getPictograms(node.target).findFirst[parentBo instanceof StateGraph]?.toPosAndSize(node.margin)
+ } else {
+ baseDiagram.getPictograms(node).findFirst[parentBo instanceof StateGraph]?.toPosAndSize(node.margin)
+ }
+ }
+
+ override getInitialPoint(StateGraph stateGraph) {
+ val initTransPe = baseDiagram.getPictograms(stateGraph.transitions.filter(InitialTransition).head).head
+ if(initTransPe instanceof Connection){
+ val sourceAnchorBo = Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(initTransPe.start)
+ if(sourceAnchorBo instanceof StateGraph)
+ return sourceAnchorBo
+ }
+ }
+
+ // TODO: better naming, this is initial point
+ override getPosition(StateGraph graph) {
+ // initial point bo is graph and it is child of border shape
+ baseDiagram.getPictograms(graph).findFirst[parentBo instanceof StateGraph]?.toPosAndSize(graph.margin)
+ }
+
+ override <T extends StateGraphNode> getPositions(List<T> items) {
+ items.map[baseDiagram.getPictograms(it).head?.toPosAndSize(it.margin)]
+ }
+
+ override getSubPosition(StateGraphNode subNode) {
+ val pe = baseDiagram.getPictograms(subNode).findFirst[parentBo instanceof State]
+ if(pe != null){
+ val parentPe = pe.eContainer as PictogramElement
+ val relX = pe.graphicsAlgorithm.getX() as double / (parentPe.graphicsAlgorithm.getWidth() - 2 * StateSupport.MARGIN)
+ val relY = pe.graphicsAlgorithm.getY() as double / (parentPe.graphicsAlgorithm.getHeight() - 2 * StateSupport.MARGIN)
+ return #[relX, relY]
+ }
+ }
+
+ var int x
+ var int y
+
+ override setPosition(int x, int y) {
+ this.x = x
+ this.y = y
+ }
+
+ var double sx
+ var double sy
+
+ override setScale(double sx, double sy) {
+ this.sx = sx
+ this.sy = sy
+ }
+
+ def private getParentBo(PictogramElement pe) {
+ Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(pe.eContainer as PictogramElement)
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.xtend b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.xtend
deleted file mode 100644
index 961b5da9d..000000000
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.xtend
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Juergen Haug (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.behavior.fsm.support
-
-import java.util.Map
-import org.eclipse.emf.ecore.EObject
-import org.eclipse.emf.ecore.util.EcoreUtil
-import org.eclipse.etrice.core.fsm.fSM.ModelComponent
-import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider
-import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase
-import org.eclipse.graphiti.mm.pictograms.Diagram
-import org.eclipse.graphiti.mm.pictograms.PictogramElement
-import org.eclipse.graphiti.mm.pictograms.PictogramLink
-import org.eclipse.graphiti.services.Graphiti
-
-/**
- * Provides the PictogramElements from the base class diagram. Replacement for DefaultPositionProvider.
- */
-class BaseDiagramProvider {
-
- val DiagramAccessBase diagramAccess
-
- val Map<EObject, PictogramElement> graphElements = newHashMap
- val Map<EObject, PictogramElement> stateElements = newHashMap
-
- new(AbstractFSMDiagramTypeProvider diagramTypeProvider) {
- diagramAccess = diagramTypeProvider.injector.getInstance(DiagramAccessBase)
-
- val mc = Graphiti.linkService.getBusinessObjectForLinkedPictogramElement(diagramTypeProvider.diagram)
- if (mc instanceof ModelComponent)
- visitDiagramRec(mc.base)
- }
-
- def void visitDiagramRec(ModelComponent mc) {
- if(mc == null) return;
-
- val rs = mc.eResource.resourceSet
- // temporary load base diagram into current resourceSet to link its business objects against current resources
- val diagram = diagramAccess.getDiagram(mc, mc.eResource.resourceSet)
- if (diagram != null) {
- mapPositions(diagram)
- rs.resources.remove(diagram)
- }
-
- // visitDiagramRec(mc.base)
- }
-
- def mapPositions(Diagram diagram) {
- // create mapping from business object to pictogram elements
- EcoreUtil.ExternalCrossReferencer.find(diagram).forEach [ crossRef, eFeatureSetting |
- eFeatureSetting.forEach [
- // println(crossRef + " -> " + EObject)
- if (EObject instanceof PictogramLink) {
- val pe = (EObject as PictogramLink).pictogramElement
- graphElements.put(crossRef, pe)
- }
- ]
- ]
- }
-
- def getBasePictogram(EObject roomObj) {
- return graphElements.get(roomObj)
- }
-
-}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java
index 66c445dc4..7f3e91ef2 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java
@@ -94,7 +94,7 @@ import org.eclipse.ui.PlatformUI;
import com.google.inject.Injector;
public class ChoicePointSupport {
-
+
public static final int ITEM_SIZE = (int) (StateGraphSupport.MARGIN*0.625);
protected static final int LINE_WIDTH = 2;
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java
index 6d194add9..8cdd19284 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java
@@ -14,9 +14,12 @@ package org.eclipse.etrice.ui.behavior.fsm.support;
import java.util.ArrayList;
+import org.eclipse.etrice.core.fsm.fSM.FSMFactory;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.fSM.StateGraph;
import org.eclipse.etrice.ui.behavior.fsm.commands.StateGraphContext;
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider;
+import org.eclipse.etrice.ui.behavior.fsm.provider.GenModelProvider;
import org.eclipse.etrice.ui.behavior.fsm.provider.IInjectorProvider;
import org.eclipse.etrice.ui.behavior.fsm.support.util.DiagramEditingUtil;
import org.eclipse.etrice.ui.behavior.fsm.support.util.FSMSupportUtil;
@@ -65,9 +68,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
*/
@Override
public IReason updateNeeded(IUpdateContext context) {
- ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram());
- Injector injector = ((IInjectorProvider) getFeatureProvider()).getInjector();
- StateGraphContext tree = StateGraphContext.createContextTree(mc, injector);
+ IStateGraphContext tree = createStateGraphContext();
usedShapes.clear();
@@ -110,9 +111,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
*/
@Override
public boolean update(IUpdateContext context) {
- ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram());
- Injector injector = ((IInjectorProvider) getFeatureProvider()).getInjector();
- StateGraphContext tree = StateGraphContext.createContextTree(mc, injector);
+ IStateGraphContext tree = createStateGraphContext();
StateGraph currentStateGraph = ContextSwitcher.getCurrentStateGraph(getDiagram());
@@ -171,7 +170,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
* @param ctx
* @return
*/
- private IReason updateNeeded(StateGraphContext ctx) {
+ private IReason updateNeeded(IStateGraphContext ctx) {
StateGraph sg = ctx.getStateGraph();
ContainerShape cont = findStateGraphContainer(sg);
if (cont==null)
@@ -198,7 +197,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
}
// recursion
- for (StateGraphContext child : ctx.getChildren()) {
+ for (IStateGraphContext child : ctx.getChildren()) {
IReason needUpdate = updateNeeded(child);
if (needUpdate.toBoolean())
return needUpdate;
@@ -211,7 +210,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
* @param ctx
* @return
*/
- private boolean update(StateGraphContext ctx) {
+ private boolean update(IStateGraphContext ctx) {
boolean changed = false;
StateGraph sg = ctx.getStateGraph();
@@ -244,7 +243,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
}
// recursion
- for (StateGraphContext child : ctx.getChildren()) {
+ for (IStateGraphContext child : ctx.getChildren()) {
if (update(child))
changed = true;
}
@@ -264,5 +263,20 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
}
return null;
}
+
+ private IStateGraphContext createStateGraphContext(){
+ ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram());
+// Injector injector = ((IInjectorProvider) getFeatureProvider()).getInjector();
+// StateGraphContext tree = StateGraphContext.createContextTree(mc, injector);
+
+ // side effect on model, but diagram needs that for initial graph shape
+ if(mc.getStateMachine() == null || mc.getStateMachine().eIsProxy()){
+ mc.setStateMachine(FSMFactory.eINSTANCE.createStateGraph());
+ }
+
+ IStateGraphContext tree = new GenModelStateGraphContext((AbstractFSMDiagramTypeProvider)getFeatureProvider().getDiagramTypeProvider());
+
+ return tree;
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.xtend b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.xtend
new file mode 100644
index 000000000..64243cbfd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.xtend
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.support
+
+import org.eclipse.etrice.core.fsm.fSM.ChoicePoint
+import org.eclipse.etrice.core.fsm.fSM.InitialTransition
+import org.eclipse.etrice.core.fsm.fSM.State
+import org.eclipse.etrice.core.fsm.fSM.TrPoint
+import org.eclipse.etrice.core.fsm.fSM.Transition
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider
+import org.eclipse.etrice.ui.behavior.fsm.provider.BaseDiagramProvider
+import org.eclipse.etrice.ui.behavior.fsm.provider.GenModelProvider
+
+/**
+ * StateGraphContext based on newfsmgen.
+ */
+class GenModelStateGraphContext implements IStateGraphContext {
+
+ val GenModelProvider genModel
+ val BaseDiagramPositionProvider baseDiagram
+ val Graph graph
+
+ new(AbstractFSMDiagramTypeProvider diagramTypeProvider){
+ this.genModel = diagramTypeProvider.genModelProvider
+ this.baseDiagram = new BaseDiagramPositionProvider(new BaseDiagramProvider(diagramTypeProvider))
+ this.graph = genModel.model.graph
+ }
+
+ new(Graph graph, GenModelStateGraphContext other){
+ this.genModel = other.genModel
+ this.baseDiagram = other.baseDiagram
+ this.graph = graph
+ }
+
+ //
+ // IStateGraphContext
+ //
+
+ override getChPoints() {
+ graph.nodes.map[it.stateGraphNode].filter(ChoicePoint).toList
+ }
+
+ override getChildren() {
+ graph.nodes.filter[it.subgraph != null].map[new GenModelStateGraphContext(it.subgraph, this) as IStateGraphContext].toList
+ }
+
+ override getInitialPoint() {
+ // return a Graph as initial point ?!?
+ if(!graph.links.map[transition].filter(InitialTransition).empty) graph.stateGraph
+ }
+
+ override getParentState() {
+ graph.node.stateGraphNode as State
+ }
+
+ override getPositionProvider() {
+ return baseDiagram
+ }
+
+ override getStateGraph() {
+ graph.stateGraph
+ }
+
+ override getStates() {
+ graph.nodes.map[it.stateGraphNode].filter(State).toList
+ }
+
+ override getTrPoints() {
+ graph.nodes.map[it.stateGraphNode].filter(TrPoint).toList
+ }
+
+ override getTransitions() {
+ graph.links.map[it.transition].filter(Transition).toList
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IStateGraphContext.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IStateGraphContext.java
new file mode 100644
index 000000000..d64a7b946
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IStateGraphContext.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.support;
+
+import java.util.List;
+
+import org.eclipse.etrice.core.fsm.fSM.ChoicePoint;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.core.fsm.fSM.TrPoint;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+
+/**
+ * Interface to change implementation of StateGraphContext (newfsmgen)
+ */
+public interface IStateGraphContext {
+
+ public State getParentState();
+
+ public List<IStateGraphContext> getChildren();
+
+ public List<State> getStates();
+
+ public List<ChoicePoint> getChPoints();
+
+ public StateGraph getStateGraph();
+
+ public List<TrPoint> getTrPoints();
+
+ public List<Transition> getTransitions();
+
+ public IPositionProvider getPositionProvider();
+
+ public StateGraph getInitialPoint();
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java
index 1a8176418..82f573889 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java
@@ -316,7 +316,7 @@ public class StateGraphSupport {
int obsolete = 0;
if (context instanceof StateGraphUpdateContext) {
- StateGraphContext ctx = ((StateGraphUpdateContext)context).getContext();
+ IStateGraphContext ctx = ((StateGraphUpdateContext)context).getContext();
// check for states added in model not present in diagram (including inherited)
{
@@ -403,7 +403,7 @@ public class StateGraphSupport {
StateGraph sg = (StateGraph) bo;
if (context instanceof StateGraphUpdateContext) {
- StateGraphContext ctx = ((StateGraphUpdateContext)context).getContext();
+ IStateGraphContext ctx = ((StateGraphUpdateContext)context).getContext();
DiagramEditingUtil.getInstance().updateStateGraph(sg, ctx, sgShape, fp);
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java
index 82c766c07..578cf77dc 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java
@@ -22,12 +22,12 @@ import org.eclipse.graphiti.mm.pictograms.PictogramElement;
*/
public class StateGraphUpdateContext extends UpdateContext {
- private StateGraphContext context;
+ private IStateGraphContext context;
/**
* @param pictogramElement
*/
- public StateGraphUpdateContext(PictogramElement pe, StateGraphContext ctx) {
+ public StateGraphUpdateContext(PictogramElement pe, IStateGraphContext ctx) {
super(pe);
this.context = ctx;
@@ -36,7 +36,7 @@ public class StateGraphUpdateContext extends UpdateContext {
/**
* @return the context
*/
- public StateGraphContext getContext() {
+ public IStateGraphContext getContext() {
return context;
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java
index bdb254a00..319aa813d 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.fsm.fSM.FSMFactory;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
@@ -158,7 +159,7 @@ public class StateSupport {
ContainerShape targetContainer = context.getTargetContainer();
ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram());
StateGraph sg = (StateGraph) targetContainer.getLink().getBusinessObjects().get(0);
-
+
boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg);
if (inherited) {
sg = ModelEditingUtil.insertRefinedState(sg, ac, targetContainer, getFeatureProvider());
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) {
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.java
new file mode 100644
index 000000000..0c14f1a28
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/BaseDiagramProvider.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.ui.behavior.fsm.provider;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import com.google.inject.Injector;
+import java.util.Collection;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider;
+import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.PictogramLink;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+/**
+ * Provides the {@linkplain PictogramElement} objects of the base class diagram.
+ * This is a reverse mapping from room business objects to linked base diagram pictograms.
+ */
+@SuppressWarnings("all")
+public class BaseDiagramProvider {
+ private final Diagram baseDiagram;
+
+ private final Multimap<EObject, PictogramElement> baseDiagramBusinessObjs = ArrayListMultimap.<EObject, PictogramElement>create();
+
+ public BaseDiagramProvider(final AbstractFSMDiagramTypeProvider diagramTypeProvider) {
+ Injector _injector = diagramTypeProvider.getInjector();
+ final DiagramAccessBase diagramAccess = _injector.<DiagramAccessBase>getInstance(DiagramAccessBase.class);
+ ILinkService _linkService = Graphiti.getLinkService();
+ Diagram _diagram = diagramTypeProvider.getDiagram();
+ EObject _businessObjectForLinkedPictogramElement = _linkService.getBusinessObjectForLinkedPictogramElement(_diagram);
+ final ModelComponent mc = ((ModelComponent) _businessObjectForLinkedPictogramElement);
+ Diagram _diagram_1 = diagramTypeProvider.getDiagram();
+ Resource _eResource = _diagram_1.eResource();
+ final ResourceSet rs = _eResource.getResourceSet();
+ Diagram _xifexpression = null;
+ ModelComponent _base = mc.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ ModelComponent _base_1 = mc.getBase();
+ _xifexpression = diagramAccess.getDiagram(_base_1, rs);
+ }
+ this.baseDiagram = _xifexpression;
+ boolean _notEquals_1 = (!Objects.equal(this.baseDiagram, null));
+ if (_notEquals_1) {
+ Map<EObject, Collection<EStructuralFeature.Setting>> _find = EcoreUtil.ExternalCrossReferencer.find(this.baseDiagram);
+ final BiConsumer<EObject, Collection<EStructuralFeature.Setting>> _function = new BiConsumer<EObject, Collection<EStructuralFeature.Setting>>() {
+ @Override
+ public void accept(final EObject targetEObj, final Collection<EStructuralFeature.Setting> eFeatureSetting) {
+ final Function1<EStructuralFeature.Setting, EObject> _function = new Function1<EStructuralFeature.Setting, EObject>() {
+ @Override
+ public EObject apply(final EStructuralFeature.Setting it) {
+ return it.getEObject();
+ }
+ };
+ Iterable<EObject> _map = IterableExtensions.<EStructuralFeature.Setting, EObject>map(eFeatureSetting, _function);
+ Iterable<PictogramLink> _filter = Iterables.<PictogramLink>filter(_map, PictogramLink.class);
+ final Function1<PictogramLink, PictogramElement> _function_1 = new Function1<PictogramLink, PictogramElement>() {
+ @Override
+ public PictogramElement apply(final PictogramLink it) {
+ return it.getPictogramElement();
+ }
+ };
+ Iterable<PictogramElement> _map_1 = IterableExtensions.<PictogramLink, PictogramElement>map(_filter, _function_1);
+ final Consumer<PictogramElement> _function_2 = new Consumer<PictogramElement>() {
+ @Override
+ public void accept(final PictogramElement pe) {
+ BaseDiagramProvider.this.baseDiagramBusinessObjs.put(targetEObj, pe);
+ }
+ };
+ _map_1.forEach(_function_2);
+ }
+ };
+ _find.forEach(_function);
+ EList<Resource> _resources = rs.getResources();
+ Resource _eResource_1 = this.baseDiagram.eResource();
+ _resources.remove(_eResource_1);
+ }
+ }
+
+ public Collection<PictogramElement> getPictograms(final EObject roomObj) {
+ Collection<PictogramElement> _xifexpression = null;
+ boolean _equals = Objects.equal(roomObj, null);
+ if (_equals) {
+ _xifexpression = CollectionLiterals.<PictogramElement>emptyList();
+ } else {
+ _xifexpression = this.baseDiagramBusinessObjs.get(roomObj);
+ }
+ return _xifexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.java
new file mode 100644
index 000000000..a1364f618
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/provider/GenModelProvider.java
@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.ui.behavior.fsm.provider;
+
+import com.google.common.base.Objects;
+import com.google.inject.Injector;
+import java.util.Map;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.fsm.fSM.TransitionBase;
+import org.eclipse.etrice.core.genmodel.fsm.BasicFsmGenBuilder;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.FSMGenElement;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.IteratorExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@SuppressWarnings("all")
+public class GenModelProvider {
+ private final BasicFsmGenBuilder builder;
+
+ private final IDiagramTypeProvider fsmDiagramProvider;
+
+ private Map<EObject, FSMGenElement> graphMap = CollectionLiterals.<EObject, FSMGenElement>newHashMap();
+
+ private GraphContainer modelInstance = null;
+
+ public GenModelProvider(final AbstractFSMDiagramTypeProvider fsmDiagramProvider) {
+ this.fsmDiagramProvider = fsmDiagramProvider;
+ Injector _injector = fsmDiagramProvider.getInjector();
+ BasicFsmGenBuilder _basicFsmGenBuilder = new BasicFsmGenBuilder(_injector);
+ this.builder = _basicFsmGenBuilder;
+ }
+
+ public void updateModel() {
+ ILinkService _linkService = Graphiti.getLinkService();
+ Diagram _diagram = this.fsmDiagramProvider.getDiagram();
+ EObject _businessObjectForLinkedPictogramElement = _linkService.getBusinessObjectForLinkedPictogramElement(_diagram);
+ final Procedure1<EObject> _function = new Procedure1<EObject>() {
+ @Override
+ public void apply(final EObject it) {
+ GraphContainer _xifexpression = null;
+ if ((it instanceof ModelComponent)) {
+ _xifexpression = GenModelProvider.this.builder.createTransformedModel(((ModelComponent)it));
+ } else {
+ _xifexpression = null;
+ }
+ GenModelProvider.this.modelInstance = _xifexpression;
+ }
+ };
+ ObjectExtensions.<EObject>operator_doubleArrow(_businessObjectForLinkedPictogramElement, _function);
+ boolean _notEquals = (!Objects.equal(this.modelInstance, null));
+ if (_notEquals) {
+ this.graphMap.clear();
+ TreeIterator<EObject> _eAllContents = this.modelInstance.eAllContents();
+ final Procedure1<EObject> _function_1 = new Procedure1<EObject>() {
+ @Override
+ public void apply(final EObject it) {
+ boolean _matched = false;
+ if (it instanceof Graph) {
+ _matched=true;
+ StateGraph _stateGraph = ((Graph)it).getStateGraph();
+ GenModelProvider.this.graphMap.put(_stateGraph, ((FSMGenElement)it));
+ }
+ if (!_matched) {
+ if (it instanceof Node) {
+ _matched=true;
+ StateGraphNode _stateGraphNode = ((Node)it).getStateGraphNode();
+ GenModelProvider.this.graphMap.put(_stateGraphNode, ((FSMGenElement)it));
+ }
+ }
+ if (!_matched) {
+ if (it instanceof Link) {
+ _matched=true;
+ TransitionBase _transition = ((Link)it).getTransition();
+ GenModelProvider.this.graphMap.put(_transition, ((FSMGenElement)it));
+ }
+ }
+ }
+ };
+ IteratorExtensions.<EObject>forEach(_eAllContents, _function_1);
+ }
+ }
+
+ public GraphContainer getModel() {
+ boolean _equals = Objects.equal(this.modelInstance, null);
+ if (_equals) {
+ this.updateModel();
+ }
+ return this.modelInstance;
+ }
+
+ public <T extends FSMGenElement> T getCasted(final EObject roomObj) {
+ FSMGenElement _get = this.graphMap.get(roomObj);
+ return ((T) _get);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.java
new file mode 100644
index 000000000..0cde9a2f5
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramPositionProvider.java
@@ -0,0 +1,386 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.ui.behavior.fsm.support;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.fsm.fSM.InitialTransition;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.fsm.fSM.RefinedState;
+import org.eclipse.etrice.core.fsm.fSM.RefinedTransition;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.fsm.fSM.TrPoint;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.ui.behavior.fsm.provider.BaseDiagramProvider;
+import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider;
+import org.eclipse.etrice.ui.behavior.fsm.support.StateSupport;
+import org.eclipse.etrice.ui.behavior.fsm.support.TrPointSupport;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Point;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+/**
+ * IPositionProvider based on {@linkplain BaseDiagramProvider}
+ * Logic copied from DefaultPositionProvider
+ */
+@FinalFieldsConstructor
+@SuppressWarnings("all")
+public class BaseDiagramPositionProvider implements IPositionProvider {
+ private final BaseDiagramProvider baseDiagram;
+
+ public int getMargin(final StateGraphNode node) {
+ int _switchResult = (int) 0;
+ boolean _matched = false;
+ if (node instanceof State) {
+ _matched=true;
+ _switchResult = StateSupport.MARGIN;
+ }
+ if (!_matched) {
+ if (node instanceof TrPoint) {
+ _matched=true;
+ _switchResult = TrPointSupport.MARGIN;
+ }
+ }
+ if (!_matched) {
+ _switchResult = 0;
+ }
+ return _switchResult;
+ }
+
+ public int getMargin(final StateGraph graph) {
+ return 0;
+ }
+
+ private IPositionProvider.PosAndSize toPosAndSize(final PictogramElement pe, final int margin) {
+ IPositionProvider.PosAndSize _xblockexpression = null;
+ {
+ EObject _eContainer = pe.eContainer();
+ GraphicsAlgorithm _graphicsAlgorithm = ((PictogramElement) _eContainer).getGraphicsAlgorithm();
+ EList<GraphicsAlgorithm> _graphicsAlgorithmChildren = _graphicsAlgorithm.getGraphicsAlgorithmChildren();
+ final GraphicsAlgorithm borderGa = IterableExtensions.<GraphicsAlgorithm>head(_graphicsAlgorithmChildren);
+ final GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ int _x = ga.getX();
+ int _width = borderGa.getWidth();
+ double _divide = (_x / ((double) _width));
+ double _multiply = (_divide * this.sx);
+ final double x = (_multiply + margin);
+ int _y = ga.getY();
+ int _height = borderGa.getHeight();
+ double _divide_1 = (_y / ((double) _height));
+ double _multiply_1 = (_divide_1 * this.sy);
+ final double y = (_multiply_1 + margin);
+ int _width_1 = ga.getWidth();
+ int _minus = (_width_1 - (2 * margin));
+ int _width_2 = borderGa.getWidth();
+ double _divide_2 = (_minus / ((double) _width_2));
+ final double width = (_divide_2 * this.sx);
+ int _height_1 = ga.getHeight();
+ int _minus_1 = (_height_1 - (2 * margin));
+ int _height_2 = borderGa.getHeight();
+ double _divide_3 = (_minus_1 / ((double) _height_2));
+ final double height = (_divide_3 * this.sy);
+ _xblockexpression = new IPositionProvider.PosAndSize(((int) x), ((int) y), ((int) width), ((int) height));
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public IPositionProvider.PosAndSize getGraphPosAndSize(final StateGraph sg) {
+ IPositionProvider.PosAndSize _xblockexpression = null;
+ {
+ Collection<PictogramElement> _pictograms = this.baseDiagram.getPictograms(sg);
+ final Function1<PictogramElement, Boolean> _function = new Function1<PictogramElement, Boolean>() {
+ @Override
+ public Boolean apply(final PictogramElement it) {
+ EObject _parentBo = BaseDiagramPositionProvider.this.getParentBo(it);
+ return Boolean.valueOf((_parentBo instanceof ModelComponent));
+ }
+ };
+ final PictogramElement pe = IterableExtensions.<PictogramElement>findFirst(_pictograms, _function);
+ IPositionProvider.PosAndSize _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(pe, null));
+ if (_notEquals) {
+ IPositionProvider.PosAndSize _xblockexpression_1 = null;
+ {
+ GraphicsAlgorithm _graphicsAlgorithm = pe.getGraphicsAlgorithm();
+ EList<GraphicsAlgorithm> _graphicsAlgorithmChildren = _graphicsAlgorithm.getGraphicsAlgorithmChildren();
+ final GraphicsAlgorithm visibleGa = IterableExtensions.<GraphicsAlgorithm>head(_graphicsAlgorithmChildren);
+ GraphicsAlgorithm _graphicsAlgorithm_1 = pe.getGraphicsAlgorithm();
+ int _x = _graphicsAlgorithm_1.getX();
+ GraphicsAlgorithm _graphicsAlgorithm_2 = pe.getGraphicsAlgorithm();
+ int _y = _graphicsAlgorithm_2.getY();
+ int _width = visibleGa.getWidth();
+ int _height = visibleGa.getHeight();
+ _xblockexpression_1 = new IPositionProvider.PosAndSize(_x, _y, _width, _height);
+ }
+ _xifexpression = _xblockexpression_1;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public List<IPositionProvider.Pos> getPoints(final Transition trans) {
+ ArrayList<IPositionProvider.Pos> _xblockexpression = null;
+ {
+ PictogramElement _xifexpression = null;
+ if ((trans instanceof RefinedTransition)) {
+ Transition _target = ((RefinedTransition)trans).getTarget();
+ Collection<PictogramElement> _pictograms = this.baseDiagram.getPictograms(_target);
+ _xifexpression = IterableExtensions.<PictogramElement>head(_pictograms);
+ } else {
+ Collection<PictogramElement> _pictograms_1 = this.baseDiagram.getPictograms(trans);
+ _xifexpression = IterableExtensions.<PictogramElement>head(_pictograms_1);
+ }
+ final PictogramElement pe = _xifexpression;
+ ArrayList<IPositionProvider.Pos> _newArrayList = CollectionLiterals.<IPositionProvider.Pos>newArrayList();
+ final Procedure1<ArrayList<IPositionProvider.Pos>> _function = new Procedure1<ArrayList<IPositionProvider.Pos>>() {
+ @Override
+ public void apply(final ArrayList<IPositionProvider.Pos> pointList) {
+ if ((pe instanceof Connection)) {
+ EObject _eContainer = trans.eContainer();
+ final IPositionProvider.PosAndSize graphPosAndSize = BaseDiagramPositionProvider.this.getGraphPosAndSize(((StateGraph) _eContainer));
+ EList<ConnectionDecorator> _connectionDecorators = ((Connection)pe).getConnectionDecorators();
+ final Function1<ConnectionDecorator, GraphicsAlgorithm> _function = new Function1<ConnectionDecorator, GraphicsAlgorithm>() {
+ @Override
+ public GraphicsAlgorithm apply(final ConnectionDecorator it) {
+ return it.getGraphicsAlgorithm();
+ }
+ };
+ List<GraphicsAlgorithm> _map = ListExtensions.<ConnectionDecorator, GraphicsAlgorithm>map(_connectionDecorators, _function);
+ Iterable<Text> _filter = Iterables.<Text>filter(_map, Text.class);
+ final Text text = IterableExtensions.<Text>head(_filter);
+ boolean _notEquals = (!Objects.equal(text, null));
+ if (_notEquals) {
+ int _x = text.getX();
+ int _width = graphPosAndSize.getWidth();
+ double _divide = (_x / ((double) _width));
+ double _multiply = (_divide * BaseDiagramPositionProvider.this.sx);
+ int _y = text.getY();
+ int _height = graphPosAndSize.getHeight();
+ double _divide_1 = (_y / ((double) _height));
+ double _multiply_1 = (_divide_1 * BaseDiagramPositionProvider.this.sy);
+ IPositionProvider.Pos _pos = new IPositionProvider.Pos(
+ ((int) _multiply),
+ ((int) _multiply_1));
+ pointList.add(_pos);
+ if ((pe instanceof FreeFormConnection)) {
+ EList<Point> _bendpoints = ((FreeFormConnection)pe).getBendpoints();
+ final Function1<Point, IPositionProvider.Pos> _function_1 = new Function1<Point, IPositionProvider.Pos>() {
+ @Override
+ public IPositionProvider.Pos apply(final Point it) {
+ int _x = text.getX();
+ int _width = graphPosAndSize.getWidth();
+ double _divide = (_x / ((double) _width));
+ double _multiply = (_divide * BaseDiagramPositionProvider.this.sx);
+ double _plus = (_multiply + BaseDiagramPositionProvider.this.x);
+ int _y = text.getY();
+ int _height = graphPosAndSize.getHeight();
+ double _divide_1 = (_y / ((double) _height));
+ double _multiply_1 = (_divide_1 * BaseDiagramPositionProvider.this.sy);
+ double _plus_1 = (_multiply_1 + BaseDiagramPositionProvider.this.y);
+ return new IPositionProvider.Pos(
+ ((int) _plus),
+ ((int) _plus_1));
+ }
+ };
+ List<IPositionProvider.Pos> _map_1 = ListExtensions.<Point, IPositionProvider.Pos>map(_bendpoints, _function_1);
+ Iterables.<IPositionProvider.Pos>addAll(pointList, _map_1);
+ }
+ }
+ }
+ }
+ };
+ _xblockexpression = ObjectExtensions.<ArrayList<IPositionProvider.Pos>>operator_doubleArrow(_newArrayList, _function);
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public IPositionProvider.PosAndSize getPosition(final StateGraphNode node) {
+ IPositionProvider.PosAndSize _xifexpression = null;
+ if ((node instanceof RefinedState)) {
+ State _target = ((RefinedState)node).getTarget();
+ Collection<PictogramElement> _pictograms = this.baseDiagram.getPictograms(_target);
+ final Function1<PictogramElement, Boolean> _function = new Function1<PictogramElement, Boolean>() {
+ @Override
+ public Boolean apply(final PictogramElement it) {
+ EObject _parentBo = BaseDiagramPositionProvider.this.getParentBo(it);
+ return Boolean.valueOf((_parentBo instanceof StateGraph));
+ }
+ };
+ PictogramElement _findFirst = IterableExtensions.<PictogramElement>findFirst(_pictograms, _function);
+ IPositionProvider.PosAndSize _posAndSize = null;
+ if (_findFirst!=null) {
+ int _margin = this.getMargin(node);
+ _posAndSize=this.toPosAndSize(_findFirst, _margin);
+ }
+ _xifexpression = _posAndSize;
+ } else {
+ Collection<PictogramElement> _pictograms_1 = this.baseDiagram.getPictograms(node);
+ final Function1<PictogramElement, Boolean> _function_1 = new Function1<PictogramElement, Boolean>() {
+ @Override
+ public Boolean apply(final PictogramElement it) {
+ EObject _parentBo = BaseDiagramPositionProvider.this.getParentBo(it);
+ return Boolean.valueOf((_parentBo instanceof StateGraph));
+ }
+ };
+ PictogramElement _findFirst_1 = IterableExtensions.<PictogramElement>findFirst(_pictograms_1, _function_1);
+ IPositionProvider.PosAndSize _posAndSize_1 = null;
+ if (_findFirst_1!=null) {
+ int _margin_1 = this.getMargin(node);
+ _posAndSize_1=this.toPosAndSize(_findFirst_1, _margin_1);
+ }
+ _xifexpression = _posAndSize_1;
+ }
+ return _xifexpression;
+ }
+
+ @Override
+ public StateGraph getInitialPoint(final StateGraph stateGraph) {
+ EList<Transition> _transitions = stateGraph.getTransitions();
+ Iterable<InitialTransition> _filter = Iterables.<InitialTransition>filter(_transitions, InitialTransition.class);
+ InitialTransition _head = IterableExtensions.<InitialTransition>head(_filter);
+ Collection<PictogramElement> _pictograms = this.baseDiagram.getPictograms(_head);
+ final PictogramElement initTransPe = IterableExtensions.<PictogramElement>head(_pictograms);
+ if ((initTransPe instanceof Connection)) {
+ ILinkService _linkService = Graphiti.getLinkService();
+ Anchor _start = ((Connection)initTransPe).getStart();
+ final EObject sourceAnchorBo = _linkService.getBusinessObjectForLinkedPictogramElement(_start);
+ if ((sourceAnchorBo instanceof StateGraph)) {
+ return ((StateGraph)sourceAnchorBo);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public IPositionProvider.PosAndSize getPosition(final StateGraph graph) {
+ Collection<PictogramElement> _pictograms = this.baseDiagram.getPictograms(graph);
+ final Function1<PictogramElement, Boolean> _function = new Function1<PictogramElement, Boolean>() {
+ @Override
+ public Boolean apply(final PictogramElement it) {
+ EObject _parentBo = BaseDiagramPositionProvider.this.getParentBo(it);
+ return Boolean.valueOf((_parentBo instanceof StateGraph));
+ }
+ };
+ PictogramElement _findFirst = IterableExtensions.<PictogramElement>findFirst(_pictograms, _function);
+ IPositionProvider.PosAndSize _posAndSize = null;
+ if (_findFirst!=null) {
+ int _margin = this.getMargin(graph);
+ _posAndSize=this.toPosAndSize(_findFirst, _margin);
+ }
+ return _posAndSize;
+ }
+
+ @Override
+ public <T extends StateGraphNode> List<IPositionProvider.PosAndSize> getPositions(final List<T> items) {
+ final Function1<T, IPositionProvider.PosAndSize> _function = new Function1<T, IPositionProvider.PosAndSize>() {
+ @Override
+ public IPositionProvider.PosAndSize apply(final T it) {
+ Collection<PictogramElement> _pictograms = BaseDiagramPositionProvider.this.baseDiagram.getPictograms(it);
+ PictogramElement _head = IterableExtensions.<PictogramElement>head(_pictograms);
+ IPositionProvider.PosAndSize _posAndSize = null;
+ if (_head!=null) {
+ int _margin = BaseDiagramPositionProvider.this.getMargin(it);
+ _posAndSize=BaseDiagramPositionProvider.this.toPosAndSize(_head, _margin);
+ }
+ return _posAndSize;
+ }
+ };
+ return ListExtensions.<T, IPositionProvider.PosAndSize>map(items, _function);
+ }
+
+ @Override
+ public double[] getSubPosition(final StateGraphNode subNode) {
+ Collection<PictogramElement> _pictograms = this.baseDiagram.getPictograms(subNode);
+ final Function1<PictogramElement, Boolean> _function = new Function1<PictogramElement, Boolean>() {
+ @Override
+ public Boolean apply(final PictogramElement it) {
+ EObject _parentBo = BaseDiagramPositionProvider.this.getParentBo(it);
+ return Boolean.valueOf((_parentBo instanceof State));
+ }
+ };
+ final PictogramElement pe = IterableExtensions.<PictogramElement>findFirst(_pictograms, _function);
+ boolean _notEquals = (!Objects.equal(pe, null));
+ if (_notEquals) {
+ EObject _eContainer = pe.eContainer();
+ final PictogramElement parentPe = ((PictogramElement) _eContainer);
+ GraphicsAlgorithm _graphicsAlgorithm = pe.getGraphicsAlgorithm();
+ int _x = _graphicsAlgorithm.getX();
+ GraphicsAlgorithm _graphicsAlgorithm_1 = parentPe.getGraphicsAlgorithm();
+ int _width = _graphicsAlgorithm_1.getWidth();
+ int _minus = (_width - (2 * StateSupport.MARGIN));
+ final double relX = (((double) _x) / _minus);
+ GraphicsAlgorithm _graphicsAlgorithm_2 = pe.getGraphicsAlgorithm();
+ int _y = _graphicsAlgorithm_2.getY();
+ GraphicsAlgorithm _graphicsAlgorithm_3 = parentPe.getGraphicsAlgorithm();
+ int _height = _graphicsAlgorithm_3.getHeight();
+ int _minus_1 = (_height - (2 * StateSupport.MARGIN));
+ final double relY = (((double) _y) / _minus_1);
+ return new double[] { relX, relY };
+ }
+ return null;
+ }
+
+ private int x;
+
+ private int y;
+
+ @Override
+ public void setPosition(final int x, final int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ private double sx;
+
+ private double sy;
+
+ @Override
+ public void setScale(final double sx, final double sy) {
+ this.sx = sx;
+ this.sy = sy;
+ }
+
+ private EObject getParentBo(final PictogramElement pe) {
+ ILinkService _linkService = Graphiti.getLinkService();
+ EObject _eContainer = pe.eContainer();
+ return _linkService.getBusinessObjectForLinkedPictogramElement(((PictogramElement) _eContainer));
+ }
+
+ public BaseDiagramPositionProvider(final BaseDiagramProvider baseDiagram) {
+ super();
+ this.baseDiagram = baseDiagram;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.java
new file mode 100644
index 000000000..bd075bba4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/BaseDiagramProvider.java
@@ -0,0 +1,151 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.ui.behavior.fsm.support;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Injector;
+import java.util.Collection;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider;
+import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.PictogramLink;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+/**
+ * Provides the {@linkplain PictogramElement} objects of the base class diagram.
+ * This is a reverse 1:1 mapping from room business objects to linked base diagram pictograms.
+ */
+@SuppressWarnings("all")
+public class BaseDiagramProvider {
+ private final DiagramAccessBase diagramAccess;
+
+ private final Map<EObject, PictogramElement> baseGraphElement = CollectionLiterals.<EObject, PictogramElement>newHashMap();
+
+ private final Map<EObject, PictogramElement> baseStateElement = CollectionLiterals.<EObject, PictogramElement>newHashMap();
+
+ private final Map<EObject, PictogramElement> initialPointElement = CollectionLiterals.<EObject, PictogramElement>newHashMap();
+
+ public BaseDiagramProvider(final AbstractFSMDiagramTypeProvider diagramTypeProvider) {
+ Injector _injector = diagramTypeProvider.getInjector();
+ DiagramAccessBase _instance = _injector.<DiagramAccessBase>getInstance(DiagramAccessBase.class);
+ this.diagramAccess = _instance;
+ ILinkService _linkService = Graphiti.getLinkService();
+ Diagram _diagram = diagramTypeProvider.getDiagram();
+ EObject _businessObjectForLinkedPictogramElement = _linkService.getBusinessObjectForLinkedPictogramElement(_diagram);
+ final ModelComponent mc = ((ModelComponent) _businessObjectForLinkedPictogramElement);
+ Diagram _diagram_1 = diagramTypeProvider.getDiagram();
+ Resource _eResource = _diagram_1.eResource();
+ final ResourceSet rs = _eResource.getResourceSet();
+ ModelComponent _base = mc.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ ModelComponent _base_1 = mc.getBase();
+ final Diagram baseDiagram = this.diagramAccess.getDiagram(_base_1, rs);
+ boolean _notEquals_1 = (!Objects.equal(baseDiagram, null));
+ if (_notEquals_1) {
+ this.mapPositions(baseDiagram);
+ EList<Resource> _resources = rs.getResources();
+ Resource _eResource_1 = baseDiagram.eResource();
+ _resources.remove(_eResource_1);
+ }
+ }
+ }
+
+ public void mapPositions(final Diagram diagram) {
+ Map<EObject, Collection<EStructuralFeature.Setting>> _find = EcoreUtil.ExternalCrossReferencer.find(diagram);
+ final BiConsumer<EObject, Collection<EStructuralFeature.Setting>> _function = new BiConsumer<EObject, Collection<EStructuralFeature.Setting>>() {
+ @Override
+ public void accept(final EObject targetEObj, final Collection<EStructuralFeature.Setting> eFeatureSetting) {
+ final Function1<EStructuralFeature.Setting, EObject> _function = new Function1<EStructuralFeature.Setting, EObject>() {
+ @Override
+ public EObject apply(final EStructuralFeature.Setting it) {
+ return it.getEObject();
+ }
+ };
+ Iterable<EObject> _map = IterableExtensions.<EStructuralFeature.Setting, EObject>map(eFeatureSetting, _function);
+ Iterable<PictogramLink> _filter = Iterables.<PictogramLink>filter(_map, PictogramLink.class);
+ final Function1<PictogramLink, PictogramElement> _function_1 = new Function1<PictogramLink, PictogramElement>() {
+ @Override
+ public PictogramElement apply(final PictogramLink it) {
+ return it.getPictogramElement();
+ }
+ };
+ Iterable<PictogramElement> _map_1 = IterableExtensions.<PictogramLink, PictogramElement>map(_filter, _function_1);
+ final Consumer<PictogramElement> _function_2 = new Consumer<PictogramElement>() {
+ @Override
+ public void accept(final PictogramElement pe) {
+ ILinkService _linkService = Graphiti.getLinkService();
+ EObject _eContainer = pe.eContainer();
+ EObject _businessObjectForLinkedPictogramElement = _linkService.getBusinessObjectForLinkedPictogramElement(((PictogramElement) _eContainer));
+ final boolean isState = (_businessObjectForLinkedPictogramElement instanceof State);
+ final boolean isInitialPoint = ((targetEObj instanceof StateGraph) && (!(pe.eContainer() instanceof Diagram)));
+ if (isState) {
+ BaseDiagramProvider.this.baseStateElement.put(targetEObj, pe);
+ } else {
+ if (isInitialPoint) {
+ BaseDiagramProvider.this.initialPointElement.put(targetEObj, pe);
+ } else {
+ BaseDiagramProvider.this.baseGraphElement.put(targetEObj, pe);
+ }
+ }
+ }
+ };
+ _map_1.forEach(_function_2);
+ }
+ };
+ _find.forEach(_function);
+ }
+
+ public PictogramElement getBaseGraphPictogram(final EObject roomObj) {
+ PictogramElement _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(roomObj, null));
+ if (_notEquals) {
+ _xifexpression = this.baseGraphElement.get(roomObj);
+ }
+ return _xifexpression;
+ }
+
+ public PictogramElement getBaseStatePictogram(final EObject roomObj) {
+ PictogramElement _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(roomObj, null));
+ if (_notEquals) {
+ _xifexpression = this.baseStateElement.get(roomObj);
+ }
+ return _xifexpression;
+ }
+
+ public PictogramElement getInitialPointPictogram(final EObject roomObj) {
+ PictogramElement _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(roomObj, null));
+ if (_notEquals) {
+ _xifexpression = this.initialPointElement.get(roomObj);
+ }
+ return _xifexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.java
new file mode 100644
index 000000000..c79d40e8b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/GenModelStateGraphContext.java
@@ -0,0 +1,182 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.ui.behavior.fsm.support;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.fsm.fSM.ChoicePoint;
+import org.eclipse.etrice.core.fsm.fSM.InitialTransition;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.fsm.fSM.TrPoint;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.core.fsm.fSM.TransitionBase;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
+import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMDiagramTypeProvider;
+import org.eclipse.etrice.ui.behavior.fsm.provider.BaseDiagramProvider;
+import org.eclipse.etrice.ui.behavior.fsm.provider.GenModelProvider;
+import org.eclipse.etrice.ui.behavior.fsm.support.BaseDiagramPositionProvider;
+import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider;
+import org.eclipse.etrice.ui.behavior.fsm.support.IStateGraphContext;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+
+/**
+ * StateGraphContext based on newfsmgen.
+ */
+@SuppressWarnings("all")
+public class GenModelStateGraphContext implements IStateGraphContext {
+ private final GenModelProvider genModel;
+
+ private final BaseDiagramPositionProvider baseDiagram;
+
+ private final Graph graph;
+
+ public GenModelStateGraphContext(final AbstractFSMDiagramTypeProvider diagramTypeProvider) {
+ GenModelProvider _genModelProvider = diagramTypeProvider.getGenModelProvider();
+ this.genModel = _genModelProvider;
+ BaseDiagramProvider _baseDiagramProvider = new BaseDiagramProvider(diagramTypeProvider);
+ BaseDiagramPositionProvider _baseDiagramPositionProvider = new BaseDiagramPositionProvider(_baseDiagramProvider);
+ this.baseDiagram = _baseDiagramPositionProvider;
+ GraphContainer _model = this.genModel.getModel();
+ Graph _graph = _model.getGraph();
+ this.graph = _graph;
+ }
+
+ public GenModelStateGraphContext(final Graph graph, final GenModelStateGraphContext other) {
+ this.genModel = other.genModel;
+ this.baseDiagram = other.baseDiagram;
+ this.graph = graph;
+ }
+
+ @Override
+ public List<ChoicePoint> getChPoints() {
+ EList<Node> _nodes = this.graph.getNodes();
+ final Function1<Node, StateGraphNode> _function = new Function1<Node, StateGraphNode>() {
+ @Override
+ public StateGraphNode apply(final Node it) {
+ return it.getStateGraphNode();
+ }
+ };
+ List<StateGraphNode> _map = ListExtensions.<Node, StateGraphNode>map(_nodes, _function);
+ Iterable<ChoicePoint> _filter = Iterables.<ChoicePoint>filter(_map, ChoicePoint.class);
+ return IterableExtensions.<ChoicePoint>toList(_filter);
+ }
+
+ @Override
+ public List<IStateGraphContext> getChildren() {
+ EList<Node> _nodes = this.graph.getNodes();
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ Graph _subgraph = it.getSubgraph();
+ return Boolean.valueOf((!Objects.equal(_subgraph, null)));
+ }
+ };
+ Iterable<Node> _filter = IterableExtensions.<Node>filter(_nodes, _function);
+ final Function1<Node, IStateGraphContext> _function_1 = new Function1<Node, IStateGraphContext>() {
+ @Override
+ public IStateGraphContext apply(final Node it) {
+ Graph _subgraph = it.getSubgraph();
+ GenModelStateGraphContext _genModelStateGraphContext = new GenModelStateGraphContext(_subgraph, GenModelStateGraphContext.this);
+ return ((IStateGraphContext) _genModelStateGraphContext);
+ }
+ };
+ Iterable<IStateGraphContext> _map = IterableExtensions.<Node, IStateGraphContext>map(_filter, _function_1);
+ return IterableExtensions.<IStateGraphContext>toList(_map);
+ }
+
+ @Override
+ public StateGraph getInitialPoint() {
+ StateGraph _xifexpression = null;
+ EList<Link> _links = this.graph.getLinks();
+ final Function1<Link, TransitionBase> _function = new Function1<Link, TransitionBase>() {
+ @Override
+ public TransitionBase apply(final Link it) {
+ return it.getTransition();
+ }
+ };
+ List<TransitionBase> _map = ListExtensions.<Link, TransitionBase>map(_links, _function);
+ Iterable<InitialTransition> _filter = Iterables.<InitialTransition>filter(_map, InitialTransition.class);
+ boolean _isEmpty = IterableExtensions.isEmpty(_filter);
+ boolean _not = (!_isEmpty);
+ if (_not) {
+ _xifexpression = this.graph.getStateGraph();
+ }
+ return _xifexpression;
+ }
+
+ @Override
+ public State getParentState() {
+ Node _node = this.graph.getNode();
+ StateGraphNode _stateGraphNode = _node.getStateGraphNode();
+ return ((State) _stateGraphNode);
+ }
+
+ @Override
+ public IPositionProvider getPositionProvider() {
+ return this.baseDiagram;
+ }
+
+ @Override
+ public StateGraph getStateGraph() {
+ return this.graph.getStateGraph();
+ }
+
+ @Override
+ public List<State> getStates() {
+ EList<Node> _nodes = this.graph.getNodes();
+ final Function1<Node, StateGraphNode> _function = new Function1<Node, StateGraphNode>() {
+ @Override
+ public StateGraphNode apply(final Node it) {
+ return it.getStateGraphNode();
+ }
+ };
+ List<StateGraphNode> _map = ListExtensions.<Node, StateGraphNode>map(_nodes, _function);
+ Iterable<State> _filter = Iterables.<State>filter(_map, State.class);
+ return IterableExtensions.<State>toList(_filter);
+ }
+
+ @Override
+ public List<TrPoint> getTrPoints() {
+ EList<Node> _nodes = this.graph.getNodes();
+ final Function1<Node, StateGraphNode> _function = new Function1<Node, StateGraphNode>() {
+ @Override
+ public StateGraphNode apply(final Node it) {
+ return it.getStateGraphNode();
+ }
+ };
+ List<StateGraphNode> _map = ListExtensions.<Node, StateGraphNode>map(_nodes, _function);
+ Iterable<TrPoint> _filter = Iterables.<TrPoint>filter(_map, TrPoint.class);
+ return IterableExtensions.<TrPoint>toList(_filter);
+ }
+
+ @Override
+ public List<Transition> getTransitions() {
+ EList<Link> _links = this.graph.getLinks();
+ final Function1<Link, TransitionBase> _function = new Function1<Link, TransitionBase>() {
+ @Override
+ public TransitionBase apply(final Link it) {
+ return it.getTransition();
+ }
+ };
+ List<TransitionBase> _map = ListExtensions.<Link, TransitionBase>map(_links, _function);
+ Iterable<Transition> _filter = Iterables.<Transition>filter(_map, Transition.class);
+ return IterableExtensions.<Transition>toList(_filter);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramExtensions.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramExtensions.java
new file mode 100644
index 000000000..bb3e077d6
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/xtend-gen/org/eclipse/etrice/ui/behavior/fsm/support/util/DiagramExtensions.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.ui.behavior.fsm.support.util;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.ILinkService;
+
+@SuppressWarnings("all")
+public class DiagramExtensions {
+ public static <T extends PictogramElement> T getCastedPe(final IPictogramElementContext ctx) {
+ PictogramElement _pictogramElement = ctx.getPictogramElement();
+ return ((T) _pictogramElement);
+ }
+
+ public static <T extends EObject> T getCastedBo(final PictogramElement pe) {
+ ILinkService _linkService = Graphiti.getLinkService();
+ EObject _businessObjectForLinkedPictogramElement = _linkService.getBusinessObjectForLinkedPictogramElement(pe);
+ return ((T) _businessObjectForLinkedPictogramElement);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ProviderDispatcher.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ProviderDispatcher.java
deleted file mode 100644
index 340298044..000000000
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ProviderDispatcher.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.behavior.support;
-
-import org.eclipse.etrice.ui.behavior.Activator;
-import org.eclipse.etrice.ui.behavior.fsm.support.AbstractFSMProviderDispatcher;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-
-import com.google.inject.Injector;
-
-/**
- * @author Henrik Rentz-Reichert
- *
- */
-public class ProviderDispatcher extends AbstractFSMProviderDispatcher {
-
-
- /**
- * @param dtp
- */
- public ProviderDispatcher(IDiagramTypeProvider dtp) {
- super(dtp);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.etrice.ui.behavior.fsm.provider.IInjectorProvider#getInjector()
- */
- @Override
- public Injector getInjector() {
- return Activator.getDefault().getInjector();
- }
-
-}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
index ea44ea81b..57cfc9422 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java
@@ -57,26 +57,23 @@ public abstract class DiagramAccessBase {
@Inject
private IResourceSetProvider resourceSetProvider;
- /**
- *
- */
public DiagramAccessBase() {
super();
injectMembers();
}
+ /**
+ * Load diagram based on rootObjects resource URI
+ */
public Diagram getDiagram(EObject rootObject){
- Resource resource = rootObject.eResource();
- if (resource==null)
- return null;
-
- URI uri = resource.getURI();
-
- ResourceSet rs = newResourceSet(uri);
+ ResourceSet rs = newResourceSet(EcoreUtil.getURI(rootObject));
return getDiagram(rootObject, rs);
}
+ /**
+ * Load diagram based on rootObjects resource URI into given resourceSet
+ */
public Diagram getDiagram(EObject rootObject, ResourceSet rs) {
Resource resource = rootObject.eResource();
if (resource==null)
@@ -152,33 +149,34 @@ public abstract class DiagramAccessBase {
}
private ResourceSet newResourceSet(URI uri) {
- ResourceSet rs;
if (uri.isPlatformResource()) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
IProject project = file.getProject();
- rs = resourceSetProvider.get(project);
+ return resourceSetProvider.get(project);
}
- else {
- rs = new XtextResourceSet();
- }
- return rs;
+
+ return new XtextResourceSet();
}
private void populateDiagram(EObject rootObject, Diagram diagram) {
- ResourceSet rs = newResourceSet(rootObject.eResource().getURI());
+ ResourceSet rs = diagram.eResource().getResourceSet();
+
+ // IMPORTANT STEP: this resolves the object and creates a new resource in the resource set
+ URI boUri = EcoreUtil.getURI(rootObject);
+ rootObject = rs.getEObject(boUri, true);
+ boolean editingDomainOwner = false;
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(rs);
if (editingDomain == null) {
// Not yet existing, create one
editingDomain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(rs);
+ editingDomainOwner = true;
}
-
- // IMPORTANT STEP: this resolves the object and creates a new resource in the resource set
- URI boUri = EcoreUtil.getURI(rootObject);
- rootObject = editingDomain.getResourceSet().getEObject(boUri, true);
editingDomain.getCommandStack().execute(getInitialCommand(rootObject, diagram, editingDomain));
- editingDomain.dispose();
+ if(editingDomainOwner){
+ editingDomain.dispose();
+ }
}
/**
@@ -186,11 +184,13 @@ public abstract class DiagramAccessBase {
*/
private void updateDiagram(Diagram diagram, boolean doSave) {
ResourceSet rs = diagram.eResource().getResourceSet();
+ boolean editingDomainOwner = false;
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(rs);
try {
if (editingDomain == null) {
// Not yet existing, create one and start a write transaction
editingDomain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(rs);
+ editingDomainOwner = true;
((TransactionalEditingDomainImpl)editingDomain).startTransaction(false, null);
}
@@ -210,7 +210,9 @@ public abstract class DiagramAccessBase {
catch (InterruptedException e) {
}
- editingDomain.dispose();
+ if(editingDomainOwner){
+ editingDomain.dispose();
+ }
}
public DiagramEditorBase findDiagramEditor(EObject rootObject) {

Back to the top