]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.fileimport/src/org/simantics/spreadsheet/fileimport/ExcelFileImport.java
Updated file importer interface and fixed Spreadsheet import
[simantics/platform.git] / bundles / org.simantics.spreadsheet.fileimport / src / org / simantics / spreadsheet / fileimport / ExcelFileImport.java
1 package org.simantics.spreadsheet.fileimport;
2
3 import java.nio.file.Path;
4 import java.util.HashMap;
5 import java.util.Map;
6 import java.util.Optional;
7
8 import org.simantics.Simantics;
9 import org.simantics.db.Resource;
10 import org.simantics.fileimport.SimanticsResourceFileImport;
11 import org.simantics.spreadsheet.graph.ExcelImport;
12
13 public class ExcelFileImport extends SimanticsResourceFileImport {
14
15     private static final Map<String, String> ALLOWED_EXTENSIONS = new HashMap<>(2);
16     
17     static {
18         ALLOWED_EXTENSIONS.put("*.xls", "Excel file *.xls");
19         ALLOWED_EXTENSIONS.put("*.xlsx", "Excel file *.xlsx");
20     }
21     
22     @Override
23     public Optional<Resource> perform(Resource possibleSelection, Path file) throws Exception {
24         if(possibleSelection != null) {
25                 //Make sure the selection is of valid type here
26                 return Optional.ofNullable(ExcelImport.importBookR(possibleSelection, file.toFile()));
27         } else {
28                 throw new NullPointerException("No selection provided - Cannot import book");
29         }
30     }
31
32     @Override
33     public Map<String, String> allowedExtensionsWithFilters() {
34         return ALLOWED_EXTENSIONS;
35     }
36
37     @Override
38     public Resource defaultParentResource() {
39         return null;
40     }
41
42 }