mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-21 20:45:10 +00:00
Support long name and alias in Chen-EER
This commit is contained in:
parent
8312e8c22f
commit
90a88ce4ee
@ -55,54 +55,54 @@ import net.sourceforge.plantuml.utils.LineLocation;
|
|||||||
|
|
||||||
public class CommandAssociate extends SingleLineCommand2<ChenEerDiagram> {
|
public class CommandAssociate extends SingleLineCommand2<ChenEerDiagram> {
|
||||||
|
|
||||||
public CommandAssociate() {
|
public CommandAssociate() {
|
||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
private static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("PARTICIPATION", "([-=])"), //
|
new RegexLeaf("PARTICIPATION", "([-=])"), //
|
||||||
new RegexOptional( //
|
new RegexOptional( //
|
||||||
new RegexLeaf("CARDINALITY", "(\\w+|\\(\\w+,[%s]*\\w+\\))")), //
|
new RegexLeaf("CARDINALITY", "(\\w+|\\(\\w+,[%s]*\\w+\\))")), //
|
||||||
new RegexLeaf("PARTICIPATION2", "([-=])"), //
|
new RegexLeaf("PARTICIPATION2", "([-=])"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("NAME2", "([\\w-]+)"), //
|
new RegexLeaf("NAME2", "([\\w-]+)"), //
|
||||||
RegexLeaf.end());
|
RegexLeaf.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||||
throws NoSuchColorException {
|
throws NoSuchColorException {
|
||||||
final String name1 = diagram.cleanId(arg.get("NAME1", 0));
|
final String name1 = diagram.cleanId(arg.get("NAME1", 0));
|
||||||
final String name2 = diagram.cleanId(arg.get("NAME2", 0));
|
final String name2 = diagram.cleanId(arg.get("NAME2", 0));
|
||||||
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
|
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
|
||||||
final String cardinality = arg.get("CARDINALITY", 0);
|
final String cardinality = arg.get("CARDINALITY", 0);
|
||||||
|
|
||||||
final Quark<Entity> quark1 = diagram.quarkInContext(true, name1);
|
final Quark<Entity> quark1 = diagram.quarkInContext(true, name1);
|
||||||
final Entity entity1 = quark1.getData();
|
final Entity entity1 = quark1.getData();
|
||||||
if (entity1 == null) {
|
if (entity1 == null) {
|
||||||
return CommandExecutionResult.error("No such entity: " + name1);
|
return CommandExecutionResult.error("No such entity: " + name1);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Quark<Entity> quark2 = diagram.quarkInContext(true, name2);
|
final Quark<Entity> quark2 = diagram.quarkInContext(true, name2);
|
||||||
final Entity entity2 = quark2.getData();
|
final Entity entity2 = quark2.getData();
|
||||||
if (entity2 == null) {
|
if (entity2 == null) {
|
||||||
return CommandExecutionResult.error("No such entity: " + name2);
|
return CommandExecutionResult.error("No such entity: " + name2);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
||||||
if (isDouble) {
|
if (isDouble) {
|
||||||
linkType = linkType.goBold();
|
linkType = linkType.goBold();
|
||||||
}
|
}
|
||||||
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity1, entity2,
|
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity1, entity2,
|
||||||
linkType,
|
linkType,
|
||||||
LinkArg.build(Display.getWithNewlines(cardinality), 3));
|
LinkArg.build(Display.getWithNewlines(cardinality), 3));
|
||||||
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
|
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
|
||||||
diagram.addLink(link);
|
diagram.addLink(link);
|
||||||
|
|
||||||
return CommandExecutionResult.ok();
|
return CommandExecutionResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2024, Arnaud Roques
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: https://plantuml.com
|
* Project Info: https://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* https://plantuml.com/patreon (only 1$ per month!)
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
* https://plantuml.com/paypal
|
* https://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.cheneer.command;
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
@ -50,66 +50,77 @@ import net.sourceforge.plantuml.plasma.Quark;
|
|||||||
import net.sourceforge.plantuml.regex.IRegex;
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
import net.sourceforge.plantuml.regex.RegexConcat;
|
import net.sourceforge.plantuml.regex.RegexConcat;
|
||||||
import net.sourceforge.plantuml.regex.RegexLeaf;
|
import net.sourceforge.plantuml.regex.RegexLeaf;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexOptional;
|
||||||
import net.sourceforge.plantuml.regex.RegexResult;
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
import net.sourceforge.plantuml.stereo.Stereotype;
|
import net.sourceforge.plantuml.stereo.Stereotype;
|
||||||
import net.sourceforge.plantuml.utils.LineLocation;
|
import net.sourceforge.plantuml.utils.LineLocation;
|
||||||
|
|
||||||
public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
|
public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
|
||||||
|
|
||||||
public CommandCreateAttribute() {
|
public CommandCreateAttribute() {
|
||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
private static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
RegexLeaf.spaceZeroOrMore(),
|
RegexLeaf.spaceZeroOrMore(),
|
||||||
new RegexLeaf("NAME", "([^<>{}=-]+)"), //
|
new RegexOptional( // Copied from CommandCreatePackageBlock
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
new RegexConcat( //
|
||||||
new RegexLeaf("STEREO", "(<<.*>>)?"), //
|
new RegexLeaf("DISPLAY", "[%g]([^%g]+)[%g]"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceOneOrMore(), //
|
||||||
new RegexLeaf("COMPOSITE", "(\\{)?"), //
|
new RegexLeaf("as"), //
|
||||||
RegexLeaf.end());
|
RegexLeaf.spaceOneOrMore() //
|
||||||
}
|
)), //
|
||||||
|
new RegexLeaf("CODE", "([%pLN%s_.:<>]+)"), //
|
||||||
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
new RegexLeaf("STEREO", "(<<.*>>)?"), //
|
||||||
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
new RegexLeaf("COMPOSITE", "(\\{)?"), //
|
||||||
|
RegexLeaf.end());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||||
throws NoSuchColorException {
|
throws NoSuchColorException {
|
||||||
final Entity owner = diagram.peekOwner();
|
final Entity owner = diagram.peekOwner();
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
return CommandExecutionResult.error("Attribute must be inside an entity, relationship or another attribute");
|
return CommandExecutionResult.error("Attribute must be inside an entity, relationship or another attribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
final LeafType type = LeafType.CHEN_ATTRIBUTE;
|
final LeafType type = LeafType.CHEN_ATTRIBUTE;
|
||||||
final String name = diagram.cleanId(arg.get("NAME", 0).trim());
|
final String idShort = diagram.cleanId(arg.get("CODE", 0).trim());
|
||||||
final String id = owner.getName() + "/" + name;
|
final String id = owner.getName() + "/" + idShort;
|
||||||
final String stereo = arg.get("STEREO", 0);
|
final Quark<Entity> quark = diagram.quarkInContext(true, id);
|
||||||
final boolean composite = arg.get("COMPOSITE", 0) != null;
|
String displayText = arg.get("DISPLAY", 0);
|
||||||
|
if (displayText == null)
|
||||||
|
displayText = quark.getName();
|
||||||
|
|
||||||
final Quark<Entity> quark = diagram.quarkInContext(true, id);
|
final String stereo = arg.get("STEREO", 0);
|
||||||
|
final boolean composite = arg.get("COMPOSITE", 0) != null;
|
||||||
|
|
||||||
Entity entity = quark.getData();
|
Entity entity = quark.getData();
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
final Display display = Display.getWithNewlines(name);
|
final Display display = Display.getWithNewlines(displayText);
|
||||||
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
||||||
} else {
|
} else {
|
||||||
return CommandExecutionResult.error("Attribute already exists");
|
return CommandExecutionResult.error("Attribute already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stereo != null) {
|
if (stereo != null) {
|
||||||
entity.setStereotype(Stereotype.build(stereo));
|
entity.setStereotype(Stereotype.build(stereo));
|
||||||
entity.setStereostyle(stereo);
|
entity.setStereostyle(stereo);
|
||||||
}
|
}
|
||||||
|
|
||||||
final LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
final LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
||||||
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity, owner, linkType,
|
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity, owner, linkType,
|
||||||
LinkArg.build(Display.NULL, 2));
|
LinkArg.build(Display.NULL, 2));
|
||||||
diagram.addLink(link);
|
diagram.addLink(link);
|
||||||
|
|
||||||
if (composite) {
|
if (composite) {
|
||||||
diagram.pushOwner(entity);
|
diagram.pushOwner(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommandExecutionResult.ok();
|
return CommandExecutionResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2024, Arnaud Roques
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: https://plantuml.com
|
* Project Info: https://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* https://plantuml.com/patreon (only 1$ per month!)
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
* https://plantuml.com/paypal
|
* https://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.cheneer.command;
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
@ -46,65 +46,78 @@ import net.sourceforge.plantuml.plasma.Quark;
|
|||||||
import net.sourceforge.plantuml.regex.IRegex;
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
import net.sourceforge.plantuml.regex.RegexConcat;
|
import net.sourceforge.plantuml.regex.RegexConcat;
|
||||||
import net.sourceforge.plantuml.regex.RegexLeaf;
|
import net.sourceforge.plantuml.regex.RegexLeaf;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexOptional;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexOr;
|
||||||
import net.sourceforge.plantuml.regex.RegexResult;
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
import net.sourceforge.plantuml.stereo.Stereotype;
|
import net.sourceforge.plantuml.stereo.Stereotype;
|
||||||
import net.sourceforge.plantuml.utils.LineLocation;
|
import net.sourceforge.plantuml.utils.LineLocation;
|
||||||
|
|
||||||
public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
|
public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
|
||||||
|
|
||||||
public CommandCreateEntity() {
|
public CommandCreateEntity() {
|
||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
private static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("TYPE", "(entity|relationship)"), //
|
new RegexLeaf("TYPE", "(entity|relationship)"), //
|
||||||
RegexLeaf.spaceOneOrMore(), //
|
RegexLeaf.spaceOneOrMore(), //
|
||||||
new RegexLeaf("NAME", "([^<>{}]+)"), //
|
new RegexOptional( // Copied from CommandCreatePackageBlock
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
new RegexConcat( //
|
||||||
new RegexLeaf("STEREO", "(<<.+>>)?"), //
|
new RegexLeaf("DISPLAY", "[%g]([^%g]+)[%g]"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceOneOrMore(), //
|
||||||
new RegexLeaf("\\{"), //
|
new RegexLeaf("as"), //
|
||||||
RegexLeaf.end());
|
RegexLeaf.spaceOneOrMore() //
|
||||||
}
|
)), //
|
||||||
|
new RegexLeaf("CODE", "([%pLN_.]+)"), //
|
||||||
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
new RegexLeaf("STEREO", "(<<.+>>)?"), //
|
||||||
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
new RegexLeaf("\\{"), //
|
||||||
|
RegexLeaf.end());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||||
throws NoSuchColorException {
|
throws NoSuchColorException {
|
||||||
LeafType type;
|
LeafType type;
|
||||||
switch (arg.get("TYPE", 0)) {
|
switch (arg.get("TYPE", 0)) {
|
||||||
case "entity":
|
case "entity":
|
||||||
type = LeafType.CHEN_ENTITY;
|
type = LeafType.CHEN_ENTITY;
|
||||||
break;
|
break;
|
||||||
case "relationship":
|
case "relationship":
|
||||||
type = LeafType.CHEN_RELATIONSHIP;
|
type = LeafType.CHEN_RELATIONSHIP;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name = diagram.cleanId(arg.get("NAME", 0).trim());
|
final String idShort = arg.get("CODE", 0);
|
||||||
final String stereo = arg.get("STEREO", 0);
|
final Quark<Entity> quark = diagram.quarkInContext(true, diagram.cleanId(idShort));
|
||||||
|
String displayText = arg.get("DISPLAY", 0);
|
||||||
|
if (displayText == null)
|
||||||
|
displayText = quark.getName();
|
||||||
|
|
||||||
final Quark<Entity> quark = diagram.quarkInContext(true, name);
|
final String stereo = arg.get("STEREO", 0);
|
||||||
Entity entity = quark.getData();
|
|
||||||
|
|
||||||
if (entity == null) {
|
Entity entity = quark.getData();
|
||||||
Display display = Display.getWithNewlines(name);
|
|
||||||
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
|
||||||
} else {
|
|
||||||
if (entity.muteToType(type, null) == false)
|
|
||||||
return CommandExecutionResult.error("Bad name");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stereo != null) {
|
if (entity == null) {
|
||||||
entity.setStereotype(Stereotype.build(stereo));
|
Display display = Display.getWithNewlines(displayText);
|
||||||
entity.setStereostyle(stereo);
|
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
||||||
}
|
} else {
|
||||||
|
if (entity.muteToType(type, null) == false)
|
||||||
|
return CommandExecutionResult.error("Bad name");
|
||||||
|
}
|
||||||
|
|
||||||
diagram.pushOwner(entity);
|
if (stereo != null) {
|
||||||
|
entity.setStereotype(Stereotype.build(stereo));
|
||||||
|
entity.setStereostyle(stereo);
|
||||||
|
}
|
||||||
|
|
||||||
return CommandExecutionResult.ok();
|
diagram.pushOwner(entity);
|
||||||
}
|
|
||||||
|
return CommandExecutionResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,80 +59,80 @@ import net.sourceforge.plantuml.utils.LineLocation;
|
|||||||
|
|
||||||
public class CommandMultiSubclass extends SingleLineCommand2<ChenEerDiagram> {
|
public class CommandMultiSubclass extends SingleLineCommand2<ChenEerDiagram> {
|
||||||
|
|
||||||
public CommandMultiSubclass() {
|
public CommandMultiSubclass() {
|
||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
private static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("SUPERCLASS", "([\\w-]+)"), //
|
new RegexLeaf("SUPERCLASS", "([\\w-]+)"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("PARTICIPATION", "([-=])"), //
|
new RegexLeaf("PARTICIPATION", "([-=])"), //
|
||||||
new RegexLeaf("(>)"), //
|
new RegexLeaf("(>)"), //
|
||||||
new RegexLeaf("PARTICIPATION2", "([-=])"), //
|
new RegexLeaf("PARTICIPATION2", "([-=])"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("SYMBOL", "([doU])"), //
|
new RegexLeaf("SYMBOL", "([doU])"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("\\{"), //
|
new RegexLeaf("\\{"), //
|
||||||
new RegexLeaf("SUBCLASSES", "(.+)"), //
|
new RegexLeaf("SUBCLASSES", "(.+)"), //
|
||||||
new RegexLeaf("\\}"), //
|
new RegexLeaf("\\}"), //
|
||||||
RegexLeaf.end());
|
RegexLeaf.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||||
throws NoSuchColorException {
|
throws NoSuchColorException {
|
||||||
final String superclass = diagram.cleanId(arg.get("SUPERCLASS", 0));
|
final String superclass = diagram.cleanId(arg.get("SUPERCLASS", 0));
|
||||||
final String subclasses = arg.get("SUBCLASSES", 0);
|
final String subclasses = arg.get("SUBCLASSES", 0);
|
||||||
final List<String> subclassIds = Arrays.stream(subclasses.split(","))
|
final List<String> subclassIds = Arrays.stream(subclasses.split(","))
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.map(diagram::cleanId)
|
.map(diagram::cleanId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
|
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
|
||||||
final String symbol = arg.get("SYMBOL", 0);
|
final String symbol = arg.get("SYMBOL", 0);
|
||||||
|
|
||||||
final Quark<Entity> centerQuark = diagram.quarkInContext(false, superclass + "/" + symbol + subclasses + "/center");
|
final Quark<Entity> centerQuark = diagram.quarkInContext(false, superclass + "/" + symbol + subclasses + "/center");
|
||||||
final Entity centerEntity = diagram.reallyCreateLeaf(centerQuark, Display.create(symbol), LeafType.CHEN_CIRCLE, null);
|
final Entity centerEntity = diagram.reallyCreateLeaf(centerQuark, Display.create(symbol), LeafType.CHEN_CIRCLE, null);
|
||||||
|
|
||||||
final Quark<Entity> superclassQuark = diagram.quarkInContext(true, superclass);
|
final Quark<Entity> superclassQuark = diagram.quarkInContext(true, superclass);
|
||||||
final Entity superclassEntity = superclassQuark.getData();
|
final Entity superclassEntity = superclassQuark.getData();
|
||||||
if (superclassEntity == null) {
|
if (superclassEntity == null) {
|
||||||
return CommandExecutionResult.error("No such entity: " + superclass);
|
return CommandExecutionResult.error("No such entity: " + superclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
||||||
if (isDouble) {
|
if (isDouble) {
|
||||||
linkType = linkType.goBold();
|
linkType = linkType.goBold();
|
||||||
}
|
}
|
||||||
if (symbol.equals("U")) {
|
if (symbol.equals("U")) {
|
||||||
linkType = linkType.withMiddleSuperset();
|
linkType = linkType.withMiddleSuperset();
|
||||||
}
|
}
|
||||||
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), superclassEntity,
|
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), superclassEntity,
|
||||||
centerEntity,
|
centerEntity,
|
||||||
linkType,
|
linkType,
|
||||||
LinkArg.build(Display.NULL, 2));
|
LinkArg.build(Display.NULL, 2));
|
||||||
link.setPortMembers(diagram.getPortId(superclassEntity.getName()), diagram.getPortId(centerEntity.getName()));
|
link.setPortMembers(diagram.getPortId(superclassEntity.getName()), diagram.getPortId(centerEntity.getName()));
|
||||||
diagram.addLink(link);
|
diagram.addLink(link);
|
||||||
|
|
||||||
for (String subclass : subclassIds) {
|
for (String subclass : subclassIds) {
|
||||||
final Quark<Entity> subclassQuark = diagram.quarkInContext(true, subclass);
|
final Quark<Entity> subclassQuark = diagram.quarkInContext(true, subclass);
|
||||||
final Entity subclassEntity = subclassQuark.getData();
|
final Entity subclassEntity = subclassQuark.getData();
|
||||||
if (subclassEntity == null) {
|
if (subclassEntity == null) {
|
||||||
return CommandExecutionResult.error("No such entity: " + subclass);
|
return CommandExecutionResult.error("No such entity: " + subclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkType subclassLinkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
LinkType subclassLinkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
||||||
if (!symbol.equals("U")) {
|
if (!symbol.equals("U")) {
|
||||||
subclassLinkType = subclassLinkType.withMiddleSuperset();
|
subclassLinkType = subclassLinkType.withMiddleSuperset();
|
||||||
}
|
}
|
||||||
final Link subclassLink = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), centerEntity,
|
final Link subclassLink = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), centerEntity,
|
||||||
subclassEntity,
|
subclassEntity,
|
||||||
subclassLinkType,
|
subclassLinkType,
|
||||||
LinkArg.build(Display.NULL, 3));
|
LinkArg.build(Display.NULL, 3));
|
||||||
diagram.addLink(subclassLink);
|
diagram.addLink(subclassLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommandExecutionResult.ok();
|
return CommandExecutionResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,58 +54,58 @@ import net.sourceforge.plantuml.utils.LineLocation;
|
|||||||
|
|
||||||
public class CommandSimpleSubclass extends SingleLineCommand2<ChenEerDiagram> {
|
public class CommandSimpleSubclass extends SingleLineCommand2<ChenEerDiagram> {
|
||||||
|
|
||||||
public CommandSimpleSubclass() {
|
public CommandSimpleSubclass() {
|
||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
private static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("PARTICIPATION", "([-=])"), //
|
new RegexLeaf("PARTICIPATION", "([-=])"), //
|
||||||
new RegexLeaf("DIRECTION", "([<>])"), //
|
new RegexLeaf("DIRECTION", "([<>])"), //
|
||||||
new RegexLeaf("PARTICIPATION2", "([-=])"), //
|
new RegexLeaf("PARTICIPATION2", "([-=])"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
new RegexLeaf("NAME2", "([\\w-]+)"), //
|
new RegexLeaf("NAME2", "([\\w-]+)"), //
|
||||||
RegexLeaf.end());
|
RegexLeaf.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||||
throws NoSuchColorException {
|
throws NoSuchColorException {
|
||||||
String name1 = diagram.cleanId(arg.get("NAME1", 0));
|
String name1 = diagram.cleanId(arg.get("NAME1", 0));
|
||||||
String name2 = diagram.cleanId(arg.get("NAME2", 0));
|
String name2 = diagram.cleanId(arg.get("NAME2", 0));
|
||||||
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
|
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
|
||||||
final boolean isSuperset = arg.get("DIRECTION", 0).equals(">");
|
final boolean isSuperset = arg.get("DIRECTION", 0).equals(">");
|
||||||
|
|
||||||
final Quark<Entity> quark1 = diagram.quarkInContext(true, name1);
|
final Quark<Entity> quark1 = diagram.quarkInContext(true, name1);
|
||||||
final Entity entity1 = quark1.getData();
|
final Entity entity1 = quark1.getData();
|
||||||
if (entity1 == null) {
|
if (entity1 == null) {
|
||||||
return CommandExecutionResult.error("No such entity: " + name1);
|
return CommandExecutionResult.error("No such entity: " + name1);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Quark<Entity> quark2 = diagram.quarkInContext(true, name2);
|
final Quark<Entity> quark2 = diagram.quarkInContext(true, name2);
|
||||||
final Entity entity2 = quark2.getData();
|
final Entity entity2 = quark2.getData();
|
||||||
if (entity2 == null) {
|
if (entity2 == null) {
|
||||||
return CommandExecutionResult.error("No such entity: " + name2);
|
return CommandExecutionResult.error("No such entity: " + name2);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
|
||||||
if (isDouble) {
|
if (isDouble) {
|
||||||
linkType = linkType.goBold();
|
linkType = linkType.goBold();
|
||||||
}
|
}
|
||||||
if (isSuperset) {
|
if (isSuperset) {
|
||||||
linkType = linkType.withMiddleSuperset();
|
linkType = linkType.withMiddleSuperset();
|
||||||
} else {
|
} else {
|
||||||
linkType = linkType.withMiddleSubset();
|
linkType = linkType.withMiddleSubset();
|
||||||
}
|
}
|
||||||
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity1, entity2,
|
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity1, entity2,
|
||||||
linkType,
|
linkType,
|
||||||
LinkArg.build(Display.NULL, 3));
|
LinkArg.build(Display.NULL, 3));
|
||||||
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
|
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
|
||||||
diagram.addLink(link);
|
diagram.addLink(link);
|
||||||
|
|
||||||
return CommandExecutionResult.ok();
|
return CommandExecutionResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user