]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Console printing also for content prints 39/539/2
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 19 May 2017 11:29:13 +0000 (14:29 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Mon, 22 May 2017 08:06:49 +0000 (11:06 +0300)
refs #7226

Change-Id: Ia95b0d5e2432d8a9a2697a9184dd268a6c1fb8ab

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

index 7c79e639ef98445bde2ff53b651e1550004a1aca..c4d64b68608533d5cf6429662017147ffd8ea9e5 100644 (file)
@@ -5,12 +5,19 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
 import java.util.Comparator;
 import java.util.List;
 
+import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.ProxyVariables;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
+import org.simantics.document.server.ConsoleSCLReportingHandler;
 import org.simantics.document.server.JSONObject;
 import org.simantics.document.server.JSONObject;
+import org.simantics.document.server.io.IConsole;
+import org.simantics.document.server.io.IConsoleSupport;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
 
 public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
 
 
 public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
 
@@ -27,16 +34,34 @@ public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
                        return Collections.emptyList();
                }
                
                        return Collections.emptyList();
                }
                
-               ArrayList<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
-               Collections.sort(result, new Comparator<JSONObject>() {
+       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);
+               SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console)
+                               : (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
+        SCLContext sclContext = SCLContext.getCurrent();
+               Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
 
 
-                       @Override
-                       public int compare(JSONObject o1, JSONObject o2) {
-                               return o1.id.compareTo(o2.id);
-                       }
+               try {
                        
                        
-               });
-               return result;
+                       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;
+                       
+               } finally {
+                       sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
+               }
                                
        }
        
                                
        }