From 60423815d213fd66f615c1e81399257a4479ae8f Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 20 Apr 2017 13:25:33 +0300 Subject: [PATCH] Fix SysdynFileImport refs #7154 Change-Id: I278ade3e0f52d03892f25723e4a0e59349ff7c54 --- .../org.simantics.sysdyn.SysdynFileImport.xml | 11 ++- .../utils/imports/SysdynFileImport.java | 84 ++++++++++--------- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/bundles/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml b/bundles/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml index a9bed563..870e9036 100644 --- a/bundles/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml +++ b/bundles/org.simantics.sysdyn/OSGI-INF/org.simantics.sysdyn.SysdynFileImport.xml @@ -1,4 +1,7 @@ - - - - \ No newline at end of file + + + + + + + diff --git a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java index 01699bfe..c07b7555 100644 --- a/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java +++ b/bundles/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/SysdynFileImport.java @@ -1,39 +1,45 @@ -package org.simantics.sysdyn.utils.imports; - -import java.nio.file.Path; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.simantics.db.Resource; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.fileimport.SimanticsResourceFileImport; -import org.simantics.scl.runtime.function.Function1; -import org.simantics.utils.DataContainer; - -public class SysdynFileImport extends SimanticsResourceFileImport { - - private static final Map EXTENSIONS_FILTERS = Collections.singletonMap("*.sysdyn", - "Sysdyn model file (*.sysdyn)"); - - @Override - public Map allowedExtensionsWithFilters() { - return EXTENSIONS_FILTERS; - } - - @Override - public Optional perform(Resource parent, Path file) throws Exception { - DataContainer result = new DataContainer<>(); - ImportUtils.importModelFile(file.toAbsolutePath().toString(), new NullProgressMonitor(), - new Function1() { - - @Override - public WriteRequest apply(Resource model) { - result.set(model); - return null; - } - }); - return Optional.ofNullable(result.get()); - } -} +package org.simantics.sysdyn.utils.imports; + +import java.nio.file.Path; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.fileimport.SimanticsResourceFileImport; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.utils.DataContainer; + +public class SysdynFileImport extends SimanticsResourceFileImport { + + private static final Map EXTENSIONS_FILTERS = Collections.singletonMap("*.sysdyn", + "Sysdyn model file (*.sysdyn)"); + + @Override + public Map allowedExtensionsWithFilters() { + return EXTENSIONS_FILTERS; + } + + @Override + public Optional perform(Resource parent, Path file) throws Exception { + DataContainer result = new DataContainer<>(); + ImportUtils.importModelFile(file.toAbsolutePath().toString(), new NullProgressMonitor(), + new Function1() { + + @Override + public WriteRequest apply(Resource model) { + result.set(model); + return null; + } + }); + return Optional.ofNullable(result.get()); + } + + @Override + public Resource defaultParentResource() { + return Simantics.getProjectResource(); + } +} -- 2.47.1