X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fui%2Fwizard%2FFileSelectionPage.java;fp=bundles%2Forg.simantics.document.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fui%2Fwizard%2FFileSelectionPage.java;h=89bbb5301c647e3c70d2802637289388b4777c45;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..89bbb5301 --- /dev/null +++ b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/wizard/FileSelectionPage.java @@ -0,0 +1,77 @@ +package org.simantics.document.ui.wizard; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Text; + +public class FileSelectionPage extends WizardPage { + + Text fileText; + Button browseButton; + + String fileName; + + public FileSelectionPage() { + super("FileSelction","Select a file",null); + } + + @Override + public void createControl(Composite parent) { + parent.setLayout(new GridLayout(3,false)); + fileText = new Text(parent,SWT.BORDER|SWT.SINGLE); + browseButton = new Button(parent, SWT.PUSH); + browseButton.setText("Browse"); + + GridData data; + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = SWT.FILL; + data.horizontalSpan = 2; + fileText.setLayoutData(data); + + data = new GridData(); + data.horizontalAlignment = SWT.FILL; + browseButton.setLayoutData(data); + + browseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(),SWT.OPEN); + // TODO : is there any way to read file/executable bindings from OS? + // if is, use those extensions to filter this list. + // note: in windows using "reg query ..." to read bindings form registry would work. + dialog.setFilterExtensions(new String[]{"*.*"}); + String name = dialog.open(); + if (name != null) { + fileText.setText(name); + fileName = name; + } + } + }); + + fileText.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + fileName = fileText.getText(); + } + }); + + } + + public String getFileName() { + return fileName; + } + + + +}