}
public static File fileDialog(String title, List<Tuple> namesAndExtensions) {
-
- Display display = Display.getCurrent();
- Shell shell = display.getActiveShell();
-
- FileDialog dialog = new FileDialog(shell, SWT.OPEN);
- dialog.setText(title);
-
- String[] extensions = new String[namesAndExtensions.size()];
- String[] filterNames = new String[namesAndExtensions.size()];
- int index = 0;
- for(Tuple t : namesAndExtensions) {
- String filterName = (String)t.get(0);
- String extension = (String)t.get(1);
- filterNames[index] = filterName;
- extensions[index] = extension;
- index++;
- }
-
- dialog.setFilterExtensions(extensions);
- dialog.setFilterNames(filterNames);
- final String fileName = dialog.open();
- if (fileName == null) return null;
-
- return new File(fileName);
+ return new Runnable() {
+ private File result;
+
+ File getFile() {
+ Display.getDefault().syncExec(this);
+ return result;
+ }
+
+ @Override
+ public void run() {
+ result = showDialog();
+ }
+ private File showDialog() {
+ Display display = Display.getCurrent();
+ Shell shell = display.getActiveShell();
+
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setText(title);
+
+ String[] extensions = new String[namesAndExtensions.size()];
+ String[] filterNames = new String[namesAndExtensions.size()];
+ int index = 0;
+ for(Tuple t : namesAndExtensions) {
+ String filterName = (String)t.get(0);
+ String extension = (String)t.get(1);
+ filterNames[index] = filterName;
+ extensions[index] = extension;
+ index++;
+ }
+
+ dialog.setFilterExtensions(extensions);
+ dialog.setFilterNames(filterNames);
+ final String fileName = dialog.open();
+ if (fileName == null) return null;
+
+ return new File(fileName);
+ }
+ }.getFile();
}
public static Resource createLibrary(WriteGraph graph, Resource parent) throws DatabaseException {