@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();
 }
예제 #2
0
 private boolean isChildOrSibling(Vertex source, Vertex target) {
   TreeIterator<EObject> iter = source.getParentRegion().eAllContents();
   while (iter.hasNext()) {
     if (target == iter.next()) {
       return true;
     }
   }
   return false;
 }
예제 #3
0
  /**
   * 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<Region>();
      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);
        }
      }
    }
  }