use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.
the class FactoryUtils method createStatechartModel.
/**
* Creates a Statechart with an initial Region and an initial State
*
* @return instanceof {@link Statechart}
*/
public static void createStatechartModel(Resource resource, PreferencesHint preferencesHint) {
// Create a statechart
Statechart statechart = SGraphFactory.eINSTANCE.createStatechart();
String lastSegment = resource.getURI().lastSegment();
String statechartName = lastSegment.substring(0, lastSegment.indexOf('.'));
statechart.setName(statechartName);
statechart.setSpecification(INITIAL_SPECIFICATION);
Diagram diagram = ViewService.createDiagram(statechart, StatechartDiagramEditor.ID, preferencesHint);
diagram.setElement(statechart);
// Add to resource
resource.getContents().add(statechart);
resource.getContents().add(diagram);
// Create an initial region
Region region = SGraphFactory.eINSTANCE.createRegion();
region.setName(INITIAL_REGION_NAME);
statechart.getRegions().add(region);
Node regionView = ViewService.createNode(diagram, region, SemanticHints.REGION, preferencesHint);
setRegionViewLayoutConstraint(regionView);
// // Create an initial state
Entry initialState = SGraphFactory.eINSTANCE.createEntry();
initialState.setKind(EntryKind.INITIAL);
region.getVertices().add(initialState);
Node initialStateView = ViewService.createNode(getRegionCompartmentView(regionView), initialState, SemanticHints.ENTRY, preferencesHint);
setInitialStateViewLayoutConstraint(initialStateView);
// Create the first state
State state = SGraphFactory.eINSTANCE.createState();
state.setName("StateA");
region.getVertices().add(state);
Node stateNode = ViewService.createNode(getRegionCompartmentView(regionView), state, SemanticHints.STATE, preferencesHint);
setStateViewLayoutConstraint(stateNode);
// Create the transition from Initial State to State
Transition transition = SGraphFactory.eINSTANCE.createTransition();
transition.setSource(initialState);
transition.setTarget(state);
initialState.getOutgoingTransitions().add(transition);
ViewService.createEdge(initialStateView, stateNode, transition, SemanticHints.TRANSITION, preferencesHint);
// Create the textcompartment for events / variables
Node textCompartment = ViewService.createNode(diagram, statechart, SemanticHints.STATECHART_TEXT, preferencesHint);
setTextCompartmentLayoutConstraint(textCompartment);
}
use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.
the class RegionCompartmentCanonicalEditPolicy method getSourceElement.
@Override
protected EObject getSourceElement(EObject relationship) {
Assert.isTrue(relationship instanceof Transition);
Transition transition = (Transition) relationship;
return transition.getSource();
}
use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.
the class RegionCompartmentCanonicalEditPolicy method getSemanticConnectionsList.
@Override
protected List getSemanticConnectionsList() {
List<Transition> transitions = Lists.newArrayList();
EList<Vertex> vertices = getSemanticHost().getVertices();
for (Vertex vertex : vertices) {
transitions.addAll(vertex.getOutgoingTransitions());
}
return transitions;
}
use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.
the class RegionCompartmentCanonicalEditPolicy method getTargetElement.
@Override
protected EObject getTargetElement(EObject relationship) {
Assert.isTrue(relationship instanceof Transition);
Transition transition = (Transition) relationship;
return transition.getTarget();
}
use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.
the class TransitionsWithNoTriggerTest method noTriggerOnSyncIncoming.
/**
* If a sync node has multiple incoming transitions then the transitions can omit the trigger.
*/
@Test
public void noTriggerOnSyncIncoming() {
statechart = loadStatechart("ValidEmptyTransitionFromSync.sct");
Region validRegion = firstNamed(eAllOfType(statechart, Region.class), "valid");
Synchronization sync = eAllOfType(validRegion, Synchronization.class).get(0);
for (Transition t : sync.getIncomingTransitions()) {
assertTrue(validate(t));
assertIssueCount(diagnostics, 0);
}
}
Aggregations