From: Jani Simomaa Date: Mon, 22 May 2017 08:08:58 +0000 (+0300) Subject: Merge "Console printing also for content prints" X-Git-Tag: v1.29.0~39 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=fc2c84b45f73743c48cd525e85355362444d67a5;hp=3cc1639723d8835421b8fe32e32ab708f4ffe056 Merge "Console printing also for content prints" --- diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java index 7c79e639e..c4d64b686 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java @@ -5,12 +5,19 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.ProxyVariables; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; +import org.simantics.document.server.ConsoleSCLReportingHandler; import org.simantics.document.server.JSONObject; +import org.simantics.document.server.io.IConsole; +import org.simantics.document.server.io.IConsoleSupport; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; public class URIDocumentRequest extends UnaryRead> { @@ -27,16 +34,34 @@ public class URIDocumentRequest extends UnaryRead> { return Collections.emptyList(); } - ArrayList result = new ArrayList(graph.syncRequest(new DocumentRequest(var))); - Collections.sort(result, new Comparator() { + IConsoleSupport cs = Simantics.getSession().getService(IConsoleSupport.class); + Variable root = ProxyVariables.proxyVariableRoot(graph, var); + if(root == null) return Collections.emptyList(); + Variable session = root.getParent(graph); + String guid = session.getName(graph); + IConsole console = cs.getConsole(guid); + SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console) + : (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); + SCLContext sclContext = SCLContext.getCurrent(); + Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer); - @Override - public int compare(JSONObject o1, JSONObject o2) { - return o1.id.compareTo(o2.id); - } + try { - }); - return result; + ArrayList result = new ArrayList(graph.syncRequest(new DocumentRequest(var))); + Collections.sort(result, new Comparator() { + + @Override + public int compare(JSONObject o1, JSONObject o2) { + return o1.id.compareTo(o2.id); + } + + }); + + return result; + + } finally { + sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); + } }