]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java
Updates for dynamic visualisations
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / visualisations / DynamicVisualisationsContributions.java
index 6c25d237886fc82825045d7f45e08c257511a5e6..e3ede04fb970053c87d17962f2fbf398ab140e98 100644 (file)
@@ -64,7 +64,8 @@ public class DynamicVisualisationsContributions {
                         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);
                 }
@@ -93,7 +94,8 @@ public class DynamicVisualisationsContributions {
                         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);
                 }
@@ -145,27 +147,17 @@ public class DynamicVisualisationsContributions {
         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;
     }
@@ -194,67 +186,25 @@ public class DynamicVisualisationsContributions {
         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, getDynamicEdgeArrowContributionSupplier(moduleURI, ARROW_CONTRIBUTION));
+            return new DynamicArrowObject(moduleType, getContributionSupplier(moduleURI, ARROW_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();
-            }
-        };
-    }
-
-    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 Supplier<Stream<DynamicArrowContribution>> getDynamicEdgeArrowContributionSupplier(String uri, String expressionText) {
+    private static <T> Supplier<Stream<T>> getContributionSupplier(String uri, String expressionText) {
         return () -> {
             try {
                 @SuppressWarnings("unchecked")
-                List<DynamicArrowContribution> result = (List<DynamicArrowContribution>) 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();
             }
         };
     }
     
-    private static Supplier<Stream<DynamicSizeContribution>> getDynamicSizeContributionSupplier(String uri, String expressionText) {
-        return () -> {
-            try {
-                @SuppressWarnings("unchecked")
-                List<DynamicSizeContribution> result = (List<DynamicSizeContribution>) 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 class DynamicArrowObject {
 
         private final NamedResource arrowObject;