*******************************************************************************/\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
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
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
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
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
});\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
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