protected void createExitPoint(Edge edge, Diagram subdiagram) {
    Transition transition = (Transition) edge.getElement();
    // create semantic exit point
    Region exitPointContainer = getExitPointContainer(transition);
    Exit exitPoint = createSemanticExitPoint(transition);

    // create node for exit point
    View exitPointContainerView = helper.getViewForSemanticElement(exitPointContainer, subdiagram);
    View exitPointRegionCompartment =
        ViewUtil.getChildBySemanticHint(exitPointContainerView, SemanticHints.REGION_COMPARTMENT);
    Node exitNode =
        ViewService.createNode(
            exitPointRegionCompartment, exitPoint, SemanticHints.EXIT, preferencesHint);

    // re-wire existing transition to new exit point
    Vertex oldTarget = transition.getTarget();
    transition.setTarget(exitPoint);
    ViewService.createEdge(
        edge.getSource(), exitNode, transition, SemanticHints.TRANSITION, preferencesHint);

    // create transition from selected state to former transition target
    Transition exitPointTransition = SGraphFactory.eINSTANCE.createTransition();
    exitPointTransition.setSource((State) subdiagram.getElement());
    exitPointTransition.setTarget(oldTarget);
    ViewService.createEdge(
        getContextObject(),
        edge.getTarget(),
        exitPointTransition,
        SemanticHints.TRANSITION,
        preferencesHint);

    addExitPointSpec(exitPointTransition, exitPoint);
  }
  protected void createEntryPoint(Edge edge, Diagram subdiagram) {
    Transition transition = (Transition) edge.getElement();
    Region entryPointContainer = getEntryPointContainer(transition);
    Entry entryPoint = createSemanticEntryPoint(transition);

    // re-wire old transition to targeting the selected state
    transition.setTarget((State) subdiagram.getElement());
    View oldTarget = edge.getTarget();
    edge.setTarget(getContextObject());

    // create node for entry point
    View entryPointContainerView =
        helper.getViewForSemanticElement(entryPointContainer, subdiagram);
    View entryPointRegionCompartment =
        ViewUtil.getChildBySemanticHint(entryPointContainerView, SemanticHints.REGION_COMPARTMENT);
    Node entryNode =
        ViewService.createNode(
            entryPointRegionCompartment, entryPoint, SemanticHints.ENTRY, preferencesHint);
    ViewService.createEdge(
        entryNode,
        oldTarget,
        entryPoint.getOutgoingTransitions().get(0),
        SemanticHints.TRANSITION,
        preferencesHint);

    addEntryPointSpec(transition, entryPoint);
  }
Ejemplo n.º 3
0
 @Override
 protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   if (!canExecute()) {
     throw new ExecutionException("Invalid arguments in create link command");
   }
   if (getSource() != null && getTarget() != null) {
     Transition transition = SGraphFactory.eINSTANCE.createTransition();
     source.getOutgoingTransitions().add(transition);
     transition.setSource(source);
     transition.setTarget(target);
     source.getOutgoingTransitions().add(transition);
     target.getIncomingTransitions().add(transition);
     ((CreateElementRequest) getRequest()).setNewElement(transition);
   }
   return CommandResult.newOKCommandResult();
 }
  @Test
  public void testTransitionCheckSequenceWithGuard() {

    EventDefinition e1 = _createEventDefinition("e1", null);
    EventDefinition e2 = _createEventDefinition("e2", null);

    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    _createRegularEventSpec(e2, tr1);

    PrimitiveValueExpression exp = _createValue(false);
    tr1.setGuard(createGuardExpression(exp));

    Transition t = SGraphFactory.eINSTANCE.createTransition();
    t.setTrigger(tr1);

    Statechart sc = _createStatechart("test");
    Region region = _createRegion("r1", sc);
    t.setSource(_createState("A", region));
    t.setTarget(_createState("B", region));

    Reaction reaction = behaviorMapping.mapTransition(t);

    // now check the expression structure ...

    // the root is an and condition with the trigger check as the first
    // (left) part and the guard as the right (second) part.
    LogicalAndExpression and = (LogicalAndExpression) reaction.getCheck().getCondition();
    LogicalOrExpression triggerCheck = (LogicalOrExpression) and.getLeftOperand();
    PrimitiveValueExpression guardCheck = (PrimitiveValueExpression) and.getRightOperand();

    assertClass(ElementReferenceExpression.class, triggerCheck.getLeftOperand());
    assertClass(ElementReferenceExpression.class, triggerCheck.getRightOperand());
    assertEquals(
        e1.getName(),
        ((NamedElement) ((ElementReferenceExpression) triggerCheck.getLeftOperand()).getReference())
            .getName());
    assertEquals(
        e2.getName(),
        ((NamedElement)
                ((ElementReferenceExpression) triggerCheck.getRightOperand()).getReference())
            .getName());

    assertBoolLiteral(false, guardCheck.getValue());
  }
  @Test
  public void testTransitionCheckSequenceWithoutGuard() {

    EventDefinition e1 = _createEventDefinition("e1", null);
    EventDefinition e2 = _createEventDefinition("e2", null);

    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    _createRegularEventSpec(e2, tr1);

    Transition t = SGraphFactory.eINSTANCE.createTransition();
    t.setTrigger(tr1);

    Statechart sc = _createStatechart("test");
    Region region = _createRegion("r1", sc);
    t.setSource(_createState("A", region));
    t.setTarget(_createState("B", region));

    Reaction reaction = behaviorMapping.mapTransition(t);

    assertTrue(reaction.getCheck().getCondition() instanceof LogicalOrExpression);
    assertClass(
        ElementReferenceExpression.class,
        ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand());
    assertClass(
        ElementReferenceExpression.class,
        ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand());

    assertEquals(
        e1.getName(),
        ((NamedElement)
                ((ElementReferenceExpression)
                        ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand())
                    .getReference())
            .getName());
    assertEquals(
        e2.getName(),
        ((NamedElement)
                ((ElementReferenceExpression)
                        ((LogicalOrExpression) reaction.getCheck().getCondition())
                            .getRightOperand())
                    .getReference())
            .getName());
  }
  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;
  }
  @Test
  public void testTransitionCheckSequenceWithoutTrigger() {

    ReactionTrigger tr1 = _createReactionTrigger(null);
    PrimitiveValueExpression exp = _createValue(false);
    tr1.setGuard(createGuardExpression(exp));

    Transition t = SGraphFactory.eINSTANCE.createTransition();
    t.setTrigger(tr1);

    Statechart sc = _createStatechart("test");
    Region region = _createRegion("r1", sc);
    t.setSource(_createState("A", region));
    t.setTarget(_createState("B", region));

    Reaction reaction = behaviorMapping.mapTransition(t);

    // now check the expression structure ...

    // the root is an and condition with the trigger check as the first
    // (left) part and the guard as the right (second) part.
    PrimitiveValueExpression guard = (PrimitiveValueExpression) reaction.getCheck().getCondition();
    assertBoolLiteral(false, guard.getValue());
  }
Ejemplo n.º 8
0
 public static Transition _createTransition(Vertex source, Vertex target) {
   Transition t = SGraphFactory.eINSTANCE.createTransition();
   t.setSource(source);
   t.setTarget(target);
   return t;
 }