]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Support also Resource inputs in standardIssueContexts property function
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 3 Mar 2017 12:43:11 +0000 (14:43 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 28 Apr 2017 13:16:20 +0000 (16:16 +0300)
Previous version only supported Variables.

refs #7064

Change-Id: If309d7c3d6c8d0b270a8344d3abaf9061e92da31

bundles/org.simantics.issues.common/src/org/simantics/issues/common/All.java

index 9173101eee8d77e57f218791d551ac9d2e5f6ff5..d2120cd78345d7fdccfcc7dcbb76d7e6d125c914 100644 (file)
@@ -1,11 +1,13 @@
 package org.simantics.issues.common;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.PossibleIndexRoot;
+import org.simantics.db.common.utils.ListUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
@@ -77,9 +79,20 @@ public class All {
        }
     }
 
-    @SCLValue(type = "ReadGraph -> Resource -> Variable -> [Resource]")
-    public static List<Resource> standardIssueContexts(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
-        return IssueUtils.getContextsForProperty(graph, property);
+    @SCLValue(type = "ReadGraph -> Resource -> a -> [Resource]")
+    public static List<Resource> standardIssueContexts(ReadGraph graph, Resource converter, Object property) throws DatabaseException {
+        if (property instanceof Variable) {
+            return IssueUtils.getContextsForProperty(graph, (Variable) property);
+        } else if (property instanceof Resource) {
+            Resource issue = (Resource) property;
+            IssueResource ISSUE = IssueResource.getInstance(graph);
+            Resource list = graph.getPossibleObject(issue, ISSUE.Issue_HasContexts);
+            if(list != null)
+                return ListUtils.toList(graph, list);
+            else
+                return Collections.emptyList();
+        }
+        throw new IllegalArgumentException("Unsupported property type: " + property);
     }
 
 }