1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/**
* 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 com.google.common.base.Objects;
import java.util.HashMap;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.fsm.fSM.FSMFactory;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.fSM.RefinedState;
import org.eclipse.etrice.core.fsm.fSM.State;
import org.eclipse.etrice.core.fsm.fSM.StateGraph;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
/**
* Shared model editing
*/
@SuppressWarnings("all")
public class ModelEditingUtil {
public static RefinedState getOrCreateRefinedStateFor(final State s, final ModelComponent mc) {
final HashMap<State, RefinedState> target2rs = new HashMap<State, RefinedState>();
StateGraph _stateMachine = mc.getStateMachine();
EList<State> _states = _stateMachine.getStates();
for (final State st : _states) {
if ((st instanceof RefinedState)) {
State _target = ((RefinedState) st).getTarget();
target2rs.put(_target, ((RefinedState) st));
}
}
RefinedState rs = null;
boolean _containsKey = target2rs.containsKey(s);
if (_containsKey) {
RefinedState _get = target2rs.get(s);
rs = _get;
} else {
StateGraph sg = null;
State parent = s;
boolean break_ = false;
while (((parent.eContainer().eContainer() instanceof State) && (!break_))) {
{
EObject _eContainer = s.eContainer();
EObject _eContainer_1 = _eContainer.eContainer();
parent = ((State) _eContainer_1);
boolean _containsKey_1 = target2rs.containsKey(parent);
if (_containsKey_1) {
final RefinedState bestFitting = target2rs.get(parent);
StateGraph _subgraph = bestFitting.getSubgraph();
boolean _equals = Objects.equal(_subgraph, null);
if (_equals) {
StateGraph _createStateGraph = FSMFactory.eINSTANCE.createStateGraph();
bestFitting.setSubgraph(_createStateGraph);
}
StateGraph _subgraph_1 = bestFitting.getSubgraph();
sg = _subgraph_1;
break_ = true;
}
}
}
boolean _equals = Objects.equal(sg, null);
if (_equals) {
StateGraph _stateMachine_1 = mc.getStateMachine();
sg = _stateMachine_1;
}
RefinedState _createRefinedState = FSMFactory.eINSTANCE.createRefinedState();
rs = _createRefinedState;
rs.setTarget(s);
EList<State> _states_1 = sg.getStates();
_states_1.add(rs);
}
return rs;
}
public static StateGraph getOrCreateSubGraphOfRefinedStateFor(final State s, final ModelComponent mc) {
final RefinedState rs = ModelEditingUtil.getOrCreateRefinedStateFor(s, mc);
StateGraph _subgraph = rs.getSubgraph();
boolean _equals = Objects.equal(_subgraph, null);
if (_equals) {
StateGraph _createStateGraph = FSMFactory.eINSTANCE.createStateGraph();
rs.setSubgraph(_createStateGraph);
}
return rs.getSubgraph();
}
public static StateGraph insertRefinedState(final StateGraph sg, final ModelComponent mc, final ContainerShape targetContainer, final IFeatureProvider fp) {
EObject _eContainer = sg.eContainer();
final StateGraph sg2 = ModelEditingUtil.getOrCreateSubGraphOfRefinedStateFor(((State) _eContainer), mc);
fp.link(targetContainer, sg2);
return sg2;
}
}
|