]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.ui/src/org/simantics/document/ui/wizard/FileSelectionPage.java
eb43ee79471af3d0da638e45bb426fdcb5a131b7
[simantics/platform.git] / bundles / org.simantics.document.ui / src / org / simantics / document / ui / wizard / FileSelectionPage.java
1 package org.simantics.document.ui.wizard;
2
3 import org.eclipse.jface.wizard.WizardPage;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.KeyAdapter;
6 import org.eclipse.swt.events.KeyEvent;
7 import org.eclipse.swt.events.SelectionAdapter;
8 import org.eclipse.swt.events.SelectionEvent;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Display;
14 import org.eclipse.swt.widgets.FileDialog;
15 import org.eclipse.swt.widgets.Text;
16
17 public class FileSelectionPage extends WizardPage {
18         
19         Text fileText;
20         Button browseButton;
21         
22         String fileName;
23
24         public FileSelectionPage() {
25                 super("FileSelction","Select a file",null);
26         }
27
28         @Override
29         public void createControl(Composite parent) {
30                 parent.setLayout(new GridLayout(3,false));
31                 fileText = new Text(parent,SWT.BORDER|SWT.SINGLE);
32                 browseButton = new Button(parent, SWT.PUSH);
33                 browseButton.setText("Browse");
34                 
35                 GridData data;
36                 data = new GridData();
37                 data.grabExcessHorizontalSpace = true;
38                 data.horizontalAlignment = SWT.FILL;
39                 data.horizontalSpan = 2;
40                 fileText.setLayoutData(data);
41                 
42                 data = new GridData();
43                 data.horizontalAlignment = SWT.FILL;
44                 browseButton.setLayoutData(data);
45                 
46                 browseButton.addSelectionListener(new SelectionAdapter() {
47                         @Override
48                         public void widgetSelected(SelectionEvent e) {
49                                 FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(),SWT.OPEN);
50                                 // TODO : is there any way to read file/executable bindings from OS?
51                                 //        if is, use those extensions to filter this list.
52                                 //        note: in windows using "reg query ..." to read bindings form registry would work.
53                                 dialog.setFilterExtensions(new String[]{"*.*"});
54                                 String name = dialog.open();
55                                 if (name != null) {
56                                         fileText.setText(name);
57                                         fileName = name;
58                                 }
59                         }
60                 });
61                 
62                 fileText.addKeyListener(new KeyAdapter() {
63                         @Override
64                         public void keyReleased(KeyEvent e) {
65                                 fileName = fileText.getText();
66                         }
67                 });
68                 
69         }
70         
71         public String getFileName() {
72                 return fileName;
73         }
74         
75         
76
77 }