@Override protected CommandExecutionResult executeArg(RegexResult arg) { final Code g1 = Code.of(arg.get("G1", 0)); final Code g2 = Code.of(arg.get("G2", 0)); if (getSystem().isGroup(g1) && getSystem().isGroup(g2)) { return executePackageLink(arg); } if (getSystem().isGroup(g1) || getSystem().isGroup(g2)) { return CommandExecutionResult.error("Package can be only linked to other package"); } final IEntity cl1 = getSystem().getOrCreateClass(g1); final IEntity cl2 = getSystem().getOrCreateClass(g2); if (arg.get("G1", 1) != null) { cl1.setStereotype(new Stereotype(arg.get("G1", 1))); } if (arg.get("G2", 1) != null) { cl2.setStereotype(new Stereotype(arg.get("G2", 1))); } final LinkType linkType; String queue; if (arg.get("AR_TO_RIGHT", 0) == null) { queue = arg.get("AR_TO_LEFT", 2) + arg.get("AR_TO_LEFT", 4); linkType = getLinkTypeNormal(queue, arg.get("AR_TO_LEFT", 1)).getInversed(); } else { queue = arg.get("AR_TO_RIGHT", 1) + arg.get("AR_TO_RIGHT", 3); linkType = getLinkTypeNormal(queue, arg.get("AR_TO_RIGHT", 4)); } final Direction dir = getDirection(arg); if (dir == Direction.LEFT || dir == Direction.RIGHT) { queue = "-"; } Link link = new Link(cl1, cl2, linkType, arg.get("END", 0), queue.length()); if (dir == Direction.LEFT || dir == Direction.UP) { link = link.getInv(); } getSystem().addLink(link); return CommandExecutionResult.ok(); }
@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(); }
@Override protected CommandExecutionResult executeArg(ClassDiagram diagram, List<String> arg) { final Code code = Code.of(arg.get(0)); final String stereotype = arg.get(1); final IEntity entity = diagram.getOrCreateLeaf(code, null, null); entity.setStereotype( new Stereotype( stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null, false), diagram.getSkinParam().getIHtmlColorSet())); return CommandExecutionResult.ok(); }
@Override protected CommandExecutionResult executeArg(List<String> arg) { final String code = arg.get(2); final String display = arg.get(1); final String stereotype = arg.get(3); if (getSystem().leafExist(code)) { return CommandExecutionResult.error("Object already exists : " + code); } final IEntity entity = getSystem().createLeaf(code, StringUtils.getWithNewlines(display), LeafType.OBJECT); if (stereotype != null) { entity.setStereotype( new Stereotype( stereotype, getSystem().getSkinParam().getCircledCharacterRadius(), getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); } 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(); }
@Override protected CommandExecutionResult executeArg(StateDiagram diagram, RegexResult arg) { final String ent1 = arg.get("ENT1", 0); final String ent2 = arg.get("ENT2", 0); final IEntity cl1 = getEntityStart(diagram, ent1); if (cl1 == null) { return CommandExecutionResult.error( "The state " + ent1 + " has been created in a concurrent state : it cannot be used here."); } final IEntity cl2 = getEntityEnd(diagram, ent2); if (cl2 == null) { return CommandExecutionResult.error( "The state " + ent2 + " has been created in a concurrent state : it cannot be used here."); } if (arg.get("ENT1", 1) != null) { cl1.setStereotype(new Stereotype(arg.get("ENT1", 1))); } if (arg.get("ENT1", 2) != null) { cl1.setSpecificColorTOBEREMOVED( ColorType.BACK, diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("ENT1", 2))); } if (arg.get("ENT2", 1) != null) { cl2.setStereotype(new Stereotype(arg.get("ENT2", 1))); } if (arg.get("ENT2", 2) != null) { cl2.setSpecificColorTOBEREMOVED( ColorType.BACK, diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("ENT2", 2))); } String queue = arg.get("ARROW_BODY1", 0) + arg.get("ARROW_BODY2", 0); final Direction dir = getDirection(arg); if (dir == Direction.LEFT || dir == Direction.RIGHT) { queue = "-"; } final int lenght = queue.length(); final boolean crossStart = arg.get("ARROW_CROSS_START", 0) != null; final boolean circleEnd = arg.get("ARROW_CIRCLE_END", 0) != null; final LinkType linkType = new LinkType( circleEnd ? LinkDecor.ARROW_AND_CIRCLE : LinkDecor.ARROW, crossStart ? LinkDecor.CIRCLE_CROSS : LinkDecor.NONE); Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(arg.get("LABEL", 0)), lenght); if (dir == Direction.LEFT || dir == Direction.UP) { link = link.getInv(); } CommandLinkClass.applyStyle(arg.getLazzy("ARROW_STYLE", 0), link); diagram.addLink(link); return CommandExecutionResult.ok(); }