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