]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/ExcelImport.java
Fix stackoverflow from excel import
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / ExcelImport.java
index 246f38edf8654dc7145ffd63c33bbe56e4dd99b3..8b2d9af4f520530f2686ee34dadf6b2415ce4233 100644 (file)
@@ -28,7 +28,7 @@ import org.simantics.datatypes.utils.BTree;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.DelayedWriteRequest;
-import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.BindingException;
 import org.simantics.db.exception.DatabaseException;
@@ -46,12 +46,20 @@ import org.simantics.spreadsheet.graph.parser.ast.AstValue;
 import org.simantics.spreadsheet.resource.SpreadsheetResource;
 import org.simantics.spreadsheet.util.SpreadsheetUtils;
 import org.simantics.utils.DataContainer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ExcelImport {
-       
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ExcelImport.class);
+    
        private static final double POINT_TO_PIXEL_RATIO = 1.33;
        
-    public static void importBook(Resource container, File file) {
+       public static void importBook(Resource container, File file) {
+           importBookR(container, file);
+       }
+       
+    public static Resource importBookR(Resource container, File file) {
         
         try {
             
@@ -254,7 +262,7 @@ public class ExcelImport {
                         btreeContainer.set(result);
                         bookContainer.set(book);
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        LOGGER.error("Could not import book " + file.getAbsolutePath(), e);
                         btreeContainer.add(Collections.emptyList());
                     }
                 }
@@ -269,20 +277,21 @@ public class ExcelImport {
                 }
             });
             
-            Simantics.getSession().sync(new WriteRequest() {
+            return Simantics.getSession().sync(new WriteResultRequest<Resource>() {
                 
                 @Override
-                public void perform(WriteGraph graph) throws DatabaseException {
+                public Resource perform(WriteGraph graph) throws DatabaseException {
                     Resource delayedBook = bookContainer.get();
                     XSupport support = graph.getService(XSupport.class);
                     Resource book = support.convertDelayedResourceToResource(delayedBook);
                     SpreadsheetGraphUtils.constructAndInitializeRunVariable(graph, book);
+                    return book;
                 }
             });
         } catch (Exception e) {
-            e.printStackTrace();
+            LOGGER.error("Could not import book " + file.getAbsolutePath(), e);
+            return null;
         }
-        
     }
     
     private static Resource assignStyles(WriteGraph graph, SpreadsheetResource SR, Cell cell, Resource book, Map<Integer, Resource> existingStyles, Map<Integer, SpreadsheetStyle> existingStyles2, String styleName) throws DatabaseException {