-
- 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;
-
+
+ IConsole console = null;
+ IConsoleSupport cs = Simantics.getSession().peekService(IConsoleSupport.class);
+ if (cs != null) {
+ Variable root = ProxyVariables.proxyVariableRoot(graph, var);
+ if (root == null)
+ return Collections.emptyList();
+ Variable session = root.getParent(graph);
+ String guid = session.getName(graph);
+ console = cs.getConsole(guid);
+ }
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console)
+ : (SCLReportingHandler) sclContext.get(SCLReportingHandler.REPORTING_HANDLER);
+ Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
+
+ try {
+ List<JSONObject> result = new ArrayList<>(graph.syncRequest(new DocumentRequest(var)));
+ Collections.sort(result, COMPARATOR);
+ return result;
+ } finally {
+ sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
+ }
+