X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2FFunctions.java;h=20fa2a71b7b272cec574e351c715a17c25479f04;hp=3b99f325230851441f7f19c1c45709b8446e5a69;hb=d49167ad01099b4c35705d702b3ddc89160b42a1;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 3b99f3252..20fa2a71b 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -1,5 +1,7 @@ package org.simantics.document.server; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -49,6 +51,7 @@ import org.simantics.document.server.io.CommandContext; import org.simantics.document.server.io.CommandContextImpl; import org.simantics.document.server.io.CommandContextMutable; import org.simantics.document.server.io.CommandResult; +import org.simantics.document.server.io.IConsole; import org.simantics.document.server.request.ServerSCLHandlerValueRequest; import org.simantics.document.server.request.ServerSCLValueRequest; import org.simantics.document.server.serverResponse.ServerResponse; @@ -651,6 +654,11 @@ public class Functions { message.append(" handler=" + path + "\n"); message.append(" expression=" + expr + "\n"); message.append(" message=" + t.getMessage() + "\n"); + + StringWriter sw = new StringWriter(); + t.printStackTrace(new PrintWriter(sw)); + message.append(" stack trace=" + sw); + return message.toString(); } @@ -667,7 +675,9 @@ public class Functions { @Override public CommandResult handle(final CommandContext parameters) { - final SCLReportingHandler printer = (SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); + IConsole console = parameters.getValue("__console__"); + SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console) + : (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); try { @@ -720,7 +730,15 @@ public class Functions { }); } else { - result = fn.apply(parameters); + + SCLContext sclContext = SCLContext.getCurrent(); + Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer); + try { + result = fn.apply(parameters); + } finally { + sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); + } + } if (result instanceof org.simantics.document.server.serverResponse.Error) { @@ -963,9 +981,7 @@ public class Functions { } public static String printContext(CommandContext context) { - String str = context.toString(); - System.err.println(str); - return str; + return context.toString(); } @SCLValue(type = "AbstractEventHandler") @@ -1157,4 +1173,35 @@ public class Functions { return graph.syncRequest(new PathExistsRequest(context)); } + static class ConsoleSCLReportingHandler implements SCLReportingHandler { + + private final IConsole console; + + ConsoleSCLReportingHandler(IConsole console) { + this.console = console; + } + + @Override + public void print(String text) { + console.addMessage(text); + } + + @Override + public void printError(String error) { + console.addMessage(error); + } + + @Override + public void printCommand(String command) { + console.addMessage(command); + } + + @Override + public void didWork(double amount) { + console.addMessage("didWork " + amount); + } + + } + + } \ No newline at end of file