X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Freport%2Ftemplates%2Fcustom%2FSCLCustomizableContent.java;fp=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Freport%2Ftemplates%2Fcustom%2FSCLCustomizableContent.java;h=09fb371948deb5e592b2b1dc5ed5a47f4c08a3fc;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=907c74c57de421a146319dd12aa1fa41d9706281;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/custom/SCLCustomizableContent.java b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/custom/SCLCustomizableContent.java index 907c74c57..09fb37194 100644 --- a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/custom/SCLCustomizableContent.java +++ b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/custom/SCLCustomizableContent.java @@ -1,93 +1,93 @@ -package org.simantics.document.linking.report.templates.custom; - -import java.util.List; -import java.util.Map; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.document.linking.report.DocumentLine; -import org.simantics.scl.compiler.commands.CommandSession; -import org.simantics.scl.compiler.types.Types; -import org.simantics.scl.osgi.SCLOsgi; -import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler; - - - -/** - * SCL-script based customization - * - * NOTE: this does not work, since at the moment the CommandSession is not able to attach itself to given read transaction. - * - * @author Marko Luukkainen - * - */ -public class SCLCustomizableContent implements CustomizableContent { - - private CommandSession session; - private String sclCode[]; - - private String label; - - public SCLCustomizableContent(String label) { - session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null); - - sclCode = new String[]{"import \"Simantics/Ontologies\"", - "nameOfResource r = match possibleRelatedValue r L0.HasName with\n"+ - " Just name -> name\n"+ - " Nothing -> \"no name\"", - "nameOfResource res"}; - } - - @Override - public String getCustomizationDescription() { - return label; - } - - @Override - public String getContent(ReadGraph graph, Resource resource, Map context) - throws DatabaseException { - - session.setVariable("res", Types.con("Simantics/DB", "Resource"), resource); - final StringBuilder responseBuilder = new StringBuilder(); - final StringBuilder errorBuilder = new StringBuilder(); - for (String code : sclCode) { - session.execute(code, new AbstractSCLReportingHandler() { - - @Override - public void print(String text) { - responseBuilder.append(text).append('\n'); - } - - @Override - public void printError(String error) { - errorBuilder.append(error).append('\n'); - } - - @Override - public void printCommand(String command) { - } - }); - if(errorBuilder.length() > 0) - throw new DatabaseException("Error executing SCL \"" + code + "\" " + errorBuilder.toString().trim()); - } - return responseBuilder.toString().trim(); - } - - @Override - public List getLines(ReadGraph graph, Resource resource, Map context) - throws DatabaseException { - // TODO Auto-generated method stub - return null; - } - - public String[] getSclCode() { - return sclCode; - } - - public void setSclCode(String[] sclCode) { - this.sclCode = sclCode; - } - - -} +package org.simantics.document.linking.report.templates.custom; + +import java.util.List; +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.document.linking.report.DocumentLine; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.compiler.types.Types; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler; + + + +/** + * SCL-script based customization + * + * NOTE: this does not work, since at the moment the CommandSession is not able to attach itself to given read transaction. + * + * @author Marko Luukkainen + * + */ +public class SCLCustomizableContent implements CustomizableContent { + + private CommandSession session; + private String sclCode[]; + + private String label; + + public SCLCustomizableContent(String label) { + session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null); + + sclCode = new String[]{"import \"Simantics/Ontologies\"", + "nameOfResource r = match possibleRelatedValue r L0.HasName with\n"+ + " Just name -> name\n"+ + " Nothing -> \"no name\"", + "nameOfResource res"}; + } + + @Override + public String getCustomizationDescription() { + return label; + } + + @Override + public String getContent(ReadGraph graph, Resource resource, Map context) + throws DatabaseException { + + session.setVariable("res", Types.con("Simantics/DB", "Resource"), resource); + final StringBuilder responseBuilder = new StringBuilder(); + final StringBuilder errorBuilder = new StringBuilder(); + for (String code : sclCode) { + session.execute(code, new AbstractSCLReportingHandler() { + + @Override + public void print(String text) { + responseBuilder.append(text).append('\n'); + } + + @Override + public void printError(String error) { + errorBuilder.append(error).append('\n'); + } + + @Override + public void printCommand(String command) { + } + }); + if(errorBuilder.length() > 0) + throw new DatabaseException("Error executing SCL \"" + code + "\" " + errorBuilder.toString().trim()); + } + return responseBuilder.toString().trim(); + } + + @Override + public List getLines(ReadGraph graph, Resource resource, Map context) + throws DatabaseException { + // TODO Auto-generated method stub + return null; + } + + public String[] getSclCode() { + return sclCode; + } + + public void setSclCode(String[] sclCode) { + this.sclCode = sclCode; + } + + +}