1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 19:09:03 +00:00

Tweak Chen EER syntax to be more consistent with existing diagram types

This commit is contained in:
Benjamin Davies 2023-11-16 09:43:54 +13:00
parent c91b5e2015
commit e26ccf756a
No known key found for this signature in database
GPG Key ID: 9FFDE0674336C460
3 changed files with 25 additions and 35 deletions

View File

@ -59,8 +59,8 @@ public class ChenEerDiagramFactory extends PSystemCommandFactory {
@Override
protected void initCommandsList(List<Command> cmds) {
cmds.add(new CommandCreateEntity());
cmds.add(new CommandCreateAttribute());
cmds.add(new CommandCreateRelationship());
cmds.add(new CommandCreateAttribute());
cmds.add(new CommandAssociateRelationship());
cmds.add(new CommandEndGroup());

View File

@ -61,37 +61,41 @@ public class CommandAssociateRelationship extends SingleLineCommand2<ChenEerDiag
private static IRegex getRegexConcat() {
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
new RegexLeaf("NAME1", "([\\w-]+)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("PARTICIPATION", "([-=])"), //
new RegexOptional( //
new RegexLeaf("CARDINALITY", "(\\w+|\\(\\w+,[%s]*\\w+\\))")), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("NAME", "([\\w-]+)"), //
new RegexLeaf("PARTICIPATION2", "([-=])"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("NAME2", "([\\w-]+)"), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
final Entity relationship = diagram.peekOwner();
if (relationship == null) {
return CommandExecutionResult.error("Can only associate from a relationship");
final String name1 = diagram.cleanId(arg.get("NAME1", 0));
final String name2 = diagram.cleanId(arg.get("NAME2", 0));
final Quark<Entity> quark1 = diagram.quarkInContext(true, name1);
final Entity entity1 = quark1.getData();
if (entity1 == null) {
return CommandExecutionResult.error("No such entity: " + name1);
}
final String entityName = diagram.cleanId(arg.get("NAME", 0));
final Quark<Entity> entityQuark = diagram.quarkInContext(true, entityName);
final Entity entity = entityQuark.getData();
if (entity == null) {
return CommandExecutionResult.error("No such entity: " + entityName);
final Quark<Entity> quark2 = diagram.quarkInContext(true, name2);
final Entity entity2 = quark2.getData();
if (entity2 == null) {
return CommandExecutionResult.error("No such entity: " + name2);
}
final LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), relationship, entity,
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity1, entity2,
linkType,
// TODO: Cardinality
LinkArg.build(Display.NULL, 3));
link.setPortMembers(diagram.getPortId(relationship.getName()), diagram.getPortId(entity.getName()));
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
diagram.addLink(link);
return CommandExecutionResult.ok();

View File

@ -63,27 +63,11 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
private static IRegex getRegexConcat() {
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(),
new RegexOptional( //
new RegexConcat( //
new RegexLeaf("MULTI", "multi"), //
RegexLeaf.spaceOneOrMore())), //
new RegexOptional( //
new RegexConcat( //
new RegexLeaf("DERIVED", "derived"), //
RegexLeaf.spaceOneOrMore())), //
new RegexOptional( //
new RegexConcat( //
new RegexOptional( //
new RegexConcat( //
new RegexLeaf("PARTIAL", "partial"), //
RegexLeaf.spaceOneOrMore())),
new RegexLeaf("KEY", "key"), //
RegexLeaf.spaceOneOrMore())), //
new RegexOptional( //
new RegexConcat( //
new RegexLeaf("attr(:?ibute)?"), //
RegexLeaf.spaceOneOrMore())), //
new RegexLeaf("NAME", "(\\w+)"), //
new RegexLeaf("NAME", "([^<>{}-]+)"), //
new RegexOptional(//
new RegexConcat(
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREOTYPE", "(<<.+>>)"))), //
new RegexOptional(//
new RegexConcat( //
RegexLeaf.spaceZeroOrMore(), //
@ -104,6 +88,8 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
final String id = owner.getName() + "/" + name;
final boolean composite = arg.get("COMPOSITE", 0) != null;
// TODO: stereotypes: multi, derived, key, partial key
final Quark<Entity> quark = diagram.quarkInContext(true, id);
Entity entity = quark.getData();