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.text.SimpleDateFormat;
|
14
|
import java.util.Calendar;
|
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.DirectoryDialog;
|
25
|
import org.eclipse.swt.widgets.Label;
|
26
|
import org.eclipse.swt.widgets.Text;
|
27
|
|
28
|
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
|
29
|
|
30
|
/**
|
31
|
* <p>
|
32
|
* ExportToFileDestinationWizardPage class.
|
33
|
* </p>
|
34
|
*
|
35
|
* @author n.hoffmann
|
36
|
* @created 15.06.2009
|
37
|
* @version 1.0
|
38
|
*/
|
39
|
public class ExportToFileDestinationWizardPage extends WizardPage {
|
40
|
|
41
|
/** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
|
42
|
public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
|
43
|
|
44
|
/** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
|
45
|
public static final String JAXB_EXPORT = "JAXB_EXPORT";
|
46
|
|
47
|
/** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
|
48
|
public static final String TCS_EXPORT = "TCS_EXPORT";
|
49
|
|
50
|
/** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
|
51
|
public static final String SDD_EXPORT = "SDD_EXPORT";
|
52
|
|
53
|
public static final String DWCA_EXPORT = "DWCA_EXPORT";
|
54
|
|
55
|
public static final String XML = "xml";
|
56
|
|
57
|
public static final String ZIP = "zip";
|
58
|
|
59
|
private DirectoryDialog folderDialog;
|
60
|
private Text text_exportFileName;
|
61
|
|
62
|
private Text text_folder;
|
63
|
|
64
|
private final String type;
|
65
|
|
66
|
private final String extension;
|
67
|
|
68
|
/**
|
69
|
* @param pageName
|
70
|
* @param selection
|
71
|
*/
|
72
|
private ExportToFileDestinationWizardPage(String pageName, String type,
|
73
|
String title, String description, String extension) {
|
74
|
super(pageName);
|
75
|
|
76
|
this.type = type;
|
77
|
this.extension = extension;
|
78
|
this.setTitle(title);
|
79
|
this.setDescription(description);
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* <p>
|
84
|
* Jaxb
|
85
|
* </p>
|
86
|
*
|
87
|
* @return a
|
88
|
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
|
89
|
* object.
|
90
|
*/
|
91
|
public static ExportToFileDestinationWizardPage Jaxb() {
|
92
|
return new ExportToFileDestinationWizardPage(
|
93
|
JAXB_EXPORT,
|
94
|
"jaxb",
|
95
|
"JAXB Export",
|
96
|
"Exports the contents of the currently selected database into the cdm jaxb format.",
|
97
|
XML);
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* <p>
|
102
|
* Tcs
|
103
|
* </p>
|
104
|
*
|
105
|
* @return a
|
106
|
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
|
107
|
* object.
|
108
|
*/
|
109
|
public static ExportToFileDestinationWizardPage Tcs() {
|
110
|
return new ExportToFileDestinationWizardPage(
|
111
|
TCS_EXPORT,
|
112
|
"tcs",
|
113
|
"Tcs Export",
|
114
|
"Export the contents of the currently selected database into TCS format.",
|
115
|
XML);
|
116
|
}
|
117
|
|
118
|
/**
|
119
|
* <p>
|
120
|
* Sdd
|
121
|
* </p>
|
122
|
*
|
123
|
* @return a
|
124
|
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
|
125
|
* object.
|
126
|
*/
|
127
|
public static ExportToFileDestinationWizardPage Sdd() {
|
128
|
return new ExportToFileDestinationWizardPage(
|
129
|
SDD_EXPORT,
|
130
|
"sdd",
|
131
|
"Sdd Export",
|
132
|
"Export the contents of the currently selected database into SDD format.",
|
133
|
XML);
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* @return
|
138
|
*/
|
139
|
public static ExportToFileDestinationWizardPage Dwca() {
|
140
|
return new ExportToFileDestinationWizardPage(
|
141
|
DWCA_EXPORT,
|
142
|
"dwca",
|
143
|
"DwC-Archive Export",
|
144
|
"Export the contents of the currently selected database into Darwin Core Archive format.",
|
145
|
ZIP);
|
146
|
}
|
147
|
|
148
|
/*
|
149
|
* (non-Javadoc)
|
150
|
*
|
151
|
* @see
|
152
|
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
|
153
|
* .Composite)
|
154
|
*/
|
155
|
/** {@inheritDoc} */
|
156
|
public void createControl(Composite parent) {
|
157
|
|
158
|
setPageComplete(false);
|
159
|
|
160
|
Composite composite = new Composite(parent, SWT.NONE);
|
161
|
GridLayout gridLayout = new GridLayout();
|
162
|
gridLayout.numColumns = 3;
|
163
|
composite.setLayout(gridLayout);
|
164
|
|
165
|
Label fileLabel = new Label(composite, SWT.NONE);
|
166
|
fileLabel.setText("File");
|
167
|
|
168
|
text_exportFileName = new Text(composite, SWT.BORDER);
|
169
|
text_exportFileName.setText(generateFilename());
|
170
|
text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
171
|
true, false, 2, 1));
|
172
|
|
173
|
Label folderLabel = new Label(composite, SWT.NONE);
|
174
|
folderLabel.setText("Folder");
|
175
|
|
176
|
folderDialog = new DirectoryDialog(parent.getShell());
|
177
|
|
178
|
text_folder = new Text(composite, SWT.BORDER);
|
179
|
text_folder.setEditable(false);
|
180
|
text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
|
181
|
false));
|
182
|
|
183
|
Button button = new Button(composite, SWT.PUSH);
|
184
|
button.setText("Browse...");
|
185
|
|
186
|
button.addSelectionListener(new SelectionAdapter() {
|
187
|
/*
|
188
|
* (non-Javadoc)
|
189
|
*
|
190
|
* @see
|
191
|
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
|
192
|
* .swt.events.SelectionEvent)
|
193
|
*/
|
194
|
@Override
|
195
|
public void widgetSelected(SelectionEvent e) {
|
196
|
super.widgetSelected(e);
|
197
|
String path = folderDialog.open();
|
198
|
if (path != null) { // a folder was selected
|
199
|
text_folder.setText(path);
|
200
|
setPageComplete(true);
|
201
|
}
|
202
|
}
|
203
|
});
|
204
|
|
205
|
// make the composite the wizard pages control
|
206
|
setControl(composite);
|
207
|
}
|
208
|
|
209
|
private String generateFilename() {
|
210
|
StringBuffer buffer = new StringBuffer();
|
211
|
|
212
|
Calendar cal = Calendar.getInstance();
|
213
|
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
|
214
|
buffer.append(sdf.format(cal.getTime()));
|
215
|
|
216
|
buffer.append("-");
|
217
|
|
218
|
buffer.append(type + "_export-");
|
219
|
buffer.append(CdmDataSourceRepository.getCurrentDataSource());
|
220
|
|
221
|
buffer.append(".");
|
222
|
buffer.append(extension);
|
223
|
|
224
|
return buffer.toString();
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* <p>
|
229
|
* getExportFileName
|
230
|
* </p>
|
231
|
*
|
232
|
* @return the exportFileName
|
233
|
*/
|
234
|
public String getExportFileName() {
|
235
|
return text_exportFileName.getText();
|
236
|
}
|
237
|
|
238
|
/**
|
239
|
* <p>
|
240
|
* getFolderText
|
241
|
* </p>
|
242
|
*
|
243
|
* @return the folderText
|
244
|
*/
|
245
|
public String getFolderText() {
|
246
|
return text_folder.getText();
|
247
|
}
|
248
|
|
249
|
}
|