@Override
public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
-
+
Variable var = Variables.getPossibleVariable(graph, parameter);
if(var == null) {
Variables.getPossibleVariable(graph, parameter);
return Collections.emptyList();
}
-
- 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);
+
+ 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.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
- SCLContext sclContext = SCLContext.getCurrent();
+ : (SCLReportingHandler) sclContext.get(SCLReportingHandler.REPORTING_HANDLER);
Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
try {
-
- 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);
- }
-
- });
-
+ List<JSONObject> result = new ArrayList<>(graph.syncRequest(new DocumentRequest(var)));
+ Collections.sort(result, COMPARATOR);
return result;
-
} finally {
sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
}
-
+
}
-
+
+ private static final Comparator<JSONObject> COMPARATOR = (o1, o2) -> o1.id.compareTo(o2.id);
+
}
\ No newline at end of file