Search in sources :

Example 1 with Vertex

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

the class ExtractSubdiagramRefactoring method createSemanticEntryPoint.

protected Entry createSemanticEntryPoint(Transition transition) {
    Region entryPointTarget = getEntryPointContainer(transition);
    String name = getEntryPointName(transition);
    Entry entryPoint = null;
    Iterator<Vertex> iterator = entryPointTarget.getVertices().iterator();
    while (iterator.hasNext()) {
        Vertex next = iterator.next();
        if (next instanceof Entry) {
            Entry current = (Entry) next;
            if (name.equals(current.getName())) {
                // Do nothing, there already exists an entry point
                return current;
            }
        }
    }
    entryPoint = SGraphFactory.eINSTANCE.createEntry();
    entryPoint.setName(name);
    entryPointTarget.getVertices().add(entryPoint);
    Transition entryPointTransition = SGraphFactory.eINSTANCE.createTransition();
    entryPointTransition.setSource(entryPoint);
    entryPointTransition.setTarget(transition.getTarget());
    return entryPoint;
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Entry(org.yakindu.sct.model.sgraph.Entry) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region)

Example 2 with Vertex

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

the class ExtractSubdiagramRefactoring method createSemanticExitPoint.

private Exit createSemanticExitPoint(Transition transition) {
    Region exitPointContainer = getExitPointContainer(transition);
    String name = getExitPointName(transition);
    Exit exitPoint = null;
    Iterator<Vertex> iterator = exitPointContainer.getVertices().iterator();
    while (iterator.hasNext()) {
        Vertex next = iterator.next();
        if (next instanceof Exit) {
            Exit current = (Exit) next;
            if (name.equals(current.getName())) {
                // Do nothing, there already exists an entry point
                return current;
            }
        }
    }
    exitPoint = SGraphFactory.eINSTANCE.createExit();
    exitPoint.setName(name);
    exitPointContainer.getVertices().add(exitPoint);
    return exitPoint;
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Region(org.yakindu.sct.model.sgraph.Region) Exit(org.yakindu.sct.model.sgraph.Exit)

Example 3 with Vertex

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

the class VertexEditHelper method getDestroyDependentsCommand.

@Override
protected ICommand getDestroyDependentsCommand(DestroyDependentsRequest req) {
    Vertex elementToDestroy = (Vertex) req.getElementToDestroy();
    EList<Transition> incomingTransitions = elementToDestroy.getIncomingTransitions();
    if (incomingTransitions.size() != 0) {
        CompositeCommand compoundCommand = new CompositeCommand("Delete vertex");
        for (Transition transition : incomingTransitions) {
            DestroyElementCommand destroyCommand = new DestroyElementCommand(new DestroyElementRequest(transition, false));
            compoundCommand.add(destroyCommand);
        }
        return compoundCommand;
    }
    return super.getDestroyDependentsCommand(req);
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) DestroyElementRequest(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest) Transition(org.yakindu.sct.model.sgraph.Transition) DestroyElementCommand(org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand) CompositeCommand(org.eclipse.gmf.runtime.common.core.command.CompositeCommand)

Example 4 with Vertex

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

the class SGraphNameProvider method qualifiedName.

public QualifiedName qualifiedName(Choice ele) {
    // first get order number of choice node
    List<Vertex> choiceList = new ArrayList<Vertex>();
    choiceList.addAll(Collections2.filter(((Region) ele.eContainer()).getVertices(), new Predicate<Vertex>() {

        public boolean apply(Vertex input) {
            return input instanceof Choice;
        }
    }));
    int index = choiceList.indexOf(ele);
    QualifiedName qualifiedNameFromConverter = QualifiedName.create(_CHOICE_NAME + index);
    return getParentQualifiedName(ele, qualifiedNameFromConverter);
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Choice(org.yakindu.sct.model.sgraph.Choice) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) Region(org.yakindu.sct.model.sgraph.Region) Predicate(com.google.common.base.Predicate)

Example 5 with Vertex

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

the class SGraphJavaValidator method regionCantBeEnteredUsingShallowHistory.

/**
 * Checks if all composite states that are siblings of a shallow history can
 * enter their regions.
 *
 * @param e
 */
@Check(CheckType.FAST)
public void regionCantBeEnteredUsingShallowHistory(Entry e) {
    if (e.getKind() == EntryKind.SHALLOW_HISTORY) {
        // get all regions off all sibling states
        List<Region> regions = new ArrayList<>();
        for (Vertex v : e.getParentRegion().getVertices()) {
            if (v instanceof org.yakindu.sct.model.sgraph.State) {
                org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) v;
                regions.addAll(state.getRegions());
            }
        }
        // check each region
        for (Region r : regions) {
            // first determine if the region contains a default entry
            Entry defaultEntry = null;
            for (Vertex v : r.getVertices()) {
                if (v instanceof Entry) {
                    String name = v.getName().trim().toLowerCase();
                    if (name != null || "".equals(name) || "default".equals(name)) {
                        defaultEntry = (Entry) v;
                        break;
                    }
                }
            }
            // now check error conditions
            if (defaultEntry == null) {
                error(ISSUE_REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY, r, null, -1);
            } else if (defaultEntry.getOutgoingTransitions().size() != 1) {
                error(ISSUE_REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY, r, null, -1);
            }
        }
    }
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) ArrayList(java.util.ArrayList) Entry(org.yakindu.sct.model.sgraph.Entry) FinalState(org.yakindu.sct.model.sgraph.FinalState) Region(org.yakindu.sct.model.sgraph.Region) Check(org.eclipse.xtext.validation.Check)

Aggregations

Vertex (org.yakindu.sct.model.sgraph.Vertex)14 Transition (org.yakindu.sct.model.sgraph.Transition)7 Region (org.yakindu.sct.model.sgraph.Region)6 ArrayList (java.util.ArrayList)4 Check (org.eclipse.xtext.validation.Check)4 EObject (org.eclipse.emf.ecore.EObject)3 Entry (org.yakindu.sct.model.sgraph.Entry)3 HashSet (java.util.HashSet)2 Exit (org.yakindu.sct.model.sgraph.Exit)2 FinalState (org.yakindu.sct.model.sgraph.FinalState)2 Predicate (com.google.common.base.Predicate)1 List (java.util.List)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 CompositeCommand (org.eclipse.gmf.runtime.common.core.command.CompositeCommand)1 PreferencesHint (org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)1 DestroyElementCommand (org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand)1 CreateElementRequest (org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest)1 DestroyElementRequest (org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest)1 Node (org.eclipse.gmf.runtime.notation.Node)1 View (org.eclipse.gmf.runtime.notation.View)1