]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImporter.java
Importing TG files creates copies of files without deleting them.
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / sharedontology / wizard / ModelImporter.java
index e7707dd407a8d4978aa8c54716ba5f1fe6604363..91660a4925667396d8b5240ad56951f50ec5d74b 100644 (file)
@@ -68,29 +68,32 @@ public class ModelImporter {
                 state.setProperty(MigrationStateKeys.MODEL_FILE, modelFile);
                 state.setProperty(MigrationStateKeys.SESSION, session);
                 state.setProperty(MigrationStateKeys.PROGRESS_MONITOR, monitor);
-
-                if (includeDependencies) {
-                    try {
-                        ModelDependenciesBean libraryDependenciesBean = ModelDependenciesBean.fromMigrationState(state);
-                        if (libraryDependenciesBean != null) {
-                            for (ModelDependency dependency : libraryDependenciesBean.dependencies) {
-                                Resource existing = session.sync(new PossibleResource(dependency.uri));
-                                boolean isExternalEntity = existing != null && session.syncRequest(new IsExternalEntity(existing));
-                                if (existing == null || isExternalEntity) {
-                                    MigrationUtils.importSharedOntology(session, dependency.tg, false);
-                                }
-                            }
-                        }
-                    } catch (AdaptException e) {
-                        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not read model dependencies bean.", e));
-                    }
+                try {
+                       if (includeDependencies) {
+                           try {
+                               ModelDependenciesBean libraryDependenciesBean = ModelDependenciesBean.fromMigrationState(state);
+                               if (libraryDependenciesBean != null) {
+                                   for (ModelDependency dependency : libraryDependenciesBean.dependencies) {
+                                       Resource existing = session.sync(new PossibleResource(dependency.uri));
+                                       boolean isExternalEntity = existing != null && session.syncRequest(new IsExternalEntity(existing));
+                                       if (existing == null || isExternalEntity) {
+                                           MigrationUtils.importSharedOntology(session, dependency.tg, false);
+                                       }
+                                   }
+                               }
+                           } catch (AdaptException e) {
+                               Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not read model dependencies bean.", e));
+                           }
+                       }
+       
+                       MigrationUtils.importMigrated(monitor, session, modelFile, state, new DefaultPasteImportAdvisor(target), target);
+       
+                       Collection<Resource> resultRoots = state.getProperty(MigrationStateKeys.CURRENT_ROOT_RESOURCES);
+                       ImportResult result = state.getProperty(MigrationStateKeys.IMPORT_RESULT);
+                       return new MigratedImportResult(resultRoots, result);
+                } finally {
+                   state.dispose();
                 }
-
-                MigrationUtils.importMigrated(monitor, session, modelFile, state, new DefaultPasteImportAdvisor(target), target);
-
-                Collection<Resource> resultRoots = state.getProperty(MigrationStateKeys.CURRENT_ROOT_RESOURCES);
-                ImportResult result = state.getProperty(MigrationStateKeys.IMPORT_RESULT);
-                return new MigratedImportResult(resultRoots, result);
             }
         };