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