| /** |
| * 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 = (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 = (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 = (Node it) -> { |
| Graph _subgraph = it.getSubgraph(); |
| GenModelStateGraphContext _genModelStateGraphContext = new GenModelStateGraphContext(_subgraph, 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 = (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 = (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 = (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 = (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); |
| } |
| } |