]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Print Sysdyn model name to satus line when modle is exported. (refs #4742)
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 21 Feb 2014 11:16:20 +0000 (11:16 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 21 Feb 2014 11:16:20 +0000 (11:16 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28914 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelAsButtonHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelButtonHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java

index e90bae08b3142174ba207d57f7ef630e74d89b79..04104b1c178f01ca037f89d72199de8a1bb372d5 100644 (file)
       <handler\r
             class="org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler"\r
             commandId="org.simantics.sysdyn.ui.importModel">\r
-         <activeWhen></activeWhen>\r
       </handler>\r
       <handler\r
             class="org.simantics.sysdyn.ui.handlers.exports.ExportModelHandler"\r
index 57a6cb424d000bf87bf823e6f24455a3f262ba56..8e6318423c80cb68097be98b038a33e6b598e4cc 100644 (file)
@@ -13,7 +13,9 @@ package org.simantics.sysdyn.ui.handlers.exports;
 \r
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.db.Resource;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
 \r
 /**\r
  * Exports a selected model asking the location.\r
@@ -27,15 +29,19 @@ public class ExportModelAsButtonHandler extends ExportModelButtonHandler {
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
         \r
+               status = WorkbenchUtils.getStatusLine( HandlerUtil.getActiveSite(event) );\r
+        \r
                final Resource model = determineModel(event);\r
         if (model == null)\r
                return null;\r
         \r
         String selected = getAbsolutePath(model, event, true);\r
         \r
-        if (selected != null)\r
+        if (selected != null) {\r
                createFile(model, selected);\r
-               \r
+               setExportStatus(model, selected);\r
+        }\r
+        \r
                return null;\r
        }\r
 \r
index a9ee8a3255a97fd425361a7d1cb3782e64b8f6e4..9954ae65c07fc094e503e83f297a21dc6247362a 100644 (file)
@@ -30,6 +30,7 @@ import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.utils.ui.AdaptionUtils;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
 \r
 /**\r
  * Exports a selected model without asking the location.\r
@@ -43,16 +44,20 @@ public class ExportModelButtonHandler extends ExportModelHandler {
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
         \r
+               status = WorkbenchUtils.getStatusLine( HandlerUtil.getActiveSite(event) );\r
+        \r
                final Resource model = determineModel(event);\r
         if (model == null)\r
                return null;\r
 \r
         String selected = getAbsolutePath(model, event, false);\r
         \r
-        if (selected != null)\r
+        if (selected != null) {\r
                createFile(model, selected);\r
-               \r
-               return null;\r
+               setExportStatus(model, selected);\r
+        }\r
+        \r
+        return null;\r
        }\r
 \r
        @Override\r
index ee0efbb9a01a5b557bae4f87f2fd5170fbfa4560..7bba5ae9eda22dd5ceec057b2b29c5b4bbaebed4 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException;\r
 import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.action.IStatusLineManager;\r
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.FileDialog;\r
@@ -43,6 +44,7 @@ import org.simantics.sysdyn.ui.Activator;
 import org.simantics.sysdyn.ui.utils.imports.ImportUtilsUI;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
 \r
 /**\r
  * Exports a selected model\r
@@ -54,21 +56,55 @@ import org.simantics.ui.utils.ResourceAdaptionUtils;
  */\r
 public class ExportModelHandler extends AbstractHandler {\r
 \r
+       protected static IStatusLineManager status;\r
+\r
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
 \r
+               status = WorkbenchUtils.getStatusLine( HandlerUtil.getActiveSite(event) );\r
+        \r
                final Resource model = determineModel(event);\r
         if (model == null)\r
                return null;\r
         \r
         String selected = getAbsolutePath(model, event, true);\r
         \r
-        if (selected != null)\r
+        if (selected != null) {\r
                createFile(model, selected);\r
+               setExportStatus(model, selected);\r
+        }\r
 \r
-               return null;\r
+        return null;\r
        }\r
-\r
+       \r
+       /**\r
+        * Create the export file.\r
+        * @param model Model which is exported.\r
+        * @param fileName Full name of the file.\r
+        */\r
+       protected void setExportStatus(final Resource model, final String fileName) {\r
+               try {\r
+                       String modelName = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+       \r
+                               @Override\r
+                               public String perform(ReadGraph graph) throws DatabaseException {\r
+                                       if (!graph.hasStatement(model, Layer0.getInstance(graph).PartOf))\r
+                                               return null;\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       return graph.syncRequest(new PossibleRelatedValue<String>(model, l0.HasName, Bindings.STRING ));\r
+                               }\r
+                               \r
+                       });\r
+       \r
+                       if (modelName != null)\r
+                               setStatus("Saved model \"" + modelName + "\" to " + fileName);\r
+               \r
+               } catch (DatabaseException e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+       \r
        /**\r
         * Create the export file.\r
         * @param model Model which is exported.\r
@@ -236,4 +272,10 @@ public class ExportModelHandler extends AbstractHandler {
                return selected;\r
 \r
        }\r
+       \r
+    protected static void setStatus(final String message) {\r
+       if (status != null)\r
+            status.setMessage(message);\r
+    }\r
+\r
 }\r