]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/wizard/FileSelectionPage.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/wizard/FileSelectionPage.java
new file mode 100644 (file)
index 0000000..89bbb53
--- /dev/null
@@ -0,0 +1,77 @@
+package org.simantics.document.ui.wizard;\r
+\r
+import org.eclipse.jface.wizard.WizardPage;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.KeyAdapter;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Button;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Text;\r
+\r
+public class FileSelectionPage extends WizardPage {\r
+       \r
+       Text fileText;\r
+       Button browseButton;\r
+       \r
+       String fileName;\r
+\r
+       public FileSelectionPage() {\r
+               super("FileSelction","Select a file",null);\r
+       }\r
+\r
+       @Override\r
+       public void createControl(Composite parent) {\r
+               parent.setLayout(new GridLayout(3,false));\r
+               fileText = new Text(parent,SWT.BORDER|SWT.SINGLE);\r
+               browseButton = new Button(parent, SWT.PUSH);\r
+               browseButton.setText("Browse");\r
+               \r
+               GridData data;\r
+               data = new GridData();\r
+               data.grabExcessHorizontalSpace = true;\r
+               data.horizontalAlignment = SWT.FILL;\r
+               data.horizontalSpan = 2;\r
+               fileText.setLayoutData(data);\r
+               \r
+               data = new GridData();\r
+               data.horizontalAlignment = SWT.FILL;\r
+               browseButton.setLayoutData(data);\r
+               \r
+               browseButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(),SWT.OPEN);\r
+                               // TODO : is there any way to read file/executable bindings from OS?\r
+                               //        if is, use those extensions to filter this list.\r
+                               //        note: in windows using "reg query ..." to read bindings form registry would work.\r
+                               dialog.setFilterExtensions(new String[]{"*.*"});\r
+                               String name = dialog.open();\r
+                               if (name != null) {\r
+                                       fileText.setText(name);\r
+                                       fileName = name;\r
+                               }\r
+                       }\r
+               });\r
+               \r
+               fileText.addKeyListener(new KeyAdapter() {\r
+                       @Override\r
+                       public void keyReleased(KeyEvent e) {\r
+                               fileName = fileText.getText();\r
+                       }\r
+               });\r
+               \r
+       }\r
+       \r
+       public String getFileName() {\r
+               return fileName;\r
+       }\r
+       \r
+       \r
+\r
+}\r