Search in sources :

Example 86 with State

use of org.yakindu.sct.model.sgraph.State in project statecharts by Yakindu.

the class StateTemplatesModification method execute.

@SuppressWarnings("unchecked")
@Override
protected void execute(EObject semanticObject, View view) {
    State state = (State) semanticObject;
    Resource resource = loadTemplateResource(getTemplatePath());
    Diagram diagram = (Diagram) getObjectByType(resource.getContents(), NotationPackage.Literals.DIAGRAM);
    EList<View> children = diagram.getChildren();
    List<Node> regions = new ArrayList<Node>();
    for (View child : children) {
        if (child.getType().equals(SemanticHints.REGION)) {
            regions.add((Node) child);
        }
    }
    View figureCompartment = ViewUtil.getChildBySemanticHint(view, SemanticHints.STATE_FIGURE_COMPARTMENT);
    while (regions.size() > 0) {
        Node child = regions.get(0);
        regions.remove(child);
        setPreferredSize(child);
        figureCompartment.insertChild(child);
        state.getRegions().add((Region) child.getElement());
    }
    EList<Edge> edges = diagram.getEdges();
    while (edges.size() > 0) {
        view.getDiagram().insertEdge(edges.get(0));
    }
    setPreferredSize(view);
}
Also used : State(org.yakindu.sct.model.sgraph.State) Node(org.eclipse.gmf.runtime.notation.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) View(org.eclipse.gmf.runtime.notation.View) Edge(org.eclipse.gmf.runtime.notation.Edge) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 87 with State

use of org.yakindu.sct.model.sgraph.State in project statecharts by Yakindu.

the class StatePropertySection method createSpecificationControl.

protected void createSpecificationControl(final Composite parent) {
    Label lblDocumentation = getToolkit().createLabel(parent, "State Behavior: ");
    Injector injector = getInjector(State.class.getName());
    if (injector != null) {
        txtSpecification = new StyledText(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP);
        ((StyledText) txtSpecification).setAlwaysShowScrollBars(false);
        enableXtext(txtSpecification, injector);
        createHelpWidget(parent, txtSpecification, HelpContextIds.SC_PROPERTIES_STATE_EXPRESSION);
    } else {
        txtSpecification = getToolkit().createText(parent, "", SWT.MULTI);
    }
    GridDataFactory.fillDefaults().span(2, 1).applyTo(lblDocumentation);
    GridDataFactory.fillDefaults().grab(true, true).hint(parent.getSize()).applyTo(txtSpecification);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Injector(com.google.inject.Injector) State(org.yakindu.sct.model.sgraph.State) Label(org.eclipse.swt.widgets.Label)

Example 88 with State

use of org.yakindu.sct.model.sgraph.State in project statecharts by Yakindu.

the class GroupStatesIntoCompositeRefactoringTest method getStatesByName.

protected List<State> getStatesByName(Statechart statechart, List<String> names) {
    List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
    List<State> result = Lists.newArrayList();
    for (State state : allStates) {
        if (names.contains(state.getName())) {
            result.add(state);
        }
    }
    return result;
}
Also used : State(org.yakindu.sct.model.sgraph.State)

Example 89 with State

use of org.yakindu.sct.model.sgraph.State in project statecharts by Yakindu.

the class GroupStatesIntoCompositeRefactoringTest method testSemanticalRefactoring.

@Test
public void testSemanticalRefactoring() {
    Statechart initial = models.loadStatechartFromResource(GROUPING_STATES + INITIAL_STATECHART);
    List<State> states = getStatesByName(initial, Lists.newArrayList("B", "C", "D"));
    GroupStatesIntoCompositeRefactoring refactoring = new GroupStatesIntoCompositeRefactoring();
    refactoring.contextStates = Lists.newArrayList(states);
    AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
    initialRes.setSerializerEnabled(true);
    refactoring.doSemanticalRefactoring();
    initialRes.setSerializerEnabled(false);
    initialRes.linkSpecificationElements();
    Statechart expected = models.loadStatechartFromResource(GROUPING_STATES + EXPECTED_STATECHART);
    compareStatecharts(initial, expected);
}
Also used : AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) State(org.yakindu.sct.model.sgraph.State) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test) RefactoringTest(org.yakindu.sct.refactoring.refactor.RefactoringTest)

Example 90 with State

use of org.yakindu.sct.model.sgraph.State in project statecharts by Yakindu.

the class SGraphJavaValidationTest method vertexNotReachable_FailOnExternalPseudoPathToSubstate.

/**
 * If an incoming transitions is part of an external transition path to an
 * internal state that only consists of pseudo states and only has state
 * predecessors within the state then the state is not reachable and the
 * validation must fail with an error.
 */
@Test
public void vertexNotReachable_FailOnExternalPseudoPathToSubstate() {
    prepareStateTest();
    Region subRegion = factory.createRegion();
    state.getRegions().add(subRegion);
    State stateA = factory.createState();
    subRegion.getVertices().add(stateA);
    Choice choice = factory.createChoice();
    region.getVertices().add(choice);
    createTransition(stateA, choice);
    createTransition(choice, stateA);
    validate(state);
    assertIssue(diagnostics, ISSUE_NODE_NOT_REACHABLE);
}
Also used : Choice(org.yakindu.sct.model.sgraph.Choice) FinalState(org.yakindu.sct.model.sgraph.FinalState) State(org.yakindu.sct.model.sgraph.State) Region(org.yakindu.sct.model.sgraph.Region) Test(org.junit.Test)

Aggregations

State (org.yakindu.sct.model.sgraph.State)106 Test (org.junit.Test)77 Region (org.yakindu.sct.model.sgraph.Region)63 Statechart (org.yakindu.sct.model.sgraph.Statechart)59 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)51 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)51 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)51 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)50 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)46 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)46 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)46 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)46 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)39 Sequence (org.yakindu.sct.model.sexec.Sequence)36 FinalState (org.yakindu.sct.model.sgraph.FinalState)35 Entry (org.yakindu.sct.model.sgraph.Entry)30 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)28 Transition (org.yakindu.sct.model.sgraph.Transition)23 EnterState (org.yakindu.sct.model.sexec.EnterState)21