]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java
Import/export changes. A load.
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / sharedontology / wizard / SharedOntologyImportWizard.java
index 95beaad384a7eb6f8a543d6aaf48030c54e6bf7c..df65646346386755b7cecc2388350ac74824a652 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
 import org.eclipse.ui.IImportWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.preferences.ScopedPreferenceStore;
@@ -37,6 +38,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.layer0.migration.MigratedImportResult;
 import org.simantics.db.layer0.migration.MigrationUtils;
 import org.simantics.db.layer0.util.DraftStatusBean;
 import org.simantics.db.management.ISessionContext;
@@ -48,8 +50,10 @@ import org.simantics.project.IProject;
 import org.simantics.project.ProjectKeys;
 import org.simantics.ui.SimanticsUI;
 import org.simantics.ui.utils.ResourceAdaptionUtils;
+import org.simantics.utils.strings.EString;
 import org.simantics.utils.ui.ErrorLogger;
 import org.simantics.utils.ui.ExceptionUtils;
+import org.simantics.utils.ui.dialogs.InfoDialog;
 
 /**
  * @author Tuukka Lehtonen
@@ -123,13 +127,14 @@ public class SharedOntologyImportWizard extends Wizard implements IImportWizard
         }
 
         try {
+            MigratedImportResult[] result = { null };
             getContainer().run(true, true, new IRunnableWithProgress() {
                 @Override
                 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                     try {
                         Resource target = ResourceAdaptionUtils.toSingleResource(importModel.selection);
                         importModel.sessionContext.getSession().markUndoPoint();
-                        doImport(monitor, importModel.importLocation, importModel.sessionContext.getSession(), target);
+                        result[0] = doImport(monitor, importModel.importLocation, importModel.sessionContext.getSession(), target);
                     } catch (Exception e) {
                         throw new InvocationTargetException(e);
                     } finally {
@@ -137,6 +142,13 @@ public class SharedOntologyImportWizard extends Wizard implements IImportWizard
                     }
                 }
             });
+
+            if (result[0].hasMissingExternals()) {
+                InfoDialog.open(getShell(), "Missing Externals Created",
+                        "The system was unable to find some of the external entities referenced by the imported material. Place-holders have been created for the missing entities.\nThe missing entities are:\n"
+                                + EString.implode(result[0].tgResult.missingExternals),
+                        SWT.SHEET);
+            }
         } catch (InvocationTargetException e) {
             Throwable cause = e.getCause();
             WizardPage cp = (WizardPage) getContainer().getCurrentPage();
@@ -161,37 +173,38 @@ public class SharedOntologyImportWizard extends Wizard implements IImportWizard
         return true;
     }
 
-    public static void doImport(IProgressMonitor monitor, File modelFile, Session session, Resource target)
+    public static MigratedImportResult doImport(IProgressMonitor monitor, File modelFile, Session session, Resource target)
             throws Exception
     {
         SubMonitor mon = SubMonitor.convert(monitor);
         mon.beginTask("Loading shared library from disk", 1000);
 
-        FormatHandler<Object> handler1 = new FormatHandler<Object>() {
+        FormatHandler<MigratedImportResult> handler1 = new FormatHandler<MigratedImportResult>() {
             @Override
             public Binding getBinding() {
                 return TransferableGraph1.BINDING;
             }
 
             @Override
-            public Object process(DataContainer container) throws Exception {
+            public MigratedImportResult process(DataContainer container) throws Exception {
                 mon.worked(100);
                 mon.setTaskName("Importing shared library into database");
                 Variant draftStatus = container.metadata.get(DraftStatusBean.EXTENSION_KEY);
                 TransferableGraph1 tg = (TransferableGraph1) container.content.getValue();
-                MigrationUtils.importSharedOntology(mon.newChild(850, SubMonitor.SUPPRESS_NONE), session, tg, draftStatus == null);
-                return null;
+                return MigrationUtils.importSharedOntology(mon.newChild(850, SubMonitor.SUPPRESS_NONE), session, tg, draftStatus == null);
             }
         };
 
-        Map<String, FormatHandler<Object>> handlers = new HashMap<>();
+        Map<String, FormatHandler<MigratedImportResult>> handlers = new HashMap<>();
         handlers.put(Constants.SHARED_LIBRARY_FORMAT_V1, handler1);
 
-        DataContainers.readFile(modelFile, handlers);
+        MigratedImportResult result = DataContainers.readFile(modelFile, handlers);
 
         mon.setTaskName("Postprocessing");
         mon.subTask("");
         mon.newChild(50).done();
+
+        return result;
     }
 
 }