]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Removed context menu and added buttons to external function file handling. Selections...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 5 May 2011 12:38:10 +0000 (12:38 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 5 May 2011 12:38:10 +0000 (12:38 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20779 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportExternalFunctionFilesHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java

index cb2355362de8dd34bd2a966c027c3ca635341aed..49de4a6929dd255ffca1539e984d2bb07b0e2bd9 100644 (file)
       </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#ExternalFunctionFileBrowser?after=wbStart">\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.importExternalFunctionFile"\r
-               label="Import Files"\r
-               style="push">\r
-         </command>\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.exportExternalFunctionFile"\r
-               label="Export Files"\r
-               style="push">\r
-         </command>\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.removeNode"\r
-               icon="icons/cross.png"\r
-               id="org.simantics.sysdyn.ui.browser.remove"\r
-               label="Remove"\r
-               style="push">\r
-            <visibleWhen\r
-                  checkEnabled="true">\r
-            </visibleWhen>\r
-         </command>\r
       </menuContribution>\r
    </extension>\r
    <extension\r
index 84573763920e5563768915299f6902bdd34b55af..727bb8be423ec09769fcb7371276e470759b1d98 100644 (file)
@@ -44,6 +44,10 @@ public class ExportExternalFunctionFilesHandler extends AbstractHandler {
                if (resources.length < 1)\r
                        return null;\r
 \r
+               return exportFiles(shell, resources);\r
+       }\r
+       \r
+       public static Object exportFiles(Shell shell, final Resource[] resources) {\r
                DirectoryDialog dd = new DirectoryDialog(shell);\r
                dd.setFilterPath(Platform.getLocation().toOSString());\r
                dd.setText("Export files to...");\r
@@ -72,7 +76,6 @@ public class ExportExternalFunctionFilesHandler extends AbstractHandler {
                                \r
                        }\r
                });\r
-\r
                return null;\r
        }\r
 \r
index 0391d90b425794f1fac21651b8571568a1208ee0..e2ee3669972ce9ac3815d23a149ae17486b984d5 100644 (file)
@@ -50,7 +50,7 @@ public class RemoveNodeHandler extends AbstractHandler {
         return null;\r
     }\r
 \r
-    private void deleteItem(final Resource[] resources) {\r
+    public static void deleteItem(final Resource[] resources) {\r
         try {\r
             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                 @Override\r
index b965ed6a28cbb4595b3576a067918bc9bd9981dc..407ea60c4d9b16d06a972671d6e1a5d571d7acc5 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.properties;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Tree;\r
 import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
 import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
 import org.simantics.browsing.ui.swt.widgets.Button;\r
 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
@@ -30,7 +38,9 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.ui.handlers.ExportExternalFunctionFilesHandler;\r
 import org.simantics.sysdyn.ui.handlers.ImportExternalFunctionFilesHandler;\r
+import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
 import org.simantics.utils.datastructures.Pair;\r
@@ -38,7 +48,7 @@ import org.simantics.utils.datastructures.Pair;
 public class ExternalFilesTab extends LabelPropertyTabContributor implements Widget {\r
 \r
        GraphExplorerComposite externalFilesExplorer;\r
-       Button importButton; \r
+       Button importButton, exportButton, removeButton\r
        \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site,\r
@@ -67,7 +77,12 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                if (c instanceof Tree)\r
                        ((Tree) c).setLinesVisible(true);\r
                \r
-               importButton = new Button(composite, support, SWT.NONE);\r
+               \r
+               Composite buttonRow = new Composite(composite, SWT.NONE);\r
+               GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonRow);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonRow);\r
+               \r
+               importButton = new Button(buttonRow, support, SWT.NONE);\r
                importButton.setText("Import");\r
                importButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
 \r
@@ -84,7 +99,7 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                                                final Pair<String, String[]> importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS);\r
                                                \r
                                                SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                                                       \r
+\r
                                                        @Override\r
                                                        public void perform(WriteGraph graph) throws DatabaseException {\r
                                                                ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles);\r
@@ -92,11 +107,65 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                                                });\r
                                        }\r
                                });\r
-                               \r
-                               \r
+\r
+\r
+                       }\r
+               });\r
+\r
+               exportButton = new Button(buttonRow, support, SWT.NONE);\r
+               exportButton.setText("Export");\r
+               exportButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, final Resource input)\r
+                       throws DatabaseException {\r
+\r
+                               exportButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+                                       @Override\r
+                                       public void run() {\r
+                                               Shell shell = exportButton.getWidget().getShell();\r
+                                               List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
+                                               Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+                                               if (resources.length > 0)\r
+                                                       ExportExternalFunctionFilesHandler.exportFiles(shell, resources);\r
+                                       }\r
+                               });\r
+\r
+\r
+                       }\r
+               });\r
+\r
+               removeButton = new Button(buttonRow, support, SWT.NONE);\r
+               removeButton.setText("Remove");\r
+               removeButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, final Resource input)\r
+                       throws DatabaseException {\r
+\r
+                               removeButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+                                       @Override\r
+                                       public void run() {\r
+                                               Shell shell = removeButton.getWidget().getShell();\r
+\r
+                                               List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
+                                               Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+                                               if(resources.length > 0) {\r
+                                                       MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0,\r
+                                                                       new String[] { "OK", "Cancel" }, 0);\r
+                                                       dialog.create();\r
+                                                       if (dialog.open() == 0) {\r
+                                                               RemoveNodeHandler.deleteItem(resources);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               });\r
+\r
+\r
                        }\r
                });\r
-               \r
        }\r
 \r
        @Override\r
@@ -104,5 +173,21 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                externalFilesExplorer.setInput(context, input);\r
        }\r
 \r
+       private List<Resource> getSelectedResources(GraphExplorerComposite explorer) {\r
+               List<Resource> result = new ArrayList<Resource>();\r
+               \r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return result;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               @SuppressWarnings("unchecked")\r
+               List<AdaptableHintContext> selections = iss.toList();\r
+               for(AdaptableHintContext ahc : selections) {\r
+                       Resource resource = (Resource) ahc.getAdapter(Resource.class);\r
+                       result.add(resource);\r
+               }\r
+               return result;\r
+       }\r
 \r
 }\r