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