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 String filename = dialog.open();
29 String path = dialog.getFilterPath();
30 String names[] = dialog.getFileNames();
31 String fullpath[] = new String[names.length];
32 for (int i = 0; i < names.length; i++) {
33 fullpath[i] = path + File.separator + names[i];
39 protected boolean isValid(File file) {
40 boolean accept = file.exists() && file.canRead();
44 public String[] getFilterExtensions() {
45 return filterExtensions;
48 public String[] getFilterNames() {
52 public void setFilterExtensions(String[] filterExtensions) {
53 this.filterExtensions = filterExtensions;
56 public void setFilterNames(String[] filterNames) {
57 this.filterNames = filterNames;