]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.excel/src/org/simantics/excel/Excel.java
SimanticsExcel interface refresh
[simantics/platform.git] / bundles / org.simantics.excel / src / org / simantics / excel / Excel.java
index bf7ddb5d5625966d05a13566db889c57f3a885e2..d692206bd147d1436ec17736f8082a80311c246c 100644 (file)
@@ -45,6 +45,10 @@ public class Excel {
 
     private static Excel instance;
 
+    public static Excel getInstance() throws ExcelException {
+        return getInstance(System.out);
+    }
+
     public static Excel getInstance(PrintStream out) throws ExcelException {
 
         if(instance == null) {
@@ -89,11 +93,11 @@ public class Excel {
 
         File extractDir = context.getDataFile("");
         if (extractDir == null)
-            throw new IOException("Bundle '" + Activator.PLUGIN_ID + " context has no file system support. Cannot extract server executables.");
+            throw new IOException("Bundle '" + Activator.PLUGIN_ID + " context has no file system support. Cannot extract DLLs.");
 
         if (!extractDir.exists())
             if (!extractDir.mkdir())
-                throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for storing Balas solver data.");
+                throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for communicating with Excel.");
         
         return extractDir;
         
@@ -266,7 +270,7 @@ public class Excel {
         
         if (!extractDir.exists())
             if (!extractDir.mkdir())
-                throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for storing Balas solver data.");
+                throw new IOException("Could not create directory '" + extractDir.getCanonicalPath() + "' for communicating with Excel.");
 
         String asd = "";
         ExecEnvironment env = ExecEnvironment.calculate();
@@ -306,8 +310,8 @@ public class Excel {
     private native int setVisible(int handle, boolean value);
     private native int close(int handle);
     
-//    private native double getDouble(int handle, int row, int column);
-//    private native String getString(int handle, int row, int column);
+    private native double getDouble(int handle, int row, int column);
+    private native String getString(int handle, int row, int column);
 
     final ScheduledExecutorService  scheduler = Executors.newSingleThreadScheduledExecutor();
 
@@ -331,6 +335,20 @@ public class Excel {
        });
     }
 
+    public int open2_(final String fileName, final String sheetName) {
+        try {
+            return scheduler.submit(new Callable<Integer>() {
+                @Override
+                public Integer call() throws Exception {
+                    return Integer.parseInt(open(fileName, sheetName));
+                }
+            }).get();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return -1;
+        }
+    }
+
     public String open_(final String fileName, final String sheetName) {
         try {
             return scheduler.submit(new Callable<String>() {
@@ -437,32 +455,32 @@ public class Excel {
         }
     }
     
-//    public double getDouble_(final int handle, final int row, final int column) {
-//        try {
-//            return scheduler.submit(new Callable<Double>() {
-//                @Override
-//                public Double call() throws Exception {
-//                    return getDouble(handle, row, column);
-//                }
-//            }).get();
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//            return Double.NaN;
-//        }
-//    }
-//    
-//    public String getString_(final int handle, final int row, final int column) {
-//        try {
-//            return scheduler.submit(new Callable<String>() {
-//                @Override
-//                public String call() throws Exception {
-//                    return getString(handle, row, column);
-//                }
-//            }).get();
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//            return null;
-//        }
-//    }
+    public double getDouble_(final int handle, final int row, final int column) {
+        try {
+            return scheduler.submit(new Callable<Double>() {
+                @Override
+                public Double call() throws Exception {
+                    return getDouble(handle, row, column);
+                }
+            }).get();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Double.NaN;
+        }
+    }
+    
+    public String getString_(final int handle, final int row, final int column) {
+        try {
+            return scheduler.submit(new Callable<String>() {
+                @Override
+                public String call() throws Exception {
+                    return getString(handle, row, column);
+                }
+            }).get();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
 
 }