Prevent unnecessary exception logging in DescriptionTooltipRule 85/785/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 1 Aug 2017 11:52:19 +0000 (14:52 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 1 Aug 2017 11:58:50 +0000 (14:58 +0300)
refs #7393

Change-Id: Ifd473d11d0987f112c2bf616f2619d05cdf7c055

bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tooltips/DescriptionTooltipRule.java

index 7bef8e22c127bf00946f7c35f92c8c3f48bcb403..a9ebb9dfcbe26e2aa4e9ba1ff16d46be1ddb9699 100644 (file)
@@ -18,9 +18,9 @@ import org.simantics.db.layer0.variable.Variable;
 import org.simantics.layer0.Layer0;
 
 public class DescriptionTooltipRule implements TooltipRule {
-    
+
     public static final DescriptionTooltipRule INSTANCE = new DescriptionTooltipRule();
-    
+
     public DescriptionTooltipRule() {
     }
 
@@ -58,28 +58,26 @@ public class DescriptionTooltipRule implements TooltipRule {
     public boolean isCompatible(Class<?> contentType) {
         return (contentType == Resource.class || contentType == Variable.class);
     }
-    
+
     private static String getToolTipContent(ReadGraph graph, NodeContext nodeContext) throws DatabaseException {
         Object input = nodeContext.getConstant(BuiltinKeys.INPUT);
-        String content = null;
         if (input instanceof Variable) {
             Variable var = (Variable) input;
-            Resource res = var.getPredicateResource(graph);
-            Layer0 L0 = Layer0.getInstance(graph);
-            String description = graph.getPossibleRelatedValue2(res, L0.HasDescription);
-            return description;
+            Resource res = var.getPossiblePredicateResource(graph);
+            if (res != null) {
+                Layer0 L0 = Layer0.getInstance(graph);
+                return graph.getPossibleRelatedValue2(res, L0.HasDescription);
+            }
         } else if (input instanceof Resource) {
             Resource res = (Resource) input;
-
             Layer0 L0 = Layer0.getInstance(graph);
-            String description = graph.getPossibleRelatedValue2(res, L0.HasDescription);
-            return description;
+            return graph.getPossibleRelatedValue2(res, L0.HasDescription);
         }
-        return content;
+        return null;
     }
 
     @Override
-    public boolean shouldCreateToolTip(ReadGraph graph  , NodeContext context, Map<Object, Object> auxiliary) throws DatabaseException {
+    public boolean shouldCreateToolTip(ReadGraph graph, NodeContext context, Map<Object, Object> auxiliary) throws DatabaseException {
         String content = getToolTipContent(graph, context);
         if (content == null || content.isEmpty())
             return false;