@Override protected CommandExecutionResult executeArg(List<String> arg) { final String code; final String display; if (arg.get(1) == null) { if (StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)).length() == 0) { code = "##" + UniqueSequence.getValue(); display = null; } else { code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); display = code; } } else { display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); code = arg.get(1); } final Group currentPackage = getSystem().getCurrentGroup(); // if (getSystem().entityExist(code)) { // return CommandExecutionResult.error("Package cannot have the same // name as an existing class"); // } final Group p = getSystem().getOrCreateGroup(code, display, null, GroupType.PACKAGE, currentPackage); p.setBold(true); final String color = arg.get(2); if (color != null) { p.setBackColor(HtmlColor.getColorIfValid(color)); } return CommandExecutionResult.ok(); }
@Override protected CommandExecutionResult executeArg(List<String> arg) { final EntityType type = EntityType.CIRCLE_INTERFACE; final String code; final String display; if (arg.get(1) == null) { code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); display = code; } else { display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1)); } final String stereotype = arg.get(2); // final Entity entity = getSystem().createEntity(code, display, type); final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type); entity.setDisplay2(display); if (stereotype != null) { entity.setStereotype( new Stereotype( stereotype, getSystem().getSkinParam().getCircledCharacterRadius(), getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); } return CommandExecutionResult.ok(); }
private CommandExecutionResult executeArgSpecial2(RegexResult arg) { final String clName1 = arg.get("COUPLE2", 0); final String clName2 = arg.get("COUPLE2", 1); if (getSystem().leafExist(clName1) == false) { return CommandExecutionResult.error("No class " + clName1); } if (getSystem().leafExist(clName2) == false) { return CommandExecutionResult.error("No class " + clName2); } final String ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1)); final IEntity cl1 = getSystem().getOrCreateClass(ent1); final LinkType linkType = getLinkType(arg); final String label = arg.get("LABEL_LINK", 0); // final int length = getQueueLength(arg); // final String weight = arg.get("HEADER").get(0); final boolean result = getSystem().associationClass(2, clName1, clName2, cl1, linkType, label); if (result == false) { return CommandExecutionResult.error("Cannot have more than 2 assocications"); } return CommandExecutionResult.ok(); }
private CommandExecutionResult executeArgSpecial2( AbstractClassOrObjectDiagram diagram, RegexResult arg) { final Code clName1 = Code.of(arg.get("COUPLE2", 0)); final Code clName2 = Code.of(arg.get("COUPLE2", 1)); if (diagram.leafExist(clName1) == false) { return CommandExecutionResult.error("No class " + clName1); } if (diagram.leafExist(clName2) == false) { return CommandExecutionResult.error("No class " + clName2); } final Code ent1 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1))); final IEntity cl1 = diagram.getOrCreateLeaf(ent1, null, null); final LinkType linkType = getLinkType(arg); final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); // final int length = getQueueLength(arg); // final String weight = arg.get("HEADER").get(0); final boolean result = diagram.associationClass(2, clName1, clName2, cl1, linkType, label); if (result == false) { return CommandExecutionResult.error("Cannot have more than 2 assocications"); } return CommandExecutionResult.ok(); }
private CommandExecutionResult executePackageLink(RegexResult arg) { final String ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1)); final String ent2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1)); final IEntity cl1 = getSystem().getGroup(ent1); final IEntity cl2 = getSystem().getGroup(ent2); final LinkType linkType = getLinkType(arg); final Direction dir = getDirection(arg); final int queue; if (dir == Direction.LEFT || dir == Direction.RIGHT) { queue = 1; } else { queue = getQueueLength(arg); } final String labelLink = arg.get("LABEL_LINK", 0); final String firstLabel = arg.get("FIRST_LABEL", 0); final String secondLabel = arg.get("SECOND_LABEL", 0); final Link link = new Link( cl1, cl2, linkType, labelLink, queue, firstLabel, secondLabel, getSystem().getLabeldistance(), getSystem().getLabelangle()); // if (dir == Direction.LEFT || dir == Direction.UP) { // link = link.getInv(); // } getSystem().resetPragmaLabel(); addLink(link, arg.get("HEADER", 0)); return CommandExecutionResult.ok(); }
private CommandExecutionResult executePackageLink( AbstractClassOrObjectDiagram diagram, RegexResult arg) { final IEntity cl1 = diagram.getGroup( Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1)))); final IEntity cl2 = diagram.getGroup( Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1)))); final LinkType linkType = getLinkType(arg); final Direction dir = getDirection(arg); final int queue; if (dir == Direction.LEFT || dir == Direction.RIGHT) { queue = 1; } else { queue = getQueueLength(arg); } final Display labelLink = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); final String firstLabel = arg.get("FIRST_LABEL", 0); final String secondLabel = arg.get("SECOND_LABEL", 0); final Link link = new Link( cl1, cl2, linkType, labelLink, queue, firstLabel, secondLabel, diagram.getLabeldistance(), diagram.getLabelangle()); diagram.resetPragmaLabel(); addLink(diagram, link, arg.get("HEADER", 0)); return CommandExecutionResult.ok(); }
@Override protected CommandExecutionResult executeArg(SequenceDiagram diagram, List<String> arg) { final LifeEventType type = LifeEventType.valueOf(StringUtils.goUpperCase(arg.get(0))); final Participant p = diagram.getOrCreateParticipant( StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1))); final HtmlColor backColor = diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get(2)); final HtmlColor lineColor = diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get(3)); final String error = diagram.activate(p, type, backColor, lineColor); if (error == null) { return CommandExecutionResult.ok(); } return CommandExecutionResult.error(error); }
@Override protected CommandExecutionResult executeArg(RegexResult arg) { final Code ent1 = Code.of(arg.get("ENT1", 1)); final Code ent2 = Code.of(arg.get("ENT2", 1)); final IEntity cl1; final IEntity cl2; final IEntity normalEntity; final String suffix = "lol" + UniqueSequence.getValue(); if (arg.get("LOL_THEN_ENT", 0) == null) { assert arg.get("ENT_THEN_LOL", 0) != null; cl1 = getSystem().getOrCreateClass(ent1); cl2 = getSystem() .createLeaf( cl1.getCode().addSuffix(suffix), StringUtils.getWithNewlines(ent2), LeafType.LOLLIPOP); normalEntity = cl1; } else { cl2 = getSystem().getOrCreateClass(ent2); cl1 = getSystem() .createLeaf( cl2.getCode().addSuffix(suffix), StringUtils.getWithNewlines(ent1), LeafType.LOLLIPOP); normalEntity = cl2; } final LinkType linkType = getLinkType(arg); final String queue = getQueue(arg); int length = queue.length(); if (length == 1 && getSystem().getNbOfHozizontalLollipop(normalEntity) > 1) { length++; } String firstLabel = arg.get("FIRST_LABEL", 0); String secondLabel = arg.get("SECOND_LABEL", 0); String labelLink = null; if (arg.get("LABEL_LINK", 0) != null) { labelLink = arg.get("LABEL_LINK", 0); if (firstLabel == null && secondLabel == null) { final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$"); final Matcher m1 = p1.matcher(labelLink); if (m1.matches()) { firstLabel = m1.group(1); labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim(); secondLabel = m1.group(3); } else { final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$"); final Matcher m2 = p2.matcher(labelLink); if (m2.matches()) { firstLabel = m2.group(1); labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim(); secondLabel = null; } else { final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$"); final Matcher m3 = p3.matcher(labelLink); if (m3.matches()) { firstLabel = null; labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim()) .trim(); secondLabel = m3.group(2); } } } } labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink); } /* * else if (arg.get("LABEL_LINK_XT").get(0) != null || * arg.get("LABEL_LINK_XT").get(1) != null || * arg.get("LABEL_LINK_XT").get(2) != null) { labelLink = * arg.get("LABEL_LINK_XT").get(1); firstLabel = merge(firstLabel, * arg.get("LABEL_LINK_XT").get(0)); secondLabel = * merge(arg.get("LABEL_LINK_XT").get(2), secondLabel); } */ final Link link = new Link( cl1, cl2, linkType, labelLink, length, firstLabel, secondLabel, getSystem().getLabeldistance(), getSystem().getLabelangle()); getSystem().resetPragmaLabel(); addLink(link, arg.get("HEADER", 0)); return CommandExecutionResult.ok(); }
@Override protected CommandExecutionResult executeArg(RegexResult arg) { String ent1 = arg.get("ENT1", 1); String ent2 = arg.get("ENT2", 1); if (ent1 == null) { return executeArgSpecial1(arg); } if (ent2 == null) { return executeArgSpecial2(arg); } ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(ent1); ent2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(ent2); if (getSystem().isGroup(ent1) && getSystem().isGroup(ent2)) { return executePackageLink(arg); } if (getSystem().isGroup(ent1) || getSystem().isGroup(ent2)) { return CommandExecutionResult.error("Package can be only linked to other package"); } final ILeaf cl1 = (ILeaf) getSystem().getOrCreateClass(ent1); final ILeaf cl2 = (ILeaf) getSystem().getOrCreateClass(ent2); if (arg.get("ENT1", 0) != null) { final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0)); if (type != LeafType.OBJECT) { cl1.muteToType(type); } } if (arg.get("ENT2", 0) != null) { final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0)); if (type != LeafType.OBJECT) { cl2.muteToType(type); } } if (arg.get("ENT1", 2) != null) { cl1.setStereotype( new Stereotype( arg.get("ENT1", 2), getSystem().getSkinParam().getCircledCharacterRadius(), getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); } if (arg.get("ENT2", 2) != null) { cl2.setStereotype( new Stereotype( arg.get("ENT2", 2), getSystem().getSkinParam().getCircledCharacterRadius(), getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); } final LinkType linkType = getLinkType(arg); final Direction dir = getDirection(arg); final int queue; if (dir == Direction.LEFT || dir == Direction.RIGHT) { queue = 1; } else { queue = getQueueLength(arg); } // if (dir != null && linkType.isExtendsOrAgregationOrCompositionOrPlus()) { // dir = dir.getInv(); // } String firstLabel = arg.get("FIRST_LABEL", 0); String secondLabel = arg.get("SECOND_LABEL", 0); String labelLink = null; if (arg.get("LABEL_LINK", 0) != null) { labelLink = arg.get("LABEL_LINK", 0); if (firstLabel == null && secondLabel == null) { final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$"); final Matcher m1 = p1.matcher(labelLink); if (m1.matches()) { firstLabel = m1.group(1); labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim(); secondLabel = m1.group(3); } else { final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$"); final Matcher m2 = p2.matcher(labelLink); if (m2.matches()) { firstLabel = m2.group(1); labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim(); secondLabel = null; } else { final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$"); final Matcher m3 = p3.matcher(labelLink); if (m3.matches()) { firstLabel = null; labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim()) .trim(); secondLabel = m3.group(2); } } } } labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink); } LinkArrow linkArrow = LinkArrow.NONE; if ("<".equals(labelLink)) { linkArrow = LinkArrow.BACKWARD; labelLink = null; } else if (">".equals(labelLink)) { linkArrow = LinkArrow.DIRECT_NORMAL; labelLink = null; } else if (labelLink != null && labelLink.startsWith("< ")) { linkArrow = LinkArrow.BACKWARD; labelLink = labelLink.substring(2).trim(); } else if (labelLink != null && labelLink.startsWith("> ")) { linkArrow = LinkArrow.DIRECT_NORMAL; labelLink = labelLink.substring(2).trim(); } else if (labelLink != null && labelLink.endsWith(" >")) { linkArrow = LinkArrow.DIRECT_NORMAL; labelLink = labelLink.substring(0, labelLink.length() - 2).trim(); } else if (labelLink != null && labelLink.endsWith(" <")) { linkArrow = LinkArrow.BACKWARD; labelLink = labelLink.substring(0, labelLink.length() - 2).trim(); } Link link = new Link( cl1, cl2, linkType, labelLink, queue, firstLabel, secondLabel, getSystem().getLabeldistance(), getSystem().getLabelangle()); if (dir == Direction.LEFT || dir == Direction.UP) { link = link.getInv(); } link.setLinkArrow(linkArrow); addLink(link, arg.get("HEADER", 0)); return CommandExecutionResult.ok(); }
@Override protected CommandExecutionResult executeArg( AbstractClassOrObjectDiagram diagram, RegexResult arg) { Code ent1 = Code.of(arg.get("ENT1", 1)); Code ent2 = Code.of(arg.get("ENT2", 1)); if (ent1 == null) { return executeArgSpecial1(diagram, arg); } if (ent2 == null) { return executeArgSpecial2(diagram, arg); } ent1 = ent1.eventuallyRemoveStartingAndEndingDoubleQuote(); ent2 = ent2.eventuallyRemoveStartingAndEndingDoubleQuote(); if (diagram.isGroup(ent1) && diagram.isGroup(ent2)) { return executePackageLink(diagram, arg); } final IEntity cl1 = diagram.isGroup(ent1) ? diagram.getGroup( Code.of( StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1)))) : diagram.getOrCreateLeaf(ent1, null, null); final IEntity cl2 = diagram.isGroup(ent2) ? diagram.getGroup( Code.of( StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1)))) : diagram.getOrCreateLeaf(ent2, null, null); if (arg.get("ENT1", 0) != null) { final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0)); if (type != LeafType.OBJECT) { ((ILeaf) cl1).muteToType(type, null); } } if (arg.get("ENT2", 0) != null) { final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0)); if (type != LeafType.OBJECT) { ((ILeaf) cl2).muteToType(type, null); } } if (arg.get("ENT1", 2) != null) { cl1.setStereotype( new Stereotype( arg.get("ENT1", 2), diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); } if (arg.get("ENT2", 2) != null) { cl2.setStereotype( new Stereotype( arg.get("ENT2", 2), diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); } final LinkType linkType = getLinkType(arg); final Direction dir = getDirection(arg); final int queue; if (dir == Direction.LEFT || dir == Direction.RIGHT) { queue = 1; } else { queue = getQueueLength(arg); } String firstLabel = arg.get("FIRST_LABEL", 0); String secondLabel = arg.get("SECOND_LABEL", 0); String labelLink = null; if (arg.get("LABEL_LINK", 0) != null) { labelLink = arg.get("LABEL_LINK", 0); if (firstLabel == null && secondLabel == null) { final Pattern p1 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)[%g]([^%g]+)[%g]$"); final Matcher m1 = p1.matcher(labelLink); if (m1.matches()) { firstLabel = m1.group(1); labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim(); secondLabel = m1.group(3); } else { final Pattern p2 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)$"); final Matcher m2 = p2.matcher(labelLink); if (m2.matches()) { firstLabel = m2.group(1); labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim(); secondLabel = null; } else { final Pattern p3 = MyPattern.cmpile("^([^%g]+)[%g]([^%g]+)[%g]$"); final Matcher m3 = p3.matcher(labelLink); if (m3.matches()) { firstLabel = null; labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim()) .trim(); secondLabel = m3.group(2); } } } } labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink); } LinkArrow linkArrow = LinkArrow.NONE; if ("<".equals(labelLink)) { linkArrow = LinkArrow.BACKWARD; labelLink = null; } else if (">".equals(labelLink)) { linkArrow = LinkArrow.DIRECT_NORMAL; labelLink = null; } else if (labelLink != null && labelLink.startsWith("< ")) { linkArrow = LinkArrow.BACKWARD; labelLink = labelLink.substring(2).trim(); } else if (labelLink != null && labelLink.startsWith("> ")) { linkArrow = LinkArrow.DIRECT_NORMAL; labelLink = labelLink.substring(2).trim(); } else if (labelLink != null && labelLink.endsWith(" >")) { linkArrow = LinkArrow.DIRECT_NORMAL; labelLink = labelLink.substring(0, labelLink.length() - 2).trim(); } else if (labelLink != null && labelLink.endsWith(" <")) { linkArrow = LinkArrow.BACKWARD; labelLink = labelLink.substring(0, labelLink.length() - 2).trim(); } Link link = new Link( cl1, cl2, linkType, Display.getWithNewlines(labelLink), queue, firstLabel, secondLabel, diagram.getLabeldistance(), diagram.getLabelangle()); if (dir == Direction.LEFT || dir == Direction.UP) { link = link.getInv(); } link.setLinkArrow(linkArrow); applyStyle(arg.getLazzy("ARROW_STYLE", 0), link); addLink(diagram, link, arg.get("HEADER", 0)); 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(); }