X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.fileimport%2Fsrc%2Forg%2Fsimantics%2Ffileimport%2FFileImportService.java;h=5f9c7257b7da977057d5ac6ef3951aff787724bb;hp=96276154237e11b31209dc1707c207edd68d8c71;hb=664f37a026967c90a9a8a4ef3c5336ee426f67aa;hpb=5915c1bbd6d0c6125aa3c815c7843339190f28e4 diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java index 962761542..5f9c7257b 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/FileImportService.java @@ -93,27 +93,35 @@ public class FileImportService { Files.write(file, bytes); ConsumerHolder holder = new ConsumerHolder(); - String result = performFileImport(file, Optional.of(holder)); + String result = performFileImport(file, Optional.empty(), Optional.of(holder)); if (holder.getThrowable() != null) throw holder.getThrowable(); return result; } - + /** * Method that performs the import of the given file. This method is called when e.g. {@link FileImportDropins} watcher detects {@link java.nio.file.StandardWatchEventKinds.ENTRY_CREATE} operation * * @param file Path file to be imported + * @param possibleSelection - the selected resource (if exists) * @param callback Optional callback which can be used to catch Throwables thrown in the import process */ - public static String performFileImport(Path file, Optional> callback) { + public static String performFileImport(Path file, Optional possibleSelection, Optional> callback) { if (file.getFileName().toString().equals(DB_FILE)) { return null; } String result = "Import failed"; IGenericFileImport service = findServiceForFileExtension(file); + if (service != null) { try { - Optional resource = service.perform(file); + Optional resource; + if (possibleSelection.isPresent() && service.defaultParentResource() == null) { + resource = Optional.of(Long.toString(service.perform(possibleSelection.get(), file).get().getResourceId())); + } + else { + resource = service.performWithDefaultParent(file); + } saveResourceForPath(file, resource); result = resource.get(); } catch (Throwable t) { @@ -130,7 +138,6 @@ public class FileImportService { } return result; } - /** * Remove the entity that matches the file. This method is called when e.g. the {@link FileImportDropins} watcher detects {@link java.nio.file.StandardWatchEventKinds.ENTRY_DELETE} operation @@ -353,12 +360,27 @@ public class FileImportService { return Optional.of(value); } + /** + * Calls the proper imported without a selection (null possibleSelection) + * @param path + * @param extension + * @return + * @throws Exception + */ public static String importGenericFileWithExtension(String path, String extension) throws Exception { IGenericFileImport service = findServiceForExtension(extension); - Optional result = service.perform(Paths.get(path)); + Optional result = service.performWithDefaultParent(Paths.get(path)); return result.get(); } + /** + * Calls the proper imported without a selection (null possibleSelection) + * @param parent + * @param path + * @param extension + * @return + * @throws Exception + */ public static Resource importGenericFileWithExtensionAndParent(Resource parent, String path, String extension) throws Exception { IGenericFileImport service = findServiceForExtension(extension); Optional result = service.perform(parent, Paths.get(path));