From: Tuukka Lehtonen Date: Tue, 14 Nov 2017 07:46:58 +0000 (+0200) Subject: Added preference for Import dependencies in generic model import/export X-Git-Tag: v1.31.0~41 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F1219%2F2;p=simantics%2Fplatform.git Added preference for Import dependencies in generic model import/export Also fixed the model import wizard to replace L0.ExternalEntity instances with the imported dependencies. refs #7572 Change-Id: Ia68eb5afc3e835821f17bf96cc48205d9372a013 --- 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 index 000000000..3ac3a5f3d --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/IsExternalEntity.java @@ -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 { + + public IsExternalEntity(Resource resource) { + super(resource); + } + + @Override + public Boolean perform(ReadGraph graph) throws ServiceException { + return graph.isInstanceOf(resource, Layer0.getInstance(graph).ExternalEntity); + } + +} diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelExportWizard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelExportWizard.java index 37996107e..182c0f6fc 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelExportWizard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelExportWizard.java @@ -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 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 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java index bb0d6f68a..011ce12ff 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImportWizard.java @@ -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(); diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImporter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImporter.java index 6a8d6718d..e7707dd40 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImporter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/ModelImporter.java @@ -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); } } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/Preferences.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/Preferences.java index 723f56df9..6887ecf4c 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/Preferences.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/Preferences.java @@ -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";