]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed URIDocumentRequest to work also without IConsoleSupport. 50/650/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 07:52:31 +0000 (10:52 +0300)
refs #7329

Change-Id: Ie84d3ae1e2213fe7656c30e573f71bceda3c1b96

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 {
 
        @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();
                }
                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 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 {
                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;
                        return result;
-                       
                } finally {
                        sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
                }
                } 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
 }
\ No newline at end of file