Added preference for Import dependencies in generic model import/export 19/1219/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 14 Nov 2017 07:46:58 +0000 (09:46 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 14 Nov 2017 07:48:34 +0000 (09:48 +0200)
Also fixed the model import wizard to replace L0.ExternalEntity
instances with the imported dependencies.

refs #7572

Change-Id: Ia68eb5afc3e835821f17bf96cc48205d9372a013

bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/IsExternalEntity.java [new file with mode: 0644]
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelExportWizard.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImporter.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/Preferences.java

diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/IsExternalEntity.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/IsExternalEntity.java
new file mode 100644 (file)
index 0000000..3ac3a5f
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.primitiverequest;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.ServiceException;
+import org.simantics.layer0.Layer0;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.31.0
+ */
+public final class IsExternalEntity extends ResourceRead<Boolean> {
+
+    public IsExternalEntity(Resource resource) {
+        super(resource);
+    }
+
+    @Override
+    public Boolean perform(ReadGraph graph) throws ServiceException {
+        return graph.isInstanceOf(resource, Layer0.getInstance(graph).ExternalEntity);
+    }
+
+}
index 37996107eb9d0829fe71cd654a182d86f28d506f..182c0f6fcb59a2835666687777c6fea5278d8210 100644 (file)
@@ -37,7 +37,7 @@ import org.simantics.utils.ui.ExceptionUtils;
 
 /**
  * @author Tuukka Lehtonen
- * @author Teemu Mätäsniemi
+ * @author Teemu Mätäsniemi
  * @author Antti Villberg
  */
 public class ModelExportWizard extends Wizard implements IExportWizard {
@@ -46,8 +46,9 @@ public class ModelExportWizard extends Wizard implements IExportWizard {
 
     Deque<String>            recentExportPaths;
     boolean                  overwrite;
+    boolean                  includeDependencies;
 
-    ExportPlan        exportModel;
+    ExportPlan               exportModel;
 
     private boolean readPreferences() {
         IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
@@ -55,6 +56,7 @@ public class ModelExportWizard extends Wizard implements IExportWizard {
         String recentPathsPref = store.getString(Preferences.RECENT_SHARED_LIBRARY_EXPORT_LOCATIONS);
         recentExportPaths = Preferences.decodePaths(recentPathsPref);
         overwrite = store.getBoolean(Preferences.SHARED_LIBRARY_EXPORT_OVERWRITE);
+        includeDependencies = store.getBoolean(Preferences.EXPORT_INCLUDE_DEPENDENCIES);
 
         return true;
     }
@@ -64,6 +66,7 @@ public class ModelExportWizard extends Wizard implements IExportWizard {
 
         store.putValue(Preferences.RECENT_SHARED_LIBRARY_EXPORT_LOCATIONS, Preferences.encodePaths(recentExportPaths));
         store.setValue(Preferences.SHARED_LIBRARY_EXPORT_OVERWRITE, exportModel.overwrite);
+        store.setValue(Preferences.EXPORT_INCLUDE_DEPENDENCIES, exportModel.includeDependencies);
 
         if (store.needsSaving())
             store.save();
@@ -89,6 +92,7 @@ public class ModelExportWizard extends Wizard implements IExportWizard {
         exportModel.project = project;
         exportModel.selection = selection;
         exportModel.overwrite = overwrite;
+        exportModel.includeDependencies = includeDependencies;
     }
 
     @Override
index bb0d6f68a7958832f4221bf1738a3523cd34df1b..011ce12ff538f1764d194ba5c2ef74c644382bc5 100644 (file)
@@ -66,6 +66,7 @@ public class ModelImportWizard extends Wizard implements IImportWizard {
         importModel = new ImportPlan(ctx, recentImportPaths);
         importModel.project = project;
         importModel.selection = selection.getFirstElement();
+        importModel.includeDependencies = store.getBoolean(Preferences.IMPORT_INCLUDE_DEPENDENCIES);
 
         return true;
     }
@@ -74,6 +75,7 @@ public class ModelImportWizard extends Wizard implements IImportWizard {
         IPersistentPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
 
         store.putValue(Preferences.RECENT_SHARED_LIBRARY_IMPORT_LOCATIONS, Preferences.encodePaths(importModel.recentLocations));
+        store.setValue(Preferences.IMPORT_INCLUDE_DEPENDENCIES, importModel.includeDependencies);
 
         if (store.needsSaving())
             store.save();
index 6a8d6718d7c5d140a6a077637ea2802cf7fbd7bf..e7707dd407a8d4978aa8c54716ba5f1fe6604363 100644 (file)
@@ -27,6 +27,7 @@ import org.simantics.databoard.container.DataContainers;
 import org.simantics.databoard.container.FormatHandler;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
+import org.simantics.db.common.primitiverequest.IsExternalEntity;
 import org.simantics.db.common.primitiverequest.PossibleResource;
 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;
 import org.simantics.db.layer0.migration.MigratedImportResult;
@@ -74,7 +75,8 @@ public class ModelImporter {
                         if (libraryDependenciesBean != null) {
                             for (ModelDependency dependency : libraryDependenciesBean.dependencies) {
                                 Resource existing = session.sync(new PossibleResource(dependency.uri));
-                                if (existing == null) {
+                                boolean isExternalEntity = existing != null && session.syncRequest(new IsExternalEntity(existing));
+                                if (existing == null || isExternalEntity) {
                                     MigrationUtils.importSharedOntology(session, dependency.tg, false);
                                 }
                             }
index 723f56df96ec961d1d3bc2b2c92c01769c0b0adb..6887ecf4ce22ab651afd11267b43b9f8752aa385 100644 (file)
@@ -28,6 +28,8 @@ public final class Preferences {
     public static final String  RECENT_SHARED_LIBRARY_IMPORT_LOCATIONS = "RECENT_SHARED_LIBRARY_IMPORT_LOCATIONS";
     public static final String  RECENT_SHARED_LIBRARY_EXPORT_LOCATIONS = "RECENT_SHARED_LIBRARY_EXPORT_LOCATIONS";
     public static final String  SHARED_LIBRARY_EXPORT_OVERWRITE = "SHARED_LIBRARY_EXPORT_OVERWRITE";
+    public static final String  EXPORT_INCLUDE_DEPENDENCIES = "EXPORT_INCLUDE_DEPENDENCIES";
+    public static final String  IMPORT_INCLUDE_DEPENDENCIES = "IMPORT_INCLUDE_DEPENDENCIES";
 
     private static final String TAG_PATH                = "path";
     private static final String ATTR_NAME               = "name";