]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphUI.java
Multiple reader thread support for db client
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / GraphUI.java
index 607661163f5f138701da9e08acf46ea61d48cb46..03df2dd0a8eb8f99af62ee7d6cfb31b012dfd660 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -135,7 +135,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
                    listener = propertyListener(client, childName);
                    listenerCache.put(child.first, listener);
            }
-               graph.asyncRequest(new FilteredVariableProperties(child.second), listener);
+               graph.syncRequest(new FilteredVariableProperties(child.second), listener);
        }
 
     }
@@ -347,7 +347,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
         private String childName;
         private boolean listenerDisposed;
 
-        public PropertyListener(AsyncListenerSupport support, ClientModel client, String childName) {
+        public PropertyListener(SyncListenerSupport support, ClientModel client, String childName) {
             super(support);
             this.client = client;
             this.childName = childName;
@@ -359,7 +359,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
             if(DEBUG)
                 System.out.println("GraphUI adds property  " + property.second.getURI(graph));
 
-            graph.asyncRequest(new CellValue(property.second), new SyncListener<Object>() {
+            graph.syncRequest(new CellValue(property.second), new SyncListener<Object>() {
 
                 @Override
                 public void execute(ReadGraph graph, final Object value) throws DatabaseException {
@@ -456,37 +456,41 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
                                @Override
                                public void handle(final String location) {
                                        
-                               processor.asyncRequest(new ReadRequest() {
-
-                                   @Override
-                                   public void run(ReadGraph graph) throws DatabaseException {
-                                       
-                                                       Variable cellVariable = run.getPossibleChild(graph, location);
-                                                       if(cellVariable != null) {
-                                                               final Resource config = cellVariable.getPossiblePropertyValue(graph, "Represents");
-                                                               if(config != null) {
-                                                                       
-                                                                       graph.asyncRequest(new WriteRequest() {
+                                       try {
+                                               processor.syncRequest(new ReadRequest() {
 
-                                                                               @Override
-                                                                               public void perform(WriteGraph graph) throws DatabaseException {
-                                                                                       
-                                                                                       Layer0 l0 = Layer0.getInstance(graph);
+                                                       @Override
+                                                       public void run(ReadGraph graph) throws DatabaseException {
+
+                                                               Variable cellVariable = run.getPossibleChild(graph, location);
+                                                               if(cellVariable != null) {
+                                                                       final Resource config = cellVariable.getPossiblePropertyValue(graph, "Represents");
+                                                                       if(config != null) {
+
+                                                                               graph.asyncRequest(new WriteRequest() {
+
+                                                                                       @Override
+                                                                                       public void perform(WriteGraph graph) throws DatabaseException {
+
+                                                                                               Layer0 l0 = Layer0.getInstance(graph);
 //                                                                                     SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
-                                                                                       graph.deny(config, l0.PartOf);
+                                                                                               graph.deny(config, l0.PartOf);
 //                                                                                     graph.deny(config, sr.RowOf);
 //                                                                                     graph.deny(config, sr.ColumnOf);
-                                                                                       
-                                                                               }
-                                                                               
-                                                                       });
-                                                                       
+
+                                                                                       }
+
+                                                                               });
+
+                                                                       }
                                                                }
+
                                                        }
-                                                       
-                                   }
-                                   
-                               });
+
+                                               });
+                                       } catch (DatabaseException e) {
+                                               LOGGER.error("Unexpected exception while removing cell", e);
+                                       }
                                        
                                }
                
@@ -791,7 +795,7 @@ public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport
 
     @Override
     public void exception(Throwable t) {
-        t.printStackTrace();
+        LOGGER.error("Failed to read properties.", t);
     }
 
     @Override