1 Simantics Generic File Import is a utility service that enables [Eclipse's Dropins](http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fp2_dropins_format.html)-like functionality. The directory resides inside `~/workspace/.metadata/plugins/org.simantics.fileimport/dropins` and it is not watched by default. There are two ways to start the watchservice:
\r
3 1. Call directly in Java `FileImportDropins.watchDropinsFolder()`
\r
4 2. Use SCL function `watchDropinsFolder` from `"Dropins/Core"`
\r
6 ## Creating own File importer
\r
8 To create own File importer it is usually enough to extend the abstract class `SimanticsResourceFileImport` and implement the two methods:
\r
11 * Returns a key-value map for file extensions this importer can handle
\r
13 * @return Map<String, String> allowed extensions this service can handle. Key is the extension e.g. <code>.sharedLibrary</code> and the value is the description of the extension
\r
15 Map<String, String> allowedExtensionsWithFilters();
\r
18 * Performs the import for the given file
\r
20 * @param parent Resource parent of the imported entity in Simantics database
\r
21 * @param file Path file location of file
\r
22 * @return Optional Resource of the imported entity in Simantics database
\r
25 public abstract Optional<Resource> perform(Resource parent, Path file) throws Exception;
\r
27 An example of such a class for importing FMU-files to Simantics workbench would be following:
\r
30 public class FMIFileImport extends SimanticsResourceFileImport {
\r
32 private static final Map<String, String> EXTENSIONS_FILTERS = Collections.singletonMap("*.fmu",
\r
33 "Functional Mock-up Unit (*.fmu)");
\r
36 public Optional<Resource> perform(Resource parent, Path file) throws IOException{
\r
38 Resource model = FMIStudioSCL.createFMIModel(parent, file);
\r
39 return Optional.of(model);
\r
40 } catch (FMILException | DatabaseException e) {
\r
41 e.printStackTrace();
\r
42 return Optional.empty();
\r
47 public Map<String, String> allowedExtensionsWithFilters() {
\r
48 return EXTENSIONS_FILTERS;
\r
54 It is important to create the component for defining declarative service. To do this right click the same plugin where the implmentation is and click New -> Other -> Plug-in Development -> Component Definition.
\r
56 Give the name for the XML file and and browse to the implementing class You just created.
\r
58 An example of XML-file is:
\r
61 <?xml version="1.0" encoding="UTF-8"?>
\r
62 <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.simantics.fmi.studio.fileimport">
\r
63 <implementation class="org.simantics.fmi.studio.fileimport.FMIFileImport"/>
\r
65 <provide interface="org.simantics.fileimport.IGenericFileImport"/>
\r
70 ## FileImportService utility class
\r
72 The class `org.simantics.fileimport.FileImportService` contains utility methods for e.g. listing all current services and performing file imports:
\r
76 * Lists all supported file extensions which have a registered service for handling the import
\r
78 * @return Map containing the extension and the description of the extension in that order
\r
80 public static Map<String, String> supportedExtensionsWithFilters();
\r
83 * 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
\r
85 * @param file Path file to be imported
\r
86 * @param callback Optional callback which can be used to catch Throwables thrown in the import process
\r
88 public static void performFileImport(Path file, Optional<Consumer<Throwable>> callback);
\r