automated build configuration is on its way
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ImportFromFileDataSourceWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.io.wizard;
12
13 import java.io.File;
14 import java.net.URI;
15
16 import org.eclipse.jface.wizard.WizardPage;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.FileDialog;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27
28 /**
29 * <p>ImportFromFileDataSourceWizardPage class.</p>
30 *
31 * @author n.hoffmann
32 * @created 04.08.2009
33 * @version 1.0
34 */
35 public class ImportFromFileDataSourceWizardPage extends WizardPage {
36
37 /** Constant <code>PAGE_NAME="CdmXmlDataSourceWizardPage"</code> */
38 public static final String PAGE_NAME = "CdmXmlDataSourceWizardPage";
39
40 private String[] extensions = {"*.xml"};
41
42 private FileDialog fileDialog;
43
44 private Text text_file;
45
46
47 /**
48 * <p>Constructor for ImportFromFileDataSourceWizardPage.</p>
49 *
50 * @param title a {@link java.lang.String} object.
51 * @param description a {@link java.lang.String} object.
52 * @param extensions an array of {@link java.lang.String} objects.
53 */
54 protected ImportFromFileDataSourceWizardPage(String title, String description, String[] extensions) {
55 super(PAGE_NAME);
56
57 setTitle(title);
58
59 setDescription(description);
60
61 this.extensions = extensions;
62 }
63
64 /**
65 * <p>XML</p>
66 *
67 * @return a {@link eu.etaxonomy.taxeditor.io.wizard.ImportFromFileDataSourceWizardPage} object.
68 */
69 protected static ImportFromFileDataSourceWizardPage XML(){
70 return new ImportFromFileDataSourceWizardPage("Xml File", "Select XML file.", new String[]{"*.xml"});
71 }
72
73
74
75 /* (non-Javadoc)
76 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
77 */
78 /** {@inheritDoc} */
79 public void createControl(Composite parent) {
80 final Composite composite = new Composite(parent, SWT.NULL);
81
82 setPageComplete(false);
83
84 GridLayout gridLayout = new GridLayout();
85 gridLayout.numColumns = 3;
86 composite.setLayout(gridLayout);
87
88 Label folderLabel = new Label(composite, SWT.NONE);
89 folderLabel.setText("File");
90
91 fileDialog = new FileDialog(parent.getShell());
92
93 fileDialog.setFilterExtensions(extensions);
94
95 text_file = new Text(composite, SWT.BORDER);
96 text_file.setEditable(false);
97 text_file.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
98
99
100 Button button = new Button(composite, SWT.PUSH);
101 button.setText("Browse...");
102
103 button.addSelectionListener(new SelectionAdapter(){
104
105 /* (non-Javadoc)
106 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
107 */
108 @Override
109 public void widgetSelected(SelectionEvent e) {
110 String path = fileDialog.open();
111 text_file.setText(path);
112 setPageComplete(true);
113 }
114
115 });
116
117 setControl(composite);
118 }
119
120 /**
121 * <p>getFile</p>
122 *
123 * @return a {@link java.io.File} object.
124 */
125 public File getFile() {
126 return new File(text_file.getText());
127 }
128
129 /**
130 * <p>getUri</p>
131 *
132 * @return a {@link java.net.URI} object.
133 */
134 public URI getUri() {
135 return getFile().toURI();
136 }
137 }