Search in sources :

Example 46 with Transition

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);
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) State(org.yakindu.sct.model.sgraph.State) Node(org.eclipse.gmf.runtime.notation.Node) DecorationNode(org.eclipse.gmf.runtime.notation.DecorationNode) Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) Region(org.yakindu.sct.model.sgraph.Region) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 47 with Transition

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();
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition)

Example 48 with Transition

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;
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Transition(org.yakindu.sct.model.sgraph.Transition)

Example 49 with Transition

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();
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition)

Example 50 with Transition

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);
    }
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) Synchronization(org.yakindu.sct.model.sgraph.Synchronization) Test(org.junit.Test)

Aggregations

Transition (org.yakindu.sct.model.sgraph.Transition)63 Test (org.junit.Test)34 Region (org.yakindu.sct.model.sgraph.Region)26 State (org.yakindu.sct.model.sgraph.State)23 Statechart (org.yakindu.sct.model.sgraph.Statechart)19 FinalState (org.yakindu.sct.model.sgraph.FinalState)13 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)13 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)13 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)13 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)13 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)10 Entry (org.yakindu.sct.model.sgraph.Entry)10 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)10 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)9 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)8 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)8 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)8 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)7 If (org.yakindu.sct.model.sexec.If)7 Vertex (org.yakindu.sct.model.sgraph.Vertex)7