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.e4.out.csv;
|
11
|
|
12
|
import java.io.File;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.eclipse.core.runtime.jobs.Job;
|
18
|
import org.eclipse.swt.widgets.Combo;
|
19
|
import org.eclipse.ui.progress.IProgressConstants;
|
20
|
|
21
|
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
23
|
import eu.etaxonomy.taxeditor.io.e4.out.AbstractExportWizardE4;
|
24
|
import eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* @author a.oppermann
|
29
|
* @created Nov. 11, 2014
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public class CsvExportWizardE4 extends AbstractExportWizardE4<CsvDemoExportConfigurator> {
|
33
|
|
34
|
private CsvDemoExportConfigurator configurator;
|
35
|
private ExportToFileDestinationWizardPage page;
|
36
|
|
37
|
private final String description = "Export the contents of the currently selected database into Comma Separated Value format.";
|
38
|
|
39
|
@Override
|
40
|
public void init() {
|
41
|
configurator = CsvDemoExportConfigurator.NewInstance(null, null);
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public CsvDemoExportConfigurator getConfigurator() {
|
46
|
return configurator;
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
public boolean performFinish() {
|
51
|
String urlString = page.getFolderText() + File.separator
|
52
|
+ page.getExportFileName();
|
53
|
|
54
|
final Combo combo = page.getCombo();
|
55
|
final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
|
56
|
if(combo != null){
|
57
|
int selectionIndex = combo.getSelectionIndex();
|
58
|
HashSet<UUID> set = new HashSet<UUID>();
|
59
|
if(selectionIndex == -1){
|
60
|
for(Classification c:listClassifications){
|
61
|
set.add(c.getUuid());
|
62
|
}
|
63
|
}else{
|
64
|
for(Classification c:listClassifications){
|
65
|
if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
|
66
|
set.add(c.getUuid());
|
67
|
}
|
68
|
}
|
69
|
configurator.setClassificationUuids(set);
|
70
|
configurator.setDoTaxa(true);
|
71
|
configurator.setHasHeaderLines(true);
|
72
|
configurator.setClassification(true);
|
73
|
configurator.setTaxonName(true);
|
74
|
configurator.setAuthor(true);
|
75
|
configurator.setRank(true);
|
76
|
configurator.setLastChange(true);
|
77
|
}
|
78
|
}
|
79
|
|
80
|
// create job
|
81
|
Job job = CdmStore.getExportManager().createIOServiceJob(configurator, new File(urlString));
|
82
|
// configure the job
|
83
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
84
|
job.setUser(true);
|
85
|
// schedule job
|
86
|
job.schedule();
|
87
|
|
88
|
return true;
|
89
|
}
|
90
|
|
91
|
@Override
|
92
|
public void addPages() {
|
93
|
//TODO create page with drop down menu for export for single classification.
|
94
|
// super.addPages();
|
95
|
|
96
|
|
97
|
//standard page
|
98
|
page = ExportToFileDestinationWizardPage.Csv(configurator);
|
99
|
|
100
|
addPage(page);
|
101
|
}
|
102
|
}
|