@Override
public String toString() {
StringBuilder sb = new StringBuilder();
+ sb.append("CommandContext:\n");
for (Map.Entry<String, List<List<Object>>> entry : data.entrySet()) {
- sb.append(entry.getKey());
- sb.append(":");
- sb.append(entry.getValue());
- sb.append("\n");
+ String key = entry.getKey();
+ if(key.startsWith("__")) continue;
+ sb.append(key);
+ sb.append(":");
+ List<List<Object>> value = entry.getValue();
+ if(value.size() == 1) {
+ List<Object> t = (List<Object>)value.get(0);
+ if(t.size() == 2) {
+ sb.append(t.get(1));
+ } else {
+ sb.append(t);
+ }
+ } else {
+ sb.append(value);
+ }
+ sb.append("\n");
}
return sb.toString();
}
cloneCommandContext :: CommandContext -> <Proc> CommandContextMutable
cloneCommandContext context = merge (commandContext ()) context
+instance Show CommandContext where
+ show ctx = printContext ctx
+
importJava "org.simantics.document.server.io.CommandResult" where
data CommandResult
displayValue0 :: Variable -> <ReadGraph> String
displayValue0 var = propertyValue var "HasDisplayValue"
-consoleLog :: Variable -> String -> <ReadGraph> ()
-consoleLog state message = do
- console = state#console
- runProc $ addMessage console message
+consoleLog :: CommandContext -> String -> ()
+consoleLog context message = match possibleValue context "console" with
+ Nothing -> ()
+ Just console -> runProc $ addMessage console message
contextDocument :: CommandContext -> <Proc> IDocument
contextDocument ctx = justValue ctx "__document__"
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