From: Tuukka Lehtonen Date: Fri, 23 Jun 2017 07:52:31 +0000 (+0300) Subject: Fixed URIDocumentRequest to work also without IConsoleSupport. X-Git-Tag: v1.31.0~297 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=2ae50af1c5391d531b93ef97bd83d33f8dd1984e;p=simantics%2Fplatform.git Fixed URIDocumentRequest to work also without IConsoleSupport. refs #7329 Change-Id: Ie84d3ae1e2213fe7656c30e573f71bceda3c1b96 --- diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java index c4d64b686..0086b33f7 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java @@ -27,42 +27,39 @@ public class URIDocumentRequest extends UnaryRead> { @Override public List 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 result = new ArrayList(graph.syncRequest(new DocumentRequest(var))); - Collections.sort(result, new Comparator() { - - @Override - public int compare(JSONObject o1, JSONObject o2) { - return o1.id.compareTo(o2.id); - } - - }); - + List 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 COMPARATOR = (o1, o2) -> o1.id.compareTo(o2.id); + } \ No newline at end of file