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 ALLOWED_EXTENSIONS = new HashMap<>(2); static { ALLOWED_EXTENSIONS.put("*.xls", "Excel file *.xls"); ALLOWED_EXTENSIONS.put("*.xlsx", "Excel file *.xlsx"); } @Override public Optional 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 allowedExtensionsWithFilters() { return ALLOWED_EXTENSIONS; } @Override public Resource defaultParentResource() { return null; } }