X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Ffunction%2FAll.java;h=99abd9b48609858adaf3983cb7d51f17e0f0c233;hb=e34fedee69a6f7e3ef2188a70d8be60f7d179c10;hp=3a71cafb7d76a26d26058d9c2b445f02e147d9ce;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document/src/org/simantics/document/function/All.java b/bundles/org.simantics.document/src/org/simantics/document/function/All.java index 3a71cafb7..99abd9b48 100644 --- a/bundles/org.simantics.document/src/org/simantics/document/function/All.java +++ b/bundles/org.simantics.document/src/org/simantics/document/function/All.java @@ -1,74 +1,73 @@ -/******************************************************************************* - * 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(); - } - - -} +/******************************************************************************* + * 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(); + } + +}