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