1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.document.function;
\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
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
34 @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
\r
35 public static String documentationText(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
\r
37 DocumentResource DOC = DocumentResource.getInstance(graph);
\r
38 Variable sel = ScenegraphLoaderUtils.getVariableSelection(graph, context);
\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
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
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
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
70 return result.toString();
\r