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.e4.in;
|
11
|
|
12
|
import java.io.File;
|
13
|
import java.net.URI;
|
14
|
|
15
|
import javax.inject.Inject;
|
16
|
|
17
|
import org.eclipse.jface.wizard.WizardPage;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.swt.events.SelectionAdapter;
|
20
|
import org.eclipse.swt.events.SelectionEvent;
|
21
|
import org.eclipse.swt.layout.GridData;
|
22
|
import org.eclipse.swt.layout.GridLayout;
|
23
|
import org.eclipse.swt.widgets.Button;
|
24
|
import org.eclipse.swt.widgets.Composite;
|
25
|
import org.eclipse.swt.widgets.FileDialog;
|
26
|
import org.eclipse.swt.widgets.Label;
|
27
|
import org.eclipse.swt.widgets.Text;
|
28
|
|
29
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
* @author pplitzner
|
34
|
* @since Oct 5, 2017
|
35
|
*
|
36
|
*/
|
37
|
public class ImportFromFileDataSourceWizardPageE4 extends WizardPage {
|
38
|
|
39
|
public static final String PAGE_NAME = "CdmXmlDataSourceWizardPage";
|
40
|
|
41
|
private String[] extensions = {"*.xml"};
|
42
|
|
43
|
private FileDialog fileDialog;
|
44
|
private Text textReferenceString;
|
45
|
|
46
|
protected Text text_source;
|
47
|
|
48
|
@Inject
|
49
|
public ImportFromFileDataSourceWizardPageE4() {
|
50
|
super(PAGE_NAME);
|
51
|
|
52
|
setTitle("Xml File");
|
53
|
|
54
|
setDescription("Select XML file.");
|
55
|
|
56
|
setExtensions(new String[]{"*.xml","*.*"});
|
57
|
}
|
58
|
|
59
|
public void setExtensions(String[] extensions) {
|
60
|
this.extensions = extensions;
|
61
|
}
|
62
|
|
63
|
/** {@inheritDoc} */
|
64
|
@Override
|
65
|
public void createControl(Composite parent) {
|
66
|
final Composite composite = new Composite(parent, SWT.NULL);
|
67
|
|
68
|
setPageComplete(false);
|
69
|
|
70
|
GridLayout gridLayout = new GridLayout();
|
71
|
gridLayout.numColumns = 3;
|
72
|
composite.setLayout(gridLayout);
|
73
|
|
74
|
Label folderLabel = new Label(composite, SWT.NONE);
|
75
|
folderLabel.setText("File");
|
76
|
|
77
|
fileDialog = new FileDialog(parent.getShell());
|
78
|
|
79
|
fileDialog.setFilterExtensions(extensions);
|
80
|
|
81
|
text_source = new Text(composite, SWT.BORDER);
|
82
|
text_source.setEditable(false);
|
83
|
text_source.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
84
|
|
85
|
|
86
|
Button button = new Button(composite, SWT.PUSH);
|
87
|
button.setText("Browse...");
|
88
|
|
89
|
button.addSelectionListener(new SelectionAdapter(){
|
90
|
|
91
|
@Override
|
92
|
public void widgetSelected(SelectionEvent e) {
|
93
|
String path = fileDialog.open();
|
94
|
if(path!=null){
|
95
|
text_source.setText(path);
|
96
|
setPageComplete(isPageComplete());
|
97
|
}
|
98
|
}
|
99
|
|
100
|
});
|
101
|
|
102
|
Label labelRef = new Label(composite, SWT.NONE);
|
103
|
labelRef.setText("Default import souce reference");
|
104
|
labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
|
105
|
textReferenceString = new Text(composite, SWT.NONE);
|
106
|
textReferenceString.setEnabled(true);
|
107
|
GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
|
108
|
gd_textReferenceString.widthHint = 229;
|
109
|
textReferenceString.setLayoutData(gd_textReferenceString);
|
110
|
setControl(composite);
|
111
|
}
|
112
|
|
113
|
public File getFile() {
|
114
|
return new File(text_source.getText());
|
115
|
}
|
116
|
|
117
|
public Text getTextReferenceString() {
|
118
|
return textReferenceString;
|
119
|
}
|
120
|
|
121
|
public void setTextReferenceString(Text textReferenceString) {
|
122
|
this.textReferenceString = textReferenceString;
|
123
|
}
|
124
|
|
125
|
public URI getUri() {
|
126
|
return getFile().toURI();
|
127
|
}
|
128
|
|
129
|
@Override
|
130
|
public boolean isPageComplete() {
|
131
|
return CdmUtils.isNotBlank(text_source.getText());
|
132
|
}
|
133
|
|
134
|
}
|