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