From d7114d30a29cc46ababfebfce09c6f7f2b3f2fbc Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 5 May 2011 12:38:10 +0000 Subject: [PATCH] Removed context menu and added buttons to external function file handling. Selections for the context menu were not reliable. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20779 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 20 ---- .../ExportExternalFunctionFilesHandler.java | 5 +- .../sysdyn/ui/handlers/RemoveNodeHandler.java | 2 +- .../ui/properties/ExternalFilesTab.java | 97 +++++++++++++++++-- 4 files changed, 96 insertions(+), 28 deletions(-) diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index cb235536..49de4a69 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -512,26 +512,6 @@ - - - - - - - - (context) { @@ -84,7 +99,7 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid final Pair importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS); SimanticsUI.getSession().asyncRequest(new WriteRequest() { - + @Override public void perform(WriteGraph graph) throws DatabaseException { ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles); @@ -92,11 +107,65 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid }); } }); - - + + + } + }); + + exportButton = new Button(buttonRow, support, SWT.NONE); + exportButton.setText("Export"); + exportButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, final Resource input) + throws DatabaseException { + + exportButton.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + Shell shell = exportButton.getWidget().getShell(); + List resourceList = getSelectedResources(externalFilesExplorer); + Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); + if (resources.length > 0) + ExportExternalFunctionFilesHandler.exportFiles(shell, resources); + } + }); + + + } + }); + + removeButton = new Button(buttonRow, support, SWT.NONE); + removeButton.setText("Remove"); + removeButton.addSelectionListener(new SelectionListenerImpl(context) { + + @Override + public void apply(WriteGraph graph, final Resource input) + throws DatabaseException { + + removeButton.getWidget().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + Shell shell = removeButton.getWidget().getShell(); + + List resourceList = getSelectedResources(externalFilesExplorer); + Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]); + if(resources.length > 0) { + MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0, + new String[] { "OK", "Cancel" }, 0); + dialog.create(); + if (dialog.open() == 0) { + RemoveNodeHandler.deleteItem(resources); + } + } + } + }); + + } }); - } @Override @@ -104,5 +173,21 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid externalFilesExplorer.setInput(context, input); } + private List getSelectedResources(GraphExplorerComposite explorer) { + List result = new ArrayList(); + + ISelection selection = ((ISelectionProvider) explorer + .getAdapter(ISelectionProvider.class)).getSelection(); + if (selection == null) + return result; + IStructuredSelection iss = (IStructuredSelection) selection; + @SuppressWarnings("unchecked") + List selections = iss.toList(); + for(AdaptableHintContext ahc : selections) { + Resource resource = (Resource) ahc.getAdapter(Resource.class); + result.add(resource); + } + return result; + } } -- 2.47.1