]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/widgets/FileSelectionWidget.java
Fixed a bug related to the extent of variable frames (see test case)
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / widgets / FileSelectionWidget.java
1 package org.simantics.utils.ui.widgets;
2
3 import java.io.File;
4
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.FileDialog;
8
9 public class FileSelectionWidget extends FileOrDirectorySelectionWidget {
10
11         
12         String[] filterExtensions = new String[]{"*.*"};
13         String[] filterNames = new String[]{"All files"};
14         int style = SWT.OPEN;
15         
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);
19         }
20
21         @Override
22         protected String[] openDialog() {
23                 FileDialog dialog = new FileDialog(getShell(),style);
24                 dialog.setFilterExtensions(getFilterExtensions());
25                 dialog.setFilterNames(getFilterNames());
26                 String filename = dialog.open();
27                 if (filename == null)
28                         return null;
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];
34                 }
35                 return fullpath;
36         }
37
38         @Override
39         protected boolean isValid(File file) {
40                 boolean accept = file.exists() && file.canRead();
41                 return accept;
42         }
43         
44         public String[] getFilterExtensions() {
45                 return filterExtensions;
46         }
47         
48         public String[] getFilterNames() {
49                 return filterNames;
50         }
51         
52         public void setFilterExtensions(String[] filterExtensions) {
53                 this.filterExtensions = filterExtensions;
54         }
55         
56         public void setFilterNames(String[] filterNames) {
57                 this.filterNames = filterNames;
58         }
59         
60
61 }