]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document/src/org/simantics/document/function/All.java
Sync git svn branch with SVN repository r33153.
[simantics/platform.git] / bundles / org.simantics.document / src / org / simantics / document / function / All.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.document.function;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.db.layer0.variable.Variable;\r
18 import org.simantics.document.DocumentResource;\r
19 import org.simantics.document.DocumentSettings;\r
20 import org.simantics.document.DocumentUtils;\r
21 import org.simantics.document.Exportable;\r
22 import org.simantics.document.node.Composite;\r
23 import org.simantics.scenegraph.loader.ScenegraphLoaderProcess;\r
24 import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;\r
25 import org.simantics.scl.reflection.annotations.SCLValue;\r
26 \r
27 public class All {\r
28     \r
29     @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")\r
30     public static Variable documentationRootVariable(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
31         return ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
32     }\r
33 \r
34     @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
35     public static String documentationText(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
36         \r
37         DocumentResource DOC = DocumentResource.getInstance(graph);\r
38         Variable sel = ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
39         \r
40         Resource represents = sel.getPossibleRepresents(graph);\r
41         Resource doc = graph.getSingleObject(represents, DOC.HasDocumentation);\r
42         Resource scenegraph = graph.getSingleObject(doc, DOC.ScenegraphDocument_scenegraph);\r
43         \r
44                 ScenegraphLoaderProcess loader = new ScenegraphLoaderProcess(new Composite(), "All.documentationText");\r
45                 WikiDocumentNodeImpl node = loader.load(graph, scenegraph, ScenegraphLoaderUtils.getRuntime(graph, context));\r
46                 StringBuilder b = new StringBuilder();\r
47                 node.create(b, false);\r
48                 loader.dispose();\r
49 \r
50                 DocumentUtils du = new DocumentUtils();\r
51                 StringBuilder css = new StringBuilder();\r
52                 du.getDocumentCSSText(graph, represents, css);\r
53                 DocumentSettings settings = du.getDocumentSettings(graph, represents);\r
54                 Exportable e = new Exportable(graph, represents, b.toString(), css.toString(), settings, false);\r
55                 return e.getHTML();\r
56         \r
57     }\r
58     \r
59     @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
60     public static String standardEditText(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
61         Variable location = context.getParent(graph);\r
62         StringBuilder result = new StringBuilder();\r
63         String path = ScenegraphLoaderUtils.getPath(graph, location);\r
64         for(Variable property : location.browseProperties(graph)) {\r
65                 if(property.getPossibleProperty(graph, "userProperty") != null) {\r
66                         String name = property.getName(graph);\r
67                         result.append("[http://variable" + path + "#" + name + " [edit " + name + "]] ");\r
68                 }\r
69         }\r
70         return result.toString();\r
71     }\r
72 \r
73 }\r