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