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
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
\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
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
// 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
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
/* ********************************* */\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
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
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
*/\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
/* ********************************* */\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
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