1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The content 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.text.SimpleDateFormat;
|
13
|
import java.util.Calendar;
|
14
|
import java.util.Collections;
|
15
|
import java.util.Comparator;
|
16
|
import java.util.List;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.eclipse.jface.wizard.WizardPage;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.events.SelectionAdapter;
|
22
|
import org.eclipse.swt.events.SelectionEvent;
|
23
|
import org.eclipse.swt.events.SelectionListener;
|
24
|
import org.eclipse.swt.layout.GridData;
|
25
|
import org.eclipse.swt.layout.GridLayout;
|
26
|
import org.eclipse.swt.widgets.Button;
|
27
|
import org.eclipse.swt.widgets.Combo;
|
28
|
import org.eclipse.swt.widgets.Composite;
|
29
|
import org.eclipse.swt.widgets.DirectoryDialog;
|
30
|
import org.eclipse.swt.widgets.Event;
|
31
|
import org.eclipse.swt.widgets.Label;
|
32
|
import org.eclipse.swt.widgets.Listener;
|
33
|
import org.eclipse.swt.widgets.Text;
|
34
|
|
35
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
36
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
37
|
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
|
38
|
import eu.etaxonomy.cdm.io.common.ExportConfiguratorBase;
|
39
|
import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
|
40
|
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
|
41
|
import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
|
42
|
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
43
|
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
|
44
|
import eu.etaxonomy.cdm.io.tcsxml.out.TcsXmlExportConfigurator;
|
45
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
46
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
47
|
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
|
48
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
49
|
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
|
50
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
51
|
|
52
|
/**
|
53
|
* <p>
|
54
|
* ExportToFileDestinationWizardPage class.
|
55
|
* </p>
|
56
|
*
|
57
|
* @author n.hoffmann
|
58
|
* @created 15.06.2009
|
59
|
* @version 1.0
|
60
|
*/
|
61
|
public class ExportToFileDestinationWizardPage extends WizardPage implements SelectionListener {
|
62
|
|
63
|
/** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
|
64
|
public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
|
65
|
|
66
|
/** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
|
67
|
public static final String JAXB_EXPORT = "JAXB_EXPORT";
|
68
|
|
69
|
/** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
|
70
|
public static final String TCS_EXPORT = "TCS_EXPORT";
|
71
|
|
72
|
/** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
|
73
|
public static final String SDD_EXPORT = "SDD_EXPORT";
|
74
|
|
75
|
public static final String DWCA_EXPORT = "DWCA_EXPORT";
|
76
|
public static final String OUTPUT_MODEL_EXPORT = "CDM_LIGHT(CSV)";
|
77
|
public static final String CSV_EXPORT = "CSV_EXPORT";
|
78
|
public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
|
79
|
private static final String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
|
80
|
private static final String EXPORT_FOLDER ="EXPORT_FOLDER";
|
81
|
public static final String XML = "xml";
|
82
|
|
83
|
public static final String CSV = "csv";
|
84
|
|
85
|
public static final String ZIP = "zip";
|
86
|
|
87
|
private boolean csvExport = false;
|
88
|
|
89
|
private boolean csvNameExport = false;
|
90
|
|
91
|
private boolean csvPrintExport = false;
|
92
|
|
93
|
private boolean outputModelExport = false;
|
94
|
private boolean dwcaExport = false;
|
95
|
|
96
|
private DirectoryDialog folderDialog;
|
97
|
private Text text_exportFileName;
|
98
|
|
99
|
private Text text_folder;
|
100
|
|
101
|
private final String type;
|
102
|
|
103
|
private final String extension;
|
104
|
|
105
|
private Combo classificationSelectionCombo;
|
106
|
|
107
|
private List<Classification> classifications;
|
108
|
|
109
|
private Classification selectedClassification;
|
110
|
|
111
|
private Label classificationLabel;
|
112
|
|
113
|
private ExportConfiguratorBase configurator;
|
114
|
private Button checkUseSelectedtaxonNode;
|
115
|
|
116
|
private Button checkUseSelectedClassification;
|
117
|
|
118
|
protected ExportToFileDestinationWizardPage(String pageName, String type,
|
119
|
String title, String description, String extension, ExportConfiguratorBase configurator) {
|
120
|
super(pageName);
|
121
|
this.configurator = configurator;
|
122
|
this.type = type;
|
123
|
switch(type) {
|
124
|
case CSV_EXPORT :
|
125
|
csvExport = true;
|
126
|
break;
|
127
|
case CSV_NAME_EXPORT:
|
128
|
csvNameExport = true;
|
129
|
break;
|
130
|
case OUTPUT_MODEL_EXPORT:
|
131
|
outputModelExport = true;
|
132
|
break;
|
133
|
case CSV_PRINT_EXPORT:
|
134
|
csvPrintExport = true;
|
135
|
break;
|
136
|
case DWCA_EXPORT:
|
137
|
dwcaExport = true;
|
138
|
break;
|
139
|
|
140
|
}
|
141
|
this.extension = extension;
|
142
|
this.setTitle(title);
|
143
|
this.setDescription(description);
|
144
|
}
|
145
|
|
146
|
public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
|
147
|
return new ExportToFileDestinationWizardPage(
|
148
|
JAXB_EXPORT,
|
149
|
"jaxb",
|
150
|
"JAXB Export",
|
151
|
"Exports the content of the currently selected database into the cdm jaxb format.",
|
152
|
XML, configurator);
|
153
|
}
|
154
|
|
155
|
public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
|
156
|
return new ExportToFileDestinationWizardPage(
|
157
|
TCS_EXPORT,
|
158
|
"tcs",
|
159
|
"Tcs Export",
|
160
|
"Export the content of the currently selected database into TCS format.",
|
161
|
XML, config);
|
162
|
}
|
163
|
|
164
|
public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
|
165
|
return new ExportToFileDestinationWizardPage(
|
166
|
SDD_EXPORT,
|
167
|
"sdd",
|
168
|
"Sdd Export",
|
169
|
"Export the content of the currently selected database into SDD format.",
|
170
|
XML, config);
|
171
|
}
|
172
|
|
173
|
public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
|
174
|
return new ExportToFileDestinationWizardPage(
|
175
|
DWCA_EXPORT,
|
176
|
DWCA_EXPORT,
|
177
|
"DwC-Archive Export",
|
178
|
"Export the content of the currently selected database into Darwin Core Archive format.",
|
179
|
ZIP, config);
|
180
|
}
|
181
|
|
182
|
public static ExportToFileDestinationWizardPage OutputModel(CdmLightExportConfigurator config) {
|
183
|
|
184
|
return new ExportToFileDestinationWizardPage(
|
185
|
OUTPUT_MODEL_EXPORT,
|
186
|
OUTPUT_MODEL_EXPORT,
|
187
|
"CDM Light Export (csv)",
|
188
|
"Export the content of the currently selected database into the CDM light (csv) format.",
|
189
|
CSV,config);
|
190
|
}
|
191
|
|
192
|
public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
|
193
|
|
194
|
return new ExportToFileDestinationWizardPage(
|
195
|
CSV_EXPORT,
|
196
|
CSV_EXPORT,
|
197
|
"CSV Export",
|
198
|
"Export the content of the currently selected database into Comma Separated Value format.",
|
199
|
CSV, config);
|
200
|
}
|
201
|
|
202
|
public static ExportToFileDestinationWizardPage CsvNames(CsvNameExportConfigurator config) {
|
203
|
|
204
|
return new ExportToFileDestinationWizardPage(
|
205
|
CSV_NAME_EXPORT,
|
206
|
CSV_NAME_EXPORT,
|
207
|
"CSV Name Export",
|
208
|
"Export the names of the currently selected database into Semicolon Separated Value format.",
|
209
|
CSV, config);
|
210
|
}
|
211
|
|
212
|
public static ExportToFileDestinationWizardPage CsvPrint(CsvNameExportConfigurator config) {
|
213
|
|
214
|
return new ExportToFileDestinationWizardPage(
|
215
|
CSV_PRINT_EXPORT,
|
216
|
CSV_NAME_EXPORT,
|
217
|
"CSV Print Export",
|
218
|
"Export the content of the currently selected database into Semicolon Separated Value format.",
|
219
|
CSV, config);
|
220
|
}
|
221
|
|
222
|
/** {@inheritDoc} */
|
223
|
@Override
|
224
|
public void createControl(Composite parent) {
|
225
|
|
226
|
setPageComplete(false);
|
227
|
|
228
|
Composite composite = new Composite(parent, SWT.NONE);
|
229
|
GridLayout gridLayout = new GridLayout();
|
230
|
|
231
|
gridLayout.numColumns = 2;
|
232
|
TaxonNode node = null;
|
233
|
|
234
|
composite.setLayout(gridLayout);
|
235
|
if(classifications == null){
|
236
|
classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
|
237
|
Collections.sort(classifications, new Comparator<Classification>() {
|
238
|
|
239
|
@Override
|
240
|
public int compare(Classification o1, Classification o2) {
|
241
|
if (o1.equals(o2)){
|
242
|
return 0;
|
243
|
}
|
244
|
int result = o1.getTitleCache().compareTo(o2.getTitleCache());
|
245
|
if (result == 0){
|
246
|
return o1.getUuid().compareTo(o2.getUuid());
|
247
|
}
|
248
|
return result;
|
249
|
}
|
250
|
});
|
251
|
if (!configurator.getTaxonNodeFilter().getClassificationFilter().isEmpty()){
|
252
|
selectedClassification = CdmStore.getService(IClassificationService.class).load(configurator.getTaxonNodeFilter().getClassificationFilter().get(0).getUuid());
|
253
|
}else{
|
254
|
|
255
|
selectedClassification = classifications.iterator().next();
|
256
|
}
|
257
|
}
|
258
|
|
259
|
|
260
|
if(csvExport || csvPrintExport || outputModelExport|| csvNameExport || dwcaExport){
|
261
|
|
262
|
// Label comboBoxLabel = new Label(composite, SWT.NONE);
|
263
|
// comboBoxLabel.setText("Classification");
|
264
|
Composite selectNodeOrClassification = new Composite(composite, SWT.NONE);
|
265
|
GridLayout grid = new GridLayout();
|
266
|
grid.numColumns = 1;
|
267
|
selectNodeOrClassification.setLayout(grid);
|
268
|
if ((outputModelExport || dwcaExport)&& !configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty()){
|
269
|
checkUseSelectedtaxonNode= new Button(selectNodeOrClassification, SWT.RADIO);
|
270
|
String taxonStr = "";
|
271
|
node = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(configurator.getTaxonNodeFilter().getSubtreeFilter().get(0).getUuid());
|
272
|
if (node.hasTaxon()){
|
273
|
taxonStr = node.getTaxon().getName().getTitleCache();
|
274
|
}
|
275
|
checkUseSelectedtaxonNode.setText("Export selected subtree ("+ taxonStr+")");
|
276
|
checkUseSelectedtaxonNode.addListener(SWT.Selection, new Listener() {
|
277
|
@Override
|
278
|
public void handleEvent(Event e) {
|
279
|
Button b = (Button) e.widget;
|
280
|
GridData data = (GridData) classificationSelectionCombo.getLayoutData();
|
281
|
data.exclude = b.getSelection();
|
282
|
classificationSelectionCombo.setVisible(!data.exclude);
|
283
|
|
284
|
}
|
285
|
});
|
286
|
checkUseSelectedtaxonNode.setSelection(true);
|
287
|
checkUseSelectedClassification= new Button(selectNodeOrClassification, SWT.RADIO);
|
288
|
checkUseSelectedClassification.setText("Export complete classification");
|
289
|
checkUseSelectedClassification.addListener(SWT.Selection, new Listener() {
|
290
|
@Override
|
291
|
public void handleEvent(Event e) {
|
292
|
Button b = (Button) e.widget;
|
293
|
GridData data = (GridData) classificationSelectionCombo.getLayoutData();
|
294
|
data.exclude = b.getSelection();
|
295
|
classificationSelectionCombo.setVisible(data.exclude);
|
296
|
|
297
|
}
|
298
|
});
|
299
|
}
|
300
|
if (node!= null){
|
301
|
selectedClassification = node.getClassification();
|
302
|
}
|
303
|
createClassificationSelectionCombo(selectNodeOrClassification);
|
304
|
|
305
|
|
306
|
|
307
|
if (checkUseSelectedtaxonNode != null){
|
308
|
|
309
|
if (checkUseSelectedtaxonNode.getSelection()){
|
310
|
classificationSelectionCombo.setVisible(false);
|
311
|
|
312
|
}
|
313
|
}else{
|
314
|
classificationSelectionCombo.setVisible(true);
|
315
|
classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
316
|
true, false, 2, 1));
|
317
|
}
|
318
|
|
319
|
}
|
320
|
|
321
|
Label folderLabel = new Label(composite, SWT.NONE);
|
322
|
folderLabel.setText("Select Folder for exported files");
|
323
|
folderLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
324
|
true, false, 2, 1));
|
325
|
folderDialog = new DirectoryDialog(parent.getShell());
|
326
|
folderDialog.setFilterPath(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
|
327
|
|
328
|
text_folder = new Text(composite, SWT.BORDER);
|
329
|
text_folder.setEditable(false);
|
330
|
text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
|
331
|
false));
|
332
|
if (PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER) != null){
|
333
|
text_folder.setText(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
|
334
|
setPageComplete(true);
|
335
|
}
|
336
|
|
337
|
Button button = new Button(composite, SWT.PUSH);
|
338
|
button.setText("Browse...");
|
339
|
|
340
|
button.addSelectionListener(new SelectionAdapter() {
|
341
|
@Override
|
342
|
public void widgetSelected(SelectionEvent e) {
|
343
|
super.widgetSelected(e);
|
344
|
|
345
|
String path = folderDialog.open();
|
346
|
if (path != null) { // a folder was selected
|
347
|
text_folder.setText(path);
|
348
|
PreferencesUtil.getPreferenceStore().setValue(EXPORT_FOLDER, path);
|
349
|
setPageComplete(true);
|
350
|
}
|
351
|
}
|
352
|
});
|
353
|
if (!outputModelExport){
|
354
|
|
355
|
Label fileLabel = new Label(composite, SWT.NONE);
|
356
|
fileLabel.setText("File");
|
357
|
text_exportFileName = new Text(composite, SWT.BORDER);
|
358
|
text_exportFileName.setText(generateFilename());
|
359
|
text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
360
|
true, false));
|
361
|
}
|
362
|
// make the composite the wizard pages control
|
363
|
setControl(composite);
|
364
|
}
|
365
|
|
366
|
protected String generateFilename() {
|
367
|
StringBuffer buffer = new StringBuffer();
|
368
|
|
369
|
Calendar cal = Calendar.getInstance();
|
370
|
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
|
371
|
buffer.append(sdf.format(cal.getTime()));
|
372
|
|
373
|
buffer.append("-");
|
374
|
|
375
|
buffer.append(type + "_export-");
|
376
|
try {
|
377
|
buffer.append(CdmDataSourceRepository.getCurrentCdmSource());
|
378
|
} catch (CdmRemoteSourceException e) {
|
379
|
buffer.append("Unknown");
|
380
|
}
|
381
|
|
382
|
buffer.append(".");
|
383
|
buffer.append(extension);
|
384
|
|
385
|
return buffer.toString();
|
386
|
}
|
387
|
|
388
|
public String getExportFileName() {
|
389
|
return text_exportFileName.getText();
|
390
|
}
|
391
|
|
392
|
public String getFolderText() {
|
393
|
return text_folder.getText();
|
394
|
}
|
395
|
|
396
|
public Text getFolderComposite() {
|
397
|
return text_folder;
|
398
|
}
|
399
|
|
400
|
private void createClassificationSelectionCombo(Composite parent){
|
401
|
|
402
|
// Composite classificationSelection = new Composite(parent, SWT.NULL);
|
403
|
// classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
|
404
|
|
405
|
// GridLayout layout = new GridLayout();
|
406
|
// classificationSelection.setLayout(layout);
|
407
|
GridData gridData = new GridData();
|
408
|
gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
|
409
|
gridData.horizontalIndent = 5;
|
410
|
// classificationSelection.setLayoutData(gridData);
|
411
|
|
412
|
classificationSelectionCombo = new Combo(parent, SWT.BORDER| SWT.READ_ONLY);
|
413
|
classificationSelectionCombo.setLayoutData(gridData);
|
414
|
for(Classification tree : classifications){
|
415
|
classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
|
416
|
|
417
|
}
|
418
|
|
419
|
classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
|
420
|
|
421
|
// TODO remember last selection
|
422
|
classificationSelectionCombo.addSelectionListener(this);
|
423
|
|
424
|
|
425
|
|
426
|
//return classificationSelection;
|
427
|
}
|
428
|
|
429
|
public Combo getCombo(){
|
430
|
return classificationSelectionCombo;
|
431
|
}
|
432
|
|
433
|
@Override
|
434
|
public void widgetSelected(SelectionEvent e) {
|
435
|
selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
|
436
|
|
437
|
}
|
438
|
|
439
|
@Override
|
440
|
public void widgetDefaultSelected(SelectionEvent e) {
|
441
|
//not needed here
|
442
|
|
443
|
}
|
444
|
|
445
|
public UUID getSelectedClassificationUUID() {
|
446
|
|
447
|
return selectedClassification.getUuid();
|
448
|
}
|
449
|
|
450
|
public boolean getCheckUseSelectedTaxonNode() {
|
451
|
if (checkUseSelectedtaxonNode== null){
|
452
|
return false;
|
453
|
}
|
454
|
return checkUseSelectedtaxonNode.getSelection();
|
455
|
}
|
456
|
|
457
|
@Override
|
458
|
public boolean canFlipToNextPage() {
|
459
|
return getFolderText() != null;
|
460
|
}
|
461
|
|
462
|
}
|