import org.simantics.db.common.request.ObjectsWithSupertype;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.district.network.visualisations.model.DynamicArrowContribution;
import org.simantics.district.network.visualisations.model.DynamicColorContribution;
import org.simantics.district.network.visualisations.model.DynamicColorMap;
import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
private static final String DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE = "DynamicVisualisationsContribution";
private static final String COLOR_CONTRIBUTION = "colorContribution";
private static final String SIZE_CONTRIBUTION = "sizeContribution";
+ private static final String ARROW_CONTRIBUTION = "arrowContribution";
public static Map<String, DynamicColorMap> dynamicColorMaps(ReadGraph graph) throws DatabaseException {
List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
results.put(colorMap.getLabel(), colorMap);
}
} catch (ValueNotFound e) {
- e.printStackTrace();
+ // ignore
+ LOGGER.debug("Dynamic color maps not found for {}", sclModule, e);
} finally {
SCLContext.getCurrent().put("graph", oldGraph);
}
results.put(sizeMap.getLabel(), sizeMap);
}
} catch (ValueNotFound e) {
- e.printStackTrace();
+ // ignore
+ LOGGER.debug("Dynamic size maps not found for {}", sclModule, e);
} finally {
SCLContext.getCurrent().put("graph", oldGraph);
}
Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
if (sclModule != null) {
String moduleURI = graph.getURI(sclModule);
- return new DynamicColoringObject(moduleType, getDynamicColorContributionSupplier(moduleURI, COLOR_CONTRIBUTION));
+ return new DynamicColoringObject(moduleType, getContributionSupplier(moduleURI, COLOR_CONTRIBUTION));
}
return null;
}
-
-// private static DynamicColoringMap dynamicColoringMap(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
-// Layer0 L0 = Layer0.getInstance(graph);
-// Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
-// if (sclModule != null) {
-// String moduleURI = graph.getURI(sclModule);
-// return new DynamicColoringMap(moduleType, getDynamicColoringMapSupplier(moduleURI, COLOR_CONTRIBUTION));
-// }
-// return null;
-// }
-
+
private static DynamicSizingObject dynamicSizingObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
if (sclModule != null) {
String moduleURI = graph.getURI(sclModule);
- return new DynamicSizingObject(moduleType, getDynamicSizeContributionSupplier(moduleURI, SIZE_CONTRIBUTION));
+ return new DynamicSizingObject(moduleType, getContributionSupplier(moduleURI, SIZE_CONTRIBUTION));
}
return null;
}
- private static Supplier<Stream<DynamicColorMap>> getDynamicColorMapSupplier(String uri, String expressionText) {
- return () -> {
- try {
- @SuppressWarnings("unchecked")
- List<DynamicColorMap> result = (List<DynamicColorMap>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
- return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9);
- } catch (ValueNotFound e) {
- LOGGER.error("Could not find contributions", e);
- //throw new RuntimeException(e);
- return Stream.empty();
+ public static Collection<DynamicArrowObject> dynamicEdgeArrowObjects(ReadGraph graph) throws DatabaseException {
+
+ List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+
+ List<DynamicArrowObject> results = new ArrayList<>();
+
+ for (Resource sharedOntology : sharedOntologies) {
+ Collection<Resource> findByType = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component));
+ //Collection<Resource> findByType = QueryIndexUtils.searchByType(graph, sharedOntology, );
+ for (Resource find : findByType) {
+ NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, find), find);
+ DynamicArrowObject dynamicarrowObject = dynamicEdgeArrowObject(graph, moduleType);
+ if (dynamicarrowObject != null)
+ results.add(dynamicarrowObject);
}
- };
+ }
+ return results;
}
-
- private static Supplier<Stream<DynamicColorContribution>> getDynamicColorContributionSupplier(String uri, String expressionText) {
- return () -> {
- try {
- @SuppressWarnings("unchecked")
- List<DynamicColorContribution> result = (List<DynamicColorContribution>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
- return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9);
- } catch (ValueNotFound e) {
- LOGGER.error("Could not find contributions", e);
- //throw new RuntimeException(e);
- return Stream.empty();
- }
- };
+
+ private static DynamicArrowObject dynamicEdgeArrowObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
+ if (sclModule != null) {
+ String moduleURI = graph.getURI(sclModule);
+ return new DynamicArrowObject(moduleType, getContributionSupplier(moduleURI, ARROW_CONTRIBUTION));
+ }
+ return null;
}
- private static Supplier<Stream<DynamicSizeContribution>> getDynamicSizeContributionSupplier(String uri, String expressionText) {
+ private static <T> Supplier<Stream<T>> getContributionSupplier(String uri, String expressionText) {
return () -> {
try {
@SuppressWarnings("unchecked")
- List<DynamicSizeContribution> result = (List<DynamicSizeContribution>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
+ List<T> result = (List<T>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9);
} catch (ValueNotFound e) {
- LOGGER.error("Could not find contributions", e);
+ LOGGER.trace("Could not find contributions for module {} and expression {}", uri, expressionText, e);
//throw new RuntimeException(e);
return Stream.empty();
}
};
}
+
+ public static class DynamicArrowObject {
+
+ private final NamedResource arrowObject;
+ private final Supplier<Stream<DynamicArrowContribution>> arrowContributionSupplier;
+ private Map<String, DynamicArrowContribution> arrowContributions;
+
+ public DynamicArrowObject(NamedResource coloringObject, Supplier<Stream<DynamicArrowContribution>> arrowContributionSupplier) {
+ this.arrowObject = coloringObject;
+ this.arrowContributionSupplier = arrowContributionSupplier;
+ }
+ public NamedResource getArrowObject() {
+ return arrowObject;
+ }
+
+ public Map<String, DynamicArrowContribution> getArrowContributions() {
+ if (arrowContributions == null)
+ arrowContributions = arrowContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c));
+ return arrowContributions;
+ }
+ }
+
public static class DynamicColoringObject {
private final NamedResource coloringObject;
colorContributions = colorContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c));
return colorContributions;
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " [" + coloringObject.getName() + " (" + coloringObject.getResource() + "), contributions=" + colorContributionsToString() + "]";
+ }
+
+ private String colorContributionsToString() {
+
+ return colorContributions.keySet().stream().map(key -> {
+ DynamicColorContribution dynamicColorContribution = colorContributions.get(key);
+ return key + "=" + dynamicColorContribution.getLabel();
+ }).collect(Collectors.joining(", ", "{", "}"));
+ }
}
public static class DynamicColoringMap {