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