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