diff options
author | 2024-01-03 02:13:15 +0100 | |
---|---|---|
committer | 2024-01-03 13:33:55 +0100 | |
commit | 2fe65e414ff3194cdddde01bea6818bbab5290e9 (patch) | |
tree | a597343718059a2ee8727a296e817f997876f248 /subprojects/language/src | |
parent | refactor: matching node names in CLI and web (diff) | |
download | refinery-2fe65e414ff3194cdddde01bea6818bbab5290e9.tar.gz refinery-2fe65e414ff3194cdddde01bea6818bbab5290e9.tar.zst refinery-2fe65e414ff3194cdddde01bea6818bbab5290e9.zip |
feat(web): color identifiers and nodes
We use a palette-based coloring strategy, where each class and enum gets a color
from
Diffstat (limited to 'subprojects/language/src')
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java b/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java index cac1f265..c04c7d09 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java +++ b/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -28,6 +28,8 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
28 | public static final String ARITY = DATA_PREFIX + "ARITY"; | 28 | public static final String ARITY = DATA_PREFIX + "ARITY"; |
29 | public static final String ERROR_PREDICATE = DATA_PREFIX + "ERROR_PREDICATE"; | 29 | public static final String ERROR_PREDICATE = DATA_PREFIX + "ERROR_PREDICATE"; |
30 | public static final String ERROR_PREDICATE_TRUE = "true"; | 30 | public static final String ERROR_PREDICATE_TRUE = "true"; |
31 | public static final String COLOR_RELATION = DATA_PREFIX + "COLOR_RELATION"; | ||
32 | public static final String COLOR_RELATION_TRUE = "true"; | ||
31 | 33 | ||
32 | @Inject | 34 | @Inject |
33 | private IQualifiedNameConverter qualifiedNameConverter; | 35 | private IQualifiedNameConverter qualifiedNameConverter; |
@@ -44,12 +46,9 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
44 | var problem = EcoreUtil2.getContainerOfType(eObject, Problem.class); | 46 | var problem = EcoreUtil2.getContainerOfType(eObject, Problem.class); |
45 | var problemQualifiedName = getNameAsQualifiedName(problem); | 47 | var problemQualifiedName = getNameAsQualifiedName(problem); |
46 | var userData = getUserData(eObject); | 48 | var userData = getUserData(eObject); |
47 | boolean nameExported; | 49 | QualifiedName lastQualifiedNameToExport = null; |
48 | if (shouldExportSimpleName(eObject)) { | 50 | if (shouldExportSimpleName(eObject)) { |
49 | acceptEObjectDescription(eObject, problemQualifiedName, qualifiedName, userData, acceptor); | 51 | lastQualifiedNameToExport = qualifiedName; |
50 | nameExported = true; | ||
51 | } else { | ||
52 | nameExported = false; | ||
53 | } | 52 | } |
54 | var parent = eObject.eContainer(); | 53 | var parent = eObject.eContainer(); |
55 | while (parent != null && parent != problem) { | 54 | while (parent != null && parent != problem) { |
@@ -60,16 +59,18 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
60 | } | 59 | } |
61 | qualifiedName = parentQualifiedName.append(qualifiedName); | 60 | qualifiedName = parentQualifiedName.append(qualifiedName); |
62 | if (shouldExportSimpleName(parent)) { | 61 | if (shouldExportSimpleName(parent)) { |
63 | acceptEObjectDescription(eObject, problemQualifiedName, qualifiedName, userData, acceptor); | 62 | if (lastQualifiedNameToExport != null) { |
64 | nameExported = true; | 63 | acceptEObjectDescription(eObject, problemQualifiedName, lastQualifiedNameToExport, userData, |
65 | } else { | 64 | acceptor); |
66 | nameExported = false; | 65 | } |
66 | lastQualifiedNameToExport = qualifiedName; | ||
67 | } | 67 | } |
68 | parent = parent.eContainer(); | 68 | parent = parent.eContainer(); |
69 | } | 69 | } |
70 | if (!nameExported) { | 70 | if (lastQualifiedNameToExport == null) { |
71 | acceptEObjectDescription(eObject, problemQualifiedName, qualifiedName, userData, acceptor); | 71 | lastQualifiedNameToExport = qualifiedName; |
72 | } | 72 | } |
73 | acceptEObjectDescription(eObject, problemQualifiedName, lastQualifiedNameToExport, userData, true, acceptor); | ||
73 | return true; | 74 | return true; |
74 | } | 75 | } |
75 | 76 | ||
@@ -120,8 +121,31 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
120 | 121 | ||
121 | private void acceptEObjectDescription(EObject eObject, QualifiedName prefix, QualifiedName qualifiedName, | 122 | private void acceptEObjectDescription(EObject eObject, QualifiedName prefix, QualifiedName qualifiedName, |
122 | Map<String, String> userData, IAcceptor<IEObjectDescription> acceptor) { | 123 | Map<String, String> userData, IAcceptor<IEObjectDescription> acceptor) { |
124 | acceptEObjectDescription(eObject, prefix, qualifiedName, userData, false, acceptor); | ||
125 | } | ||
126 | |||
127 | private void acceptEObjectDescription(EObject eObject, QualifiedName prefix, QualifiedName qualifiedName, | ||
128 | Map<String, String> userData, boolean fullyQualified, | ||
129 | IAcceptor<IEObjectDescription> acceptor) { | ||
123 | var qualifiedNameWithPrefix = prefix == null ? qualifiedName : prefix.append(qualifiedName); | 130 | var qualifiedNameWithPrefix = prefix == null ? qualifiedName : prefix.append(qualifiedName); |
124 | var description = EObjectDescription.create(qualifiedNameWithPrefix, eObject, userData); | 131 | Map<String, String> userDataWithFullyQualified; |
132 | if (fullyQualified && shouldColorRelation(eObject)) { | ||
133 | userDataWithFullyQualified = ImmutableMap.<String, String>builder() | ||
134 | .putAll(userData) | ||
135 | .put(COLOR_RELATION, COLOR_RELATION_TRUE) | ||
136 | .build(); | ||
137 | } else { | ||
138 | userDataWithFullyQualified = userData; | ||
139 | } | ||
140 | var description = EObjectDescription.create(qualifiedNameWithPrefix, eObject, userDataWithFullyQualified); | ||
125 | acceptor.accept(description); | 141 | acceptor.accept(description); |
126 | } | 142 | } |
143 | |||
144 | private boolean shouldColorRelation(EObject eObject) { | ||
145 | if (ProblemUtil.isBuiltIn(eObject)) { | ||
146 | return false; | ||
147 | } | ||
148 | return eObject instanceof ClassDeclaration || eObject instanceof EnumDeclaration; | ||
149 | |||
150 | } | ||
127 | } | 151 | } |