X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fsharedontology%2Fwizard%2FSharedOntologyImportWizard.java;h=df65646346386755b7cecc2388350ac74824a652;hp=95beaad384a7eb6f8a543d6aaf48030c54e6bf7c;hb=9acebe9584f8f2a78f0322b6e0e24438e7ceb984;hpb=081bf7e08a67c0af23c5846e163be39bb19f12cb diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java index 95beaad38..df6564634 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyImportWizard.java @@ -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 handler1 = new FormatHandler() { + FormatHandler handler1 = new FormatHandler() { @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> handlers = new HashMap<>(); + Map> 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; } }