--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2012 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.document.function;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.document.DocumentResource;\r
+import org.simantics.document.DocumentSettings;\r
+import org.simantics.document.DocumentUtils;\r
+import org.simantics.document.Exportable;\r
+import org.simantics.document.node.Composite;\r
+import org.simantics.scenegraph.loader.ScenegraphLoaderProcess;\r
+import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+\r
+public class All {\r
+ \r
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")\r
+ public static Variable documentationRootVariable(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+ return ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
+ }\r
+\r
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+ public static String documentationText(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+ \r
+ DocumentResource DOC = DocumentResource.getInstance(graph);\r
+ Variable sel = ScenegraphLoaderUtils.getVariableSelection(graph, context);\r
+ \r
+ Resource represents = sel.getPossibleRepresents(graph);\r
+ Resource doc = graph.getSingleObject(represents, DOC.HasDocumentation);\r
+ Resource scenegraph = graph.getSingleObject(doc, DOC.ScenegraphDocument_scenegraph);\r
+ \r
+ ScenegraphLoaderProcess loader = new ScenegraphLoaderProcess(new Composite(), "All.documentationText");\r
+ WikiDocumentNodeImpl node = loader.load(graph, scenegraph, ScenegraphLoaderUtils.getRuntime(graph, context));\r
+ StringBuilder b = new StringBuilder();\r
+ node.create(b, false);\r
+ loader.dispose();\r
+\r
+ DocumentUtils du = new DocumentUtils();\r
+ StringBuilder css = new StringBuilder();\r
+ du.getDocumentCSSText(graph, represents, css);\r
+ DocumentSettings settings = du.getDocumentSettings(graph, represents);\r
+ Exportable e = new Exportable(graph, represents, b.toString(), css.toString(), settings, false);\r
+ return e.getHTML();\r
+ \r
+ }\r
+ \r
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+ public static String standardEditText(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {\r
+ Variable location = context.getParent(graph);\r
+ StringBuilder result = new StringBuilder();\r
+ String path = ScenegraphLoaderUtils.getPath(graph, location);\r
+ for(Variable property : location.browseProperties(graph)) {\r
+ if(property.getPossibleProperty(graph, "userProperty") != null) {\r
+ String name = property.getName(graph);\r
+ result.append("[http://variable" + path + "#" + name + " [edit " + name + "]] ");\r
+ }\r
+ }\r
+ return result.toString();\r
+ }\r
+\r
+ \r
+}\r