1 package org.simantics.utils.ui.widgets;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.FileDialog;
9 public class FileSelectionWidget extends FileOrDirectorySelectionWidget {
12 String[] filterExtensions = new String[]{"*.*"};
13 String[] filterNames = new String[]{"All files"};
16 public FileSelectionWidget(Composite parent, String name, int style) {
17 super(parent, name, style&~(SWT.OPEN|SWT.CLOSE));
18 this.style = style & (SWT.OPEN|SWT.CLOSE|SWT.MULTI);
22 protected String[] openDialog() {
23 FileDialog dialog = new FileDialog(getShell(),style);
24 dialog.setFilterExtensions(getFilterExtensions());
25 dialog.setFilterNames(getFilterNames());
26 if (filename != null && filename.length == 1)
27 dialog.setFileName(filename[0]);
28 String filename = dialog.open();
31 String path = dialog.getFilterPath();
32 String names[] = dialog.getFileNames();
33 String fullpath[] = new String[names.length];
34 for (int i = 0; i < names.length; i++) {
35 fullpath[i] = path + File.separator + names[i];
41 protected boolean isValid(File file) {
42 boolean accept = file.exists() && file.canRead();
46 public String[] getFilterExtensions() {
47 return filterExtensions;
50 public String[] getFilterNames() {
54 public void setFilterExtensions(String[] filterExtensions) {
55 this.filterExtensions = filterExtensions;
58 public void setFilterNames(String[] filterNames) {
59 this.filterNames = filterNames;