private CommandExecutionResult executeInternal(
      ActivityDiagram system, RegexResult arg, IEntity note) {

    note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)));

    IEntity activity = system.getLastEntityConsulted();
    if (activity == null) {
      activity = system.getStart();
    }

    final Link link;

    final Position position =
        Position.valueOf(arg.get("POSITION", 0).toUpperCase()).withRankdir(system.getRankdir());

    final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();

    if (position == Position.RIGHT) {
      link = new Link(activity, note, type, null, 1);
    } else if (position == Position.LEFT) {
      link = new Link(note, activity, type, null, 1);
    } else if (position == Position.BOTTOM) {
      link = new Link(activity, note, type, null, 2);
    } else if (position == Position.TOP) {
      link = new Link(note, activity, type, null, 2);
    } else {
      throw new IllegalArgumentException();
    }
    system.addLink(link);
    return CommandExecutionResult.ok();
  }
Пример #2
0
  @Override
  protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg2) {
    final IEntity entity1 = getEntity(getSystem(), arg2, true);
    if (entity1 == null) {
      return CommandExecutionResult.error("No such activity");
    }
    if (arg2.get("STEREOTYPE").get(0) != null) {
      entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0)));
    }
    if (arg2.get("BACKCOLOR").get(0) != null) {
      entity1.setSpecificBackcolor(arg2.get("BACKCOLOR").get(0));
    }

    final IEntity entity2 = getEntity(getSystem(), arg2, false);
    if (entity2 == null) {
      return CommandExecutionResult.error("No such activity");
    }
    if (arg2.get("BACKCOLOR2").get(0) != null) {
      entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0));
    }
    if (arg2.get("STEREOTYPE2").get(0) != null) {
      entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2").get(0)));
    }

    final String linkLabel = arg2.get("BRACKET").get(0);

    final String arrow = StringUtils.manageArrowForCuca(arg2.get("ARROW").get(0));
    final int lenght = arrow.length() - 1;

    Link link =
        new Link(
            entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
    final Direction direction = StringUtils.getArrowDirection(arg2.get("ARROW").get(0));
    if (direction == Direction.LEFT || direction == Direction.UP) {
      link = link.getInv();
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }
  public final CommandExecutionResult execute(List<String> lines) {

    final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim());
    final String pos = line0.get(0);

    final IEntity activity = getSystem().getLastEntityConsulted();
    if (activity == null) {
      // activity = getSystem().getStart();
      return CommandExecutionResult.error("No activity defined");
    }

    final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
    //		final String s = StringUtils.getMergedLines(strings);

    final IEntity note =
        getSystem().createLeaf(UniqueSequence.getCode("GMN"), strings, LeafType.NOTE);
    note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get(1)));

    final Link link;

    final Position position =
        Position.valueOf(pos.toUpperCase()).withRankdir(getSystem().getRankdir());

    final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();

    if (position == Position.RIGHT) {
      link = new Link(activity, note, type, null, 1);
    } else if (position == Position.LEFT) {
      link = new Link(note, activity, type, null, 1);
    } else if (position == Position.BOTTOM) {
      link = new Link(activity, note, type, null, 2);
    } else if (position == Position.TOP) {
      link = new Link(note, activity, type, null, 2);
    } else {
      throw new IllegalArgumentException();
    }
    getSystem().addLink(link);
    return CommandExecutionResult.ok();
  }
  public CommandExecutionResult execute(List<String> lines) {
    StringUtils.trim(lines, false);
    final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim());

    final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), line0, true);

    if (line0.get("STEREOTYPE", 0) != null) {
      entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0)));
    }
    if (line0.get("BACKCOLOR", 0) != null) {
      entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("BACKCOLOR", 0)));
    }
    final StringBuilder sb = new StringBuilder();

    final String desc0 = line0.get("DESC", 0);
    Url urlActivity = null;
    if (StringUtils.isNotEmpty(desc0)) {
      final UrlBuilder urlBuilder =
          new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
      urlActivity = urlBuilder.getUrl(desc0);
      if (urlActivity == null) {
        sb.append(desc0);
        sb.append("\\n");
      }
    }
    for (int i = 1; i < lines.size() - 1; i++) {
      if (i == 1 && urlActivity == null) {
        final UrlBuilder urlBuilder =
            new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
        urlActivity = urlBuilder.getUrl(lines.get(i));
        if (urlActivity != null) {
          continue;
        }
      }
      sb.append(lines.get(i));
      if (i < lines.size() - 2) {
        sb.append("\\n");
      }
    }

    final List<String> lineLast =
        StringUtils.getSplit(Pattern.compile(getPatternEnd()), lines.get(lines.size() - 1));
    if (StringUtils.isNotEmpty(lineLast.get(0))) {
      if (sb.length() > 0 && sb.toString().endsWith("\\n") == false) {
        sb.append("\\n");
      }
      sb.append(lineLast.get(0));
    }

    final String display = sb.toString();
    final Code code = Code.of(lineLast.get(1) == null ? display : lineLast.get(1));

    String partition = null;
    if (lineLast.get(3) != null) {
      partition = lineLast.get(3);
      partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition);
    }
    if (partition != null) {
      getSystem()
          .getOrCreateGroup(
              Code.of(partition),
              StringUtils.getWithNewlines(partition),
              null,
              GroupType.PACKAGE,
              null);
    }
    final IEntity entity2 =
        getSystem().createLeaf(code, StringUtils.getWithNewlines(display), LeafType.ACTIVITY);
    if (partition != null) {
      getSystem().endGroup();
    }
    if (urlActivity != null) {
      entity2.addUrl(urlActivity);
    }

    if (lineLast.get(2) != null) {
      entity2.setStereotype(new Stereotype(lineLast.get(2)));
    }
    if (lineLast.get(4) != null) {
      entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(lineLast.get(4)));
    }

    if (entity1 == null || entity2 == null) {
      return CommandExecutionResult.error("No such entity");
    }

    final String arrow = StringUtils.manageArrowForCuca(line0.get("ARROW", 0));
    final int lenght = arrow.length() - 1;

    final String linkLabel = line0.get("BRACKET", 0);

    LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
    if (line0.get("ARROW", 0).contains(".")) {
      type = type.getDotted();
    }
    Link link = new Link(entity1, entity2, type, linkLabel, lenght);
    final Direction direction = StringUtils.getArrowDirection(line0.get("ARROW", 0));
    if (direction == Direction.LEFT || direction == Direction.UP) {
      link = link.getInv();
    }

    if (line0.get("URL", 0) != null) {
      final UrlBuilder urlBuilder =
          new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
      final Url urlLink = urlBuilder.getUrl(line0.get("URL", 0));
      link.setUrl(urlLink);
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }