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;
@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 {
});
} 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) {
}
public static String printContext(CommandContext context) {
- String str = context.toString();
- System.err.println(str);
- return str;
+ return context.toString();
}
@SCLValue(type = "AbstractEventHandler")
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