-package org.simantics.spreadsheet.fileimport;\r
-\r
-import java.nio.file.Path;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.Optional;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.fileimport.SimanticsResourceFileImport;\r
-\r
-public class ExcelFileImport extends SimanticsResourceFileImport {\r
-\r
- private static final Map<String, String> ALLOWED_EXTENSIONS = new HashMap<>(2);\r
- \r
- static {\r
- ALLOWED_EXTENSIONS.put("*.xls", "Excel file *.xls");\r
- ALLOWED_EXTENSIONS.put("*.xlsx", "Excel file *.xlsx");\r
- }\r
- \r
- @Override\r
- public Optional<Resource> perform(Resource parent, Path file) {\r
- return Optional.empty();\r
- }\r
-\r
- @Override\r
- public Map<String, String> allowedExtensionsWithFilters() {\r
- return ALLOWED_EXTENSIONS;\r
- }\r
-\r
-}\r
+package org.simantics.spreadsheet.fileimport;
+
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.fileimport.SimanticsResourceFileImport;
+import org.simantics.spreadsheet.graph.ExcelImport;
+
+public class ExcelFileImport extends SimanticsResourceFileImport {
+
+ private static final Map<String, String> ALLOWED_EXTENSIONS = new HashMap<>(2);
+
+ static {
+ ALLOWED_EXTENSIONS.put("*.xls", "Excel file *.xls");
+ ALLOWED_EXTENSIONS.put("*.xlsx", "Excel file *.xlsx");
+ }
+
+ @Override
+ public Optional<Resource> perform(Resource possibleSelection, Path file) throws Exception {
+ if(possibleSelection != null) {
+ //Make sure the selection is of valid type here
+ return Optional.ofNullable(ExcelImport.importBookR(possibleSelection, file.toFile()));
+ } else {
+ throw new NullPointerException("No selection provided - Cannot import book");
+ }
+ }
+
+ @Override
+ public Map<String, String> allowedExtensionsWithFilters() {
+ return ALLOWED_EXTENSIONS;
+ }
+
+ @Override
+ public Resource defaultParentResource() {
+ return null;
+ }
+
+}