Project

General

Profile

Download (3.59 KB) Statistics
| Branch: | Tag: | Revision:
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
import eu.etaxonomy.cdm.common.CdmUtils;
29

    
30
/**
31
 * <p>ImportFromFileDataSourceWizardPage class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created 04.08.2009
35
 * @version 1.0
36
 */
37
public class ImportFromFileDataSourceWizardPage extends WizardPage {
38

    
39
	/** Constant <code>PAGE_NAME="CdmXmlDataSourceWizardPage"</code> */
40
	public static final String PAGE_NAME = "CdmXmlDataSourceWizardPage";
41

    
42
	private String[] extensions = {"*.xml"};
43

    
44
	private FileDialog fileDialog;
45

    
46
	private Text text_file;
47

    
48

    
49
	/**
50
	 * <p>Constructor for ImportFromFileDataSourceWizardPage.</p>
51
	 *
52
	 * @param title a {@link java.lang.String} object.
53
	 * @param description a {@link java.lang.String} object.
54
	 * @param extensions an array of {@link java.lang.String} objects.
55
	 */
56
	protected ImportFromFileDataSourceWizardPage(String title, String description, String[] extensions) {
57
		super(PAGE_NAME);
58

    
59
		setTitle(title);
60

    
61
		setDescription(description);
62

    
63
		this.extensions = extensions;
64
	}
65

    
66
	/**
67
	 * <p>XML</p>
68
	 *
69
	 * @return a {@link eu.etaxonomy.taxeditor.io.wizard.ImportFromFileDataSourceWizardPage} object.
70
	 */
71
	protected static ImportFromFileDataSourceWizardPage XML(){
72
		return new ImportFromFileDataSourceWizardPage("Xml File", "Select XML file.", new String[]{"*.xml","*.*"});
73
	}
74

    
75

    
76

    
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
79
	 */
80
	/** {@inheritDoc} */
81
	@Override
82
    public void createControl(Composite parent) {
83
		final Composite composite = new Composite(parent, SWT.NULL);
84

    
85
		setPageComplete(false);
86

    
87
		GridLayout gridLayout = new GridLayout();
88
		gridLayout.numColumns = 3;
89
		composite.setLayout(gridLayout);
90

    
91
		Label folderLabel = new Label(composite, SWT.NONE);
92
		folderLabel.setText("File");
93

    
94
		fileDialog = new FileDialog(parent.getShell());
95

    
96
		fileDialog.setFilterExtensions(extensions);
97

    
98
		text_file = new Text(composite, SWT.BORDER);
99
		text_file.setEditable(false);
100
		text_file.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
101

    
102

    
103
		Button button = new Button(composite, SWT.PUSH);
104
		button.setText("Browse...");
105

    
106
		button.addSelectionListener(new SelectionAdapter(){
107

    
108
			/* (non-Javadoc)
109
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
110
			 */
111
			@Override
112
			public void widgetSelected(SelectionEvent e) {
113
				String path = fileDialog.open();
114
				if(path!=null){
115
				    text_file.setText(path);
116
				    setPageComplete(true);
117
				}
118
			}
119

    
120
		});
121

    
122

    
123
		setControl(composite);
124
	}
125

    
126
	/**
127
	 * <p>getFile</p>
128
	 *
129
	 * @return a {@link java.io.File} object.
130
	 */
131
	public File getFile() {
132
		return new File(text_file.getText());
133
	}
134

    
135
	/**
136
	 * <p>getUri</p>
137
	 *
138
	 * @return a {@link java.net.URI} object.
139
	 */
140
	public URI getUri() {
141
		return getFile().toURI();
142
	}
143

    
144
	@Override
145
	public boolean isPageComplete() {
146
		return CdmUtils.isNotBlank(text_file.getText());
147
	}
148

    
149
}
(15-15/24)