]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueImageRule.java
Preliminary support for purely Variable based dynamic issue sources
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / IssueImageRule.java
index b19a1f711ed507e7099f9258f92bc1f3e6ec2f7d..10de114c780b55a6b2cb1162940fc57d6ecc7053 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2017 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - #6948
  *******************************************************************************/
 package org.simantics.issues.ui;
 
@@ -31,6 +32,25 @@ public class IssueImageRule implements ImageRule {
 
     private final String DESCRIPTION = ColumnKeys.SINGLE;
 
+    private final ImageDescriptor tick;
+    private final ImageDescriptor fatal;
+    private final ImageDescriptor error;
+    private final ImageDescriptor warning;
+    private final ImageDescriptor info;
+    private final ImageDescriptor note;
+    private final ImageDescriptor help;
+
+    public IssueImageRule(ReadGraph graph) throws DatabaseException {
+        SilkResources SILK = SilkResources.getInstance(graph);
+        tick = graph.adapt(SILK.tick, ImageDescriptor.class);
+        fatal = graph.adapt(SILK.bomb, ImageDescriptor.class);
+        error = graph.adapt(SILK.exclamation, ImageDescriptor.class);
+        warning = graph.adapt(SILK.error, ImageDescriptor.class);
+        info = graph.adapt(SILK.information, ImageDescriptor.class);
+        note = graph.adapt(SILK.note, ImageDescriptor.class);
+        help = graph.adapt(SILK.help, ImageDescriptor.class);
+    }
+
     @Override
     public boolean isCompatible(Class<?> contentType) {
         return contentType.equals(Variable.class);
@@ -38,26 +58,32 @@ public class IssueImageRule implements ImageRule {
 
     @Override
     public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
+        Variable issue = (Variable) content;
+        String severity = issue.getPossiblePropertyValue(graph, "severity");
+        if (severity == null)
+            return Collections.emptyMap();
+        boolean resolved = isResolved(graph, issue);
+        return Collections.singletonMap(DESCRIPTION, resolved ? tick : toImageDescriptor(severity));
+    }
 
-        Variable issue = (Variable)content;
-
-        IssueResource ISSUE = IssueResource.getInstance(graph);
-        SilkResources SILK = SilkResources.getInstance(graph);
-        String severity = issue.getPropertyValue(graph, "severity");
-
-        // TODO: now to do this with variables?
+    public boolean isResolved(ReadGraph graph, Variable issue) throws DatabaseException {
         Resource issueResource = issue.getPossibleRepresents(graph);
-        boolean resolved = issueResource != null ? graph.hasStatement(issueResource, ISSUE.Resolved) : false;
-        if (resolved)
-            return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.tick, ImageDescriptor.class));
+        if (issueResource != null)
+            return graph.hasStatement(issueResource, IssueResource.getInstance(graph).Resolved);
 
-        if("Fatal".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.bomb, ImageDescriptor.class));
-        else if("Error".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.exclamation, ImageDescriptor.class));
-        else if("Warning".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.error, ImageDescriptor.class));
-        else if("Info".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.information, ImageDescriptor.class));
-        else if("Note".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.note, ImageDescriptor.class));
-        else return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.help, ImageDescriptor.class));
+        Boolean resolved = issue.getPossiblePropertyValue(graph, "resolved");
+        return Boolean.TRUE.equals(resolved);
+    }
 
+    private ImageDescriptor toImageDescriptor(String severity) {
+        switch (severity) {
+        case "Fatal":   return fatal;
+        case "Error":   return error;
+        case "Warning": return warning;
+        case "Info":    return info;
+        case "Note":    return note;
+        default:        return help;
+        }
     }
 
 }