X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.excel%2Fsrc%2Forg%2Fsimantics%2Fexcel%2FExcel.java;h=d692206bd147d1436ec17736f8082a80311c246c;hp=bf7ddb5d5625966d05a13566db889c57f3a885e2;hb=0c128e8f1ce1dd42d4375b0f91e4e93f02214ccf;hpb=ea16512131c5b9d8f77991c0f16c285638ed709d diff --git a/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java b/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java index bf7ddb5d5..d692206bd 100644 --- a/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java +++ b/bundles/org.simantics.excel/src/org/simantics/excel/Excel.java @@ -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() { + @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() { @@ -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() { -// @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() { -// @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() { + @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() { + @Override + public String call() throws Exception { + return getString(handle, row, column); + } + }).get(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } }