]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed URIDocumentRequest to work also without IConsoleSupport. 51/651/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 23 Jun 2017 07:52:31 +0000 (10:52 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 23 Jun 2017 08:09:39 +0000 (11:09 +0300)
A late but necessary fix for 1.29.0.

refs #7329

Change-Id: Ie84d3ae1e2213fe7656c30e573f71bceda3c1b96
(cherry picked from commit 2ae50af1c5391d531b93ef97bd83d33f8dd1984e)

bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java

index c4d64b68608533d5cf6429662017147ffd8ea9e5..0086b33f7487d0889fc366be9c1f1ef15a7860e3 100644 (file)
@@ -27,42 +27,39 @@ public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
 
        @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