- fixed NPE
[taxeditor.git] / eu.etaxonomy.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 @Override
80 public void createControl(Composite parent) {
81 final Composite composite = new Composite(parent, SWT.NULL);
82
83 setPageComplete(false);
84
85 GridLayout gridLayout = new GridLayout();
86 gridLayout.numColumns = 3;
87 composite.setLayout(gridLayout);
88
89 Label folderLabel = new Label(composite, SWT.NONE);
90 folderLabel.setText("File");
91
92 fileDialog = new FileDialog(parent.getShell());
93
94 fileDialog.setFilterExtensions(extensions);
95
96 text_file = new Text(composite, SWT.BORDER);
97 text_file.setEditable(false);
98 text_file.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
99
100
101 Button button = new Button(composite, SWT.PUSH);
102 button.setText("Browse...");
103
104 button.addSelectionListener(new SelectionAdapter(){
105
106 /* (non-Javadoc)
107 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
108 */
109 @Override
110 public void widgetSelected(SelectionEvent e) {
111 String path = fileDialog.open();
112 if(path!=null){
113 text_file.setText(path);
114 setPageComplete(true);
115 }
116 }
117
118 });
119
120 setControl(composite);
121 }
122
123 /**
124 * <p>getFile</p>
125 *
126 * @return a {@link java.io.File} object.
127 */
128 public File getFile() {
129 return new File(text_file.getText());
130 }
131
132 /**
133 * <p>getUri</p>
134 *
135 * @return a {@link java.net.URI} object.
136 */
137 public URI getUri() {
138 return getFile().toURI();
139 }
140 }