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.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.Control;
|
30
|
import org.eclipse.swt.widgets.DirectoryDialog;
|
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.service.IClassificationService;
|
36
|
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
|
37
|
import eu.etaxonomy.cdm.io.common.ExportConfiguratorBase;
|
38
|
import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
|
39
|
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
|
40
|
import eu.etaxonomy.cdm.io.csv.redlist.out.CsvTaxExportConfiguratorRedlist;
|
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.taxeditor.datasource.CdmDataSourceRepository;
|
47
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
48
|
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
|
49
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
50
|
|
51
|
/**
|
52
|
* <p>
|
53
|
* ExportToFileDestinationWizardPage class.
|
54
|
* </p>
|
55
|
*
|
56
|
* @author n.hoffmann
|
57
|
* @created 15.06.2009
|
58
|
* @version 1.0
|
59
|
*/
|
60
|
public class ExportToFileDestinationWizardPage extends WizardPage implements SelectionListener {
|
61
|
|
62
|
/** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
|
63
|
public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
|
64
|
|
65
|
/** Constant <code>JAXB_EXPORT="JAXB_EXPORT"</code> */
|
66
|
public static final String JAXB_EXPORT = "JAXB_EXPORT";
|
67
|
|
68
|
/** Constant <code>TCS_EXPORT="TCS_EXPORT"</code> */
|
69
|
public static final String TCS_EXPORT = "TCS_EXPORT";
|
70
|
|
71
|
/** Constant <code>SDD_EXPORT="SDD_EXPORT"</code> */
|
72
|
public static final String SDD_EXPORT = "SDD_EXPORT";
|
73
|
|
74
|
public static final String DWCA_EXPORT = "DWCA_EXPORT";
|
75
|
public static final String OUTPUT_MODEL_EXPORT = "CDM_LIGHT(CSV)";
|
76
|
public static final String CSV_EXPORT = "CSV_EXPORT";
|
77
|
public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
|
78
|
private static final String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
|
79
|
private static final String EXPORT_FOLDER ="EXPORT_FOLDER";
|
80
|
public static final String XML = "xml";
|
81
|
|
82
|
public static final String CSV = "csv";
|
83
|
|
84
|
|
85
|
|
86
|
public static final String ZIP = "zip";
|
87
|
|
88
|
private boolean csvExport = false;
|
89
|
|
90
|
private boolean csvNameExport = false;
|
91
|
|
92
|
|
93
|
|
94
|
private boolean csvPrintExport = false;
|
95
|
|
96
|
private boolean outputModelExport = 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 ExportConfiguratorBase configurator;
|
114
|
|
115
|
/**
|
116
|
* @param pageName
|
117
|
* @param selection
|
118
|
*/
|
119
|
protected ExportToFileDestinationWizardPage(String pageName, String type,
|
120
|
String title, String description, String extension, ExportConfiguratorBase configurator) {
|
121
|
super(pageName);
|
122
|
this.configurator = configurator;
|
123
|
this.type = type;
|
124
|
switch(type) {
|
125
|
case CSV_EXPORT :
|
126
|
csvExport = true;
|
127
|
break;
|
128
|
case CSV_NAME_EXPORT:
|
129
|
csvNameExport = true;
|
130
|
break;
|
131
|
case OUTPUT_MODEL_EXPORT:
|
132
|
outputModelExport = true;
|
133
|
break;
|
134
|
case CSV_PRINT_EXPORT:
|
135
|
csvPrintExport = true;
|
136
|
break;
|
137
|
|
138
|
}
|
139
|
this.extension = extension;
|
140
|
this.setTitle(title);
|
141
|
this.setDescription(description);
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* <p>
|
146
|
* Jaxb
|
147
|
* </p>
|
148
|
*
|
149
|
* @return a
|
150
|
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
|
151
|
* object.
|
152
|
*/
|
153
|
public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
|
154
|
return new ExportToFileDestinationWizardPage(
|
155
|
JAXB_EXPORT,
|
156
|
"jaxb",
|
157
|
"JAXB Export",
|
158
|
"Exports the contents of the currently selected database into the cdm jaxb format.",
|
159
|
XML, configurator);
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* <p>
|
164
|
* Tcs
|
165
|
* </p>
|
166
|
*
|
167
|
* @return a
|
168
|
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
|
169
|
* object.
|
170
|
*/
|
171
|
public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
|
172
|
return new ExportToFileDestinationWizardPage(
|
173
|
TCS_EXPORT,
|
174
|
"tcs",
|
175
|
"Tcs Export",
|
176
|
"Export the contents of the currently selected database into TCS format.",
|
177
|
XML, config);
|
178
|
}
|
179
|
|
180
|
/**
|
181
|
* <p>
|
182
|
* Sdd
|
183
|
* </p>
|
184
|
*
|
185
|
* @return a
|
186
|
* {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
|
187
|
* object.
|
188
|
*/
|
189
|
public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
|
190
|
return new ExportToFileDestinationWizardPage(
|
191
|
SDD_EXPORT,
|
192
|
"sdd",
|
193
|
"Sdd Export",
|
194
|
"Export the contents of the currently selected database into SDD format.",
|
195
|
XML, config);
|
196
|
}
|
197
|
|
198
|
/**
|
199
|
* @return
|
200
|
*/
|
201
|
public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
|
202
|
return new ExportToFileDestinationWizardPage(
|
203
|
DWCA_EXPORT,
|
204
|
DWCA_EXPORT,
|
205
|
"DwC-Archive Export",
|
206
|
"Export the contents of the currently selected database into Darwin Core Archive format.",
|
207
|
ZIP, config);
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* @return
|
212
|
*/
|
213
|
public static ExportToFileDestinationWizardPage OutputModel(CdmLightExportConfigurator config) {
|
214
|
|
215
|
return new ExportToFileDestinationWizardPage(
|
216
|
OUTPUT_MODEL_EXPORT,
|
217
|
OUTPUT_MODEL_EXPORT,
|
218
|
"Output Model Export",
|
219
|
"Export the contents of the currently selected database into the output model format.",
|
220
|
CSV,config);
|
221
|
}
|
222
|
|
223
|
|
224
|
/**
|
225
|
* @return
|
226
|
*/
|
227
|
public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
|
228
|
|
229
|
return new ExportToFileDestinationWizardPage(
|
230
|
CSV_EXPORT,
|
231
|
CSV_EXPORT,
|
232
|
"CSV Export",
|
233
|
"Export the contents of the currently selected database into Comma Separated Value format.",
|
234
|
CSV, config);
|
235
|
}
|
236
|
|
237
|
/**
|
238
|
* @return
|
239
|
*/
|
240
|
public static ExportToFileDestinationWizardPage CsvNames(CsvNameExportConfigurator config) {
|
241
|
|
242
|
return new ExportToFileDestinationWizardPage(
|
243
|
CSV_NAME_EXPORT,
|
244
|
CSV_NAME_EXPORT,
|
245
|
"CSV Name Export",
|
246
|
"Export the names of the currently selected database into Semicolon Separated Value format.",
|
247
|
CSV, config);
|
248
|
}
|
249
|
|
250
|
/**
|
251
|
* @return
|
252
|
*/
|
253
|
public static ExportToFileDestinationWizardPage CsvPrint(CsvNameExportConfigurator config) {
|
254
|
|
255
|
return new ExportToFileDestinationWizardPage(
|
256
|
CSV_PRINT_EXPORT,
|
257
|
CSV_NAME_EXPORT,
|
258
|
"CSV Print Export",
|
259
|
"Export the content of the currently selected database into Semicolon Separated Value format.",
|
260
|
CSV, config);
|
261
|
}
|
262
|
|
263
|
/*
|
264
|
* (non-Javadoc)
|
265
|
*
|
266
|
* @see
|
267
|
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
|
268
|
* .Composite)
|
269
|
*/
|
270
|
/** {@inheritDoc} */
|
271
|
@Override
|
272
|
public void createControl(Composite parent) {
|
273
|
|
274
|
setPageComplete(false);
|
275
|
|
276
|
Composite composite = new Composite(parent, SWT.NONE);
|
277
|
GridLayout gridLayout = new GridLayout();
|
278
|
|
279
|
gridLayout.numColumns = 2;
|
280
|
|
281
|
|
282
|
composite.setLayout(gridLayout);
|
283
|
if(classifications == null){
|
284
|
classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
|
285
|
Collections.sort(classifications, new Comparator<Classification>() {
|
286
|
|
287
|
@Override
|
288
|
public int compare(Classification o1, Classification o2) {
|
289
|
if (o1.equals(o2)){
|
290
|
return 0;
|
291
|
}
|
292
|
int result = o1.getTitleCache().compareTo(o2.getTitleCache());
|
293
|
if (result == 0){
|
294
|
return o1.getUuid().compareTo(o2.getUuid());
|
295
|
}
|
296
|
return result;
|
297
|
}
|
298
|
});
|
299
|
|
300
|
selectedClassification = classifications.iterator().next();
|
301
|
}
|
302
|
|
303
|
|
304
|
if(csvExport || csvPrintExport || outputModelExport|| csvNameExport){
|
305
|
// Label comboBoxLabel = new Label(composite, SWT.NONE);
|
306
|
// comboBoxLabel.setText("Classification");
|
307
|
|
308
|
createClassificationSelectionCombo(composite);
|
309
|
classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
310
|
true, false, 2, 1));
|
311
|
}
|
312
|
|
313
|
|
314
|
Label folderLabel = new Label(composite, SWT.NONE);
|
315
|
folderLabel.setText("Select Folder for exported files");
|
316
|
folderLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
317
|
true, false, 2, 1));
|
318
|
folderDialog = new DirectoryDialog(parent.getShell());
|
319
|
folderDialog.setFilterPath(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
|
320
|
|
321
|
text_folder = new Text(composite, SWT.BORDER);
|
322
|
text_folder.setEditable(false);
|
323
|
text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
|
324
|
false));
|
325
|
if (PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER) != null){
|
326
|
text_folder.setText(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
|
327
|
setPageComplete(true);
|
328
|
}
|
329
|
|
330
|
Button button = new Button(composite, SWT.PUSH);
|
331
|
button.setText("Browse...");
|
332
|
|
333
|
button.addSelectionListener(new SelectionAdapter() {
|
334
|
/*
|
335
|
* (non-Javadoc)
|
336
|
*
|
337
|
* @see
|
338
|
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
|
339
|
* .swt.events.SelectionEvent)
|
340
|
*/
|
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
|
/**
|
389
|
* <p>
|
390
|
* getExportFileName
|
391
|
* </p>
|
392
|
*
|
393
|
* @return the exportFileName
|
394
|
*/
|
395
|
public String getExportFileName() {
|
396
|
return text_exportFileName.getText();
|
397
|
}
|
398
|
|
399
|
/**
|
400
|
* <p>
|
401
|
* getFolderText
|
402
|
* </p>
|
403
|
*
|
404
|
* @return the folderText
|
405
|
*/
|
406
|
public String getFolderText() {
|
407
|
return text_folder.getText();
|
408
|
}
|
409
|
|
410
|
/**
|
411
|
* <p>
|
412
|
* getFolderComposite
|
413
|
* </p>
|
414
|
*
|
415
|
* @return the folderText
|
416
|
*/
|
417
|
public Text getFolderComposite() {
|
418
|
return text_folder;
|
419
|
}
|
420
|
|
421
|
private void createClassificationSelectionCombo(Composite parent){
|
422
|
// classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
|
423
|
|
424
|
// Composite classificationSelection = new Composite(parent, SWT.NULL);
|
425
|
// classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
|
426
|
|
427
|
// GridLayout layout = new GridLayout();
|
428
|
// classificationSelection.setLayout(layout);
|
429
|
|
430
|
Label label = new Label(parent, SWT.NULL);
|
431
|
// TODO not working is not really true but leave it here to remind everyone that this is under construction
|
432
|
label.setText("Select Classification");
|
433
|
|
434
|
classificationSelectionCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
|
435
|
classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 2,1));
|
436
|
|
437
|
for(Classification tree : classifications){
|
438
|
classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
|
439
|
|
440
|
}
|
441
|
|
442
|
classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
|
443
|
|
444
|
// TODO remember last selection
|
445
|
classificationSelectionCombo.addSelectionListener(this);
|
446
|
|
447
|
|
448
|
|
449
|
//return classificationSelection;
|
450
|
}
|
451
|
|
452
|
public Combo getCombo(){
|
453
|
return classificationSelectionCombo;
|
454
|
}
|
455
|
|
456
|
@Override
|
457
|
public void widgetSelected(SelectionEvent e) {
|
458
|
selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
|
459
|
|
460
|
}
|
461
|
|
462
|
@Override
|
463
|
public void widgetDefaultSelected(SelectionEvent e) {
|
464
|
//not needed here
|
465
|
|
466
|
}
|
467
|
|
468
|
public UUID getSelectedClassificationUUID() {
|
469
|
|
470
|
return selectedClassification.getUuid();
|
471
|
}
|
472
|
|
473
|
|
474
|
|
475
|
|
476
|
|
477
|
}
|