From 2d5980a0e6c4b6f321be64612b02a04b9c3e8e0f Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Fri, 19 May 2017 14:29:13 +0300 Subject: [PATCH] Console printing also for content prints refs #7226 Change-Id: Ia95b0d5e2432d8a9a2697a9184dd268a6c1fb8ab --- .../server/request/URIDocumentRequest.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) 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); + } } -- 2.47.1