1 package org.simantics.views;
\r
3 import java.io.IOException;
\r
4 import java.net.MalformedURLException;
\r
6 import java.util.ArrayList;
\r
7 import java.util.Collection;
\r
8 import java.util.List;
\r
10 import org.eclipse.core.runtime.FileLocator;
\r
11 import org.eclipse.core.runtime.Path;
\r
12 import org.eclipse.core.runtime.Platform;
\r
13 import org.osgi.framework.Bundle;
\r
14 import org.simantics.databoard.util.StreamUtil;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.common.utils.ListUtils;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.db.layer0.variable.Variable;
\r
20 import org.simantics.db.layer0.variable.Variables;
\r
21 import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;
\r
22 import org.simantics.scl.reflection.annotations.SCLValue;
\r
23 import org.simantics.views.ViewUtils.ColumnBean;
\r
24 import org.simantics.views.ontology.ViewsResources;
\r
28 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
29 public static Object resourceURI(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
31 ViewsResources VIEW = ViewsResources.getInstance(graph);
\r
32 Resource resource = graph.getSingleObject(converter, VIEW.ResourceURI_HasResource);
\r
33 return graph.getURI(resource);
\r
37 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
38 public static Object parameterValue(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
40 Variable runtime = ScenegraphLoaderUtils.getRuntimeVariable(graph, context);
\r
41 Variable base = ScenegraphLoaderUtils.getBaseVariable(graph, context);
\r
42 //System.err.println("parameterValue " + context.getURI(graph) + " " + base.getURI(graph) + " " + runtime.getURI(graph));
\r
43 String rvi = context.getURI(graph).substring(base.getURI(graph).length());
\r
44 //System.err.println("rvi " + rvi);
\r
45 Variable parameter = runtime.browse(graph, rvi);
\r
46 return parameter.getValue(graph);
\r
50 @SCLValue(type = "ReadGraph -> Resource -> Variable -> Resource")
\r
51 public static Resource singleResourceSelection(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
\r
52 return ScenegraphLoaderUtils.getPossibleResourceSelection(graph, context);
\r
55 @SCLValue(type = "ReadGraph -> Resource -> Variable -> [String]")
\r
56 public static List<String> tabChildNames(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
58 Collection<Variable> children = context.getParent(graph).getChildren(graph);
\r
60 List<String> result = new ArrayList<String>();
\r
62 for(Variable child : children) {
\r
63 String label = child.getPropertyValue(graph, Variables.LABEL);
\r
71 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
72 public static Object bundleImage(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
74 ViewsResources VIEW = ViewsResources.getInstance(graph);
\r
75 String reference = graph.getRelatedValue(converter, VIEW.BundleImage_HasReference);
\r
77 String[] parts = reference.split(":");
\r
78 if(parts.length != 2) return null;
\r
80 Bundle bundle = Platform.getBundle(parts[0]);
\r
82 if (bundle == null) {
\r
83 throw new IllegalArgumentException("null bundle");
\r
86 // look for the image (this will check both the plugin and fragment folders
\r
87 URL fullPathString = FileLocator.find(bundle, new Path(parts[1]), null);
\r
88 if (fullPathString == null) {
\r
90 fullPathString = new URL(parts[1]);
\r
91 } catch (MalformedURLException e) {
\r
97 return StreamUtil.readFully(fullPathString.openStream());
\r
98 } catch (IOException e) {
\r
99 e.printStackTrace();
\r
105 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
106 public static Object gridData(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
107 return ViewUtils.getGridData(graph, converter);
\r
110 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
111 public static Object gridLayout(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
112 return ViewUtils.getLayout(graph, converter);
\r
115 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
116 public static Object rowData(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
117 return ViewUtils.getRowData(graph, converter);
\r
120 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
121 public static Object rowLayout(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
122 return ViewUtils.getRowLayout(graph, converter);
\r
125 @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
\r
126 public static Object style(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
\r
127 return ViewUtils.getStyle(graph, converter);
\r
130 @SCLValue(type = "ReadGraph -> Resource -> a -> b")
\r
131 public static Object columnList(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
\r
132 ArrayList<ColumnBean> result = new ArrayList<ColumnBean>();
\r
133 for(Resource item : ListUtils.toList(graph, resource)) {
\r
134 result.add(ViewUtils.getColumn(graph, item));
\r