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