]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #4938
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 Jun 2014 11:09:33 +0000 (11:09 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 Jun 2014 11:09:33 +0000 (11:09 +0000)
Enhancing error handling in Sysdyn Model and Shared Library imports if dependencies are missing from database (e.g. user tries to import a Shared Library with references to Simupedia)

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29608 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportSharedLibraryHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtilsUI.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/wizards/models/WizardModelsImportPage.java
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java

index 48daeb98006f14ae7dec3d17f7a308d60034625c..2849101cf0d0a743b1d1512006abe2333055790b 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;\r
 import org.eclipse.core.runtime.IProgressMonitor;\r
 import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
 import org.eclipse.core.runtime.jobs.Job;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.FileDialog;\r
@@ -26,6 +27,8 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import org.simantics.DatabaseJob;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.utils.imports.ImportUtilsUI;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
 \r
 /**\r
  * Imports models from exported transferable graph files.\r
@@ -60,7 +63,20 @@ public class ImportModelHandler extends AbstractHandler {
 \r
             @Override\r
             protected IStatus run(IProgressMonitor monitor) {\r
-                IStatus status = ImportUtilsUI.importModelFile(selected, monitor);\r
+               monitor.beginTask("Importing Model " + selected, 3);\r
+               IStatus status = null;\r
+               try {\r
+                       monitor.worked(1);\r
+                    status = ImportUtilsUI.importModelFile(selected, monitor);                         \r
+                    monitor.worked(2);\r
+               } catch (Exception e) {\r
+                       ExceptionUtils.logAndShowError("Model import failed, see exception for details",  e);\r
+                       ErrorLogger.defaultLogError("Model import failed, see exception for details", e);\r
+                       return Status.OK_STATUS;\r
+               } finally {\r
+                       monitor.done();\r
+               }\r
+\r
                 return status;\r
             }\r
         };\r
index 4190860dfb4e94441b703b59cfcd0a35fef30630..8165e545e93d3107fb705e9a2589ce92f59a6b36 100644 (file)
@@ -25,9 +25,13 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.DatabaseJob;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.graph.db.MissingDependencyException;\r
 import org.simantics.modeling.ModelingUtils;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.utils.imports.ImportUtilsUI;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
 \r
 public class ImportSharedLibraryHandler extends AbstractHandler {\r
 \r
@@ -37,7 +41,7 @@ public class ImportSharedLibraryHandler extends AbstractHandler {
         // Get imported transferable graph file using FileDialog\r
         Shell shell = HandlerUtil.getActiveShellChecked(event);\r
         FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
-        fd.setText("Import Model");\r
+        fd.setText("Import Shared Library");\r
 \r
         String path = Activator.getDefault().getPreferenceStore().getString(ImportUtilsUI.IMPORTMODELTPATH);\r
         if(path.isEmpty() || !(new File(path).exists())){\r
@@ -52,11 +56,21 @@ public class ImportSharedLibraryHandler extends AbstractHandler {
         final String selected = fd.open();\r
         if(selected == null) return null;\r
 \r
-        Job job = new DatabaseJob("Import model") {\r
+        Job job = new DatabaseJob("Import Shared Library") {\r
 \r
             @Override\r
             protected IStatus run(IProgressMonitor monitor) {\r
-               ModelingUtils.importSharedOntology(selected);\r
+               monitor.beginTask("Importing Shared Library " + selected, 3);\r
+               try {\r
+                       monitor.worked(1);\r
+                                       ModelingUtils.importSharedOntology(selected);\r
+                                       monitor.worked(2);\r
+               } catch (Exception e) {\r
+                       ExceptionUtils.logAndShowError(e);\r
+                       ErrorLogger.defaultLogError("Shared Library import failed, see exception for details.", e);\r
+               } finally {\r
+                                       monitor.done();\r
+                               }\r
                 return Status.OK_STATUS;\r
             }\r
         };\r
index 3e0eed5732c8e4773f10592a7620d490698b075c..9aa85f83ca00aba3907cc4b4b95d56769bab7fd6 100644 (file)
@@ -35,7 +35,7 @@ public class ImportUtilsUI {
     /* ********************************* */\r
     /* *******   IMPORT MODEL  ********* */\r
     /* ********************************* */\r
-    public static IStatus importModelFile(String path, IProgressMonitor monitor) {\r
+    public static IStatus importModelFile(String path, IProgressMonitor monitor) throws Exception {\r
         Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent());\r
         return ImportUtils.importModelFile(path, monitor);\r
     }\r
index e91798ed70148fe5ea96baeb6c1b97b2edfce22e..a4c69b9c9fb612d025c18c9ad77c17b56ce7ce5e 100644 (file)
@@ -187,8 +187,18 @@ public class WizardModelsImportPage extends WizardPage{
                        setErrorMessage("No file selected");\r
                        return false;\r
                }\r
-               \r
-               IStatus status = ImportUtilsUI.importModelFile(selected, null);\r
+\r
+               try {\r
+                       IStatus status = ImportUtilsUI.importModelFile(selected, null);\r
+                       if(status == null || !status.equals(Status.OK_STATUS)) {\r
+                           setErrorMessage(status.getMessage());\r
+                           return false;\r
+                       }\r
+                       return true;\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       return false;\r
+               }\r
                \r
         /*\r
                TransferableGraph1 tg = null;\r
@@ -257,11 +267,11 @@ public class WizardModelsImportPage extends WizardPage{
                        return false;\r
                }\r
                */\r
-               if(status == null || !status.equals(Status.OK_STATUS)) {\r
-                   setErrorMessage(status.getMessage());\r
-                   return false;\r
-               }\r
-               return true;            \r
+//             if(status == null || !status.equals(Status.OK_STATUS)) {\r
+//                 setErrorMessage(status.getMessage());\r
+//                 return false;\r
+//             }\r
+//             return true;            \r
        }\r
        \r
        /**\r
index 2247106a65b39d56b20d12188be93bc3987e0d8d..0d5c613136044ea90016598c8c14261fd9848ea4 100644 (file)
@@ -481,15 +481,19 @@ public class DocumentationUtils {
      */\r
     public static Resource importModel(String path) {\r
        final DataContainer<Resource> m = new DataContainer<Resource>();\r
-        ImportUtils.importModelFile(path, new NullProgressMonitor(), new FunctionImpl1<Resource,WriteRequest>() {\r
+        try {\r
+                       ImportUtils.importModelFile(path, new NullProgressMonitor(), new FunctionImpl1<Resource,WriteRequest>() {\r
 \r
-               @Override\r
-               public WriteRequest apply(Resource model) {\r
-                       m.set(model);\r
-                       return null;\r
-               }\r
-               \r
-        });\r
+                               @Override\r
+                               public WriteRequest apply(Resource model) {\r
+                                       m.set(model);\r
+                                       return null;\r
+                               }\r
+                               \r
+                       });\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
         return m.get();\r
     }\r
 \r
index 75a83b4b82ebb7afdbc9ab8e98405d8a4b0e00e5..405fc79f906db4e4804b5f00292d073449d969e1 100644 (file)
@@ -135,10 +135,10 @@ public class ImportUtils {
     /* ********************************* */\r
     /* *******   IMPORT MODEL  ********* */\r
     /* ********************************* */\r
-    public static IStatus importModelFile(String path, final IProgressMonitor monitor) {\r
+    public static IStatus importModelFile(String path, final IProgressMonitor monitor) throws Exception {\r
         return importModelFile(path, monitor, null);\r
     }\r
-    public static IStatus importModelFile(String path, final IProgressMonitor monitor, Function1<Resource,WriteRequest> callback) {\r
+    public static IStatus importModelFile(String path, final IProgressMonitor monitor, Function1<Resource,WriteRequest> callback) throws Exception {\r
         final Resource project = Simantics.getProject().get();\r
         if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null);\r
 \r
@@ -153,6 +153,7 @@ public class ImportUtils {
             result = MigrationUtils.importMigrated(monitor, Simantics.getSession(), new File(path), state, new DefaultPasteImportAdvisor(project), project);\r
         } catch (Exception e1) {\r
             e1.printStackTrace();\r
+            throw e1;\r
         }\r
 \r
         if(result == null || !(result instanceof Resource)) {\r