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<String, List<JSONObject>> {
return Collections.emptyList();
}
- ArrayList<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
- Collections.sort(result, new Comparator<JSONObject>() {
+ 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<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
+ Collections.sort(result, new Comparator<JSONObject>() {
+
+ @Override
+ public int compare(JSONObject o1, JSONObject o2) {
+ return o1.id.compareTo(o2.id);
+ }
+
+ });
+
+ return result;
+
+ } finally {
+ sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
+ }
}