]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.views/src/org/simantics/views/All.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.views / src / org / simantics / views / All.java
diff --git a/bundles/org.simantics.views/src/org/simantics/views/All.java b/bundles/org.simantics.views/src/org/simantics/views/All.java
new file mode 100644 (file)
index 0000000..941213f
--- /dev/null
@@ -0,0 +1,130 @@
+package org.simantics.views;\r
+\r
+import java.io.IOException;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.eclipse.core.runtime.FileLocator;\r
+import org.eclipse.core.runtime.Path;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.osgi.framework.Bundle;\r
+import org.simantics.databoard.util.StreamUtil;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+import org.simantics.views.ViewUtils.ColumnBean;\r
+import org.simantics.views.ontology.ViewsResources;\r
+\r
+public class All {\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object resourceURI(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       \r
+       ViewsResources VIEW = ViewsResources.getInstance(graph);\r
+       Resource resource = graph.getSingleObject(converter, VIEW.ResourceURI_HasResource);\r
+       return graph.getURI(resource);\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object parameterValue(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       \r
+       Variable runtime = ScenegraphLoaderUtils.getRuntimeVariable(graph, context);\r
+       Variable base = ScenegraphLoaderUtils.getBaseVariable(graph, context);\r
+       //System.err.println("parameterValue " + context.getURI(graph) + " " + base.getURI(graph) + " " + runtime.getURI(graph));\r
+       String rvi = context.getURI(graph).substring(base.getURI(graph).length());\r
+       //System.err.println("rvi " + rvi);\r
+       Variable parameter = runtime.browse(graph, rvi);\r
+       return parameter.getValue(graph);\r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> Resource")\r
+    public static Resource singleResourceSelection(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+       return ScenegraphLoaderUtils.getPossibleResourceSelection(graph, context);\r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> [String]")\r
+    public static List<String> tabChildNames(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       \r
+       Collection<Variable> children = context.getParent(graph).getChildren(graph);\r
+       \r
+       List<String> result = new ArrayList<String>();\r
+\r
+               for(Variable child : children) {\r
+                       String label = child.getPropertyValue(graph, Variables.LABEL); \r
+                       result.add(label);\r
+               }\r
+               \r
+               return result;          \r
+        \r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object bundleImage(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       \r
+       ViewsResources VIEW = ViewsResources.getInstance(graph);\r
+       String reference = graph.getRelatedValue(converter, VIEW.BundleImage_HasReference);\r
+       \r
+       String[] parts = reference.split(":");\r
+       if(parts.length != 2) return null;\r
+       \r
+        Bundle bundle = Platform.getBundle(parts[0]);\r
+        \r
+        if (bundle == null) {\r
+            throw new IllegalArgumentException("null bundle");\r
+        }\r
+\r
+        // look for the image (this will check both the plugin and fragment folders\r
+        URL fullPathString = FileLocator.find(bundle, new Path(parts[1]), null);\r
+        if (fullPathString == null) {\r
+            try {\r
+                fullPathString = new URL(parts[1]);\r
+            } catch (MalformedURLException e) {\r
+                return null;\r
+            }\r
+        }\r
+        \r
+        try {\r
+                       return StreamUtil.readFully(fullPathString.openStream());\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+                       return null;\r
+               }\r
+        \r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object gridData(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       return ViewUtils.getGridData(graph, converter);\r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object gridLayout(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       return ViewUtils.getLayout(graph, converter);\r
+    }\r
+\r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")\r
+    public static Object style(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {\r
+       return ViewUtils.getStyle(graph, converter);\r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> a -> b")\r
+    public static Object columnList(ReadGraph graph, Resource resource, Object context) throws DatabaseException {\r
+       ArrayList<ColumnBean> result = new ArrayList<ColumnBean>();\r
+       for(Resource item : ListUtils.toList(graph, resource)) {\r
+               result.add(ViewUtils.getColumn(graph, item));\r
+       }\r
+       return result;\r
+    }\r
+    \r
+    \r
+}
\ No newline at end of file