1
|
package eu.etaxonomy.taxeditor.io.wizard;
|
2
|
|
3
|
import java.io.File;
|
4
|
import java.util.HashSet;
|
5
|
import java.util.List;
|
6
|
import java.util.UUID;
|
7
|
|
8
|
import org.eclipse.core.runtime.jobs.Job;
|
9
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
10
|
import org.eclipse.swt.widgets.Combo;
|
11
|
import org.eclipse.ui.IWorkbench;
|
12
|
import org.eclipse.ui.progress.IProgressConstants;
|
13
|
|
14
|
import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
|
15
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
16
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
17
|
|
18
|
public class CsvPrintExportWizard extends CsvNameExportWizard{
|
19
|
|
20
|
|
21
|
private final String description = "Export the contents of the currently selected database into Semicolon Separated Value format.";
|
22
|
@Override
|
23
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
24
|
configurator = CsvNameExportConfigurator.NewInstance(null,null);
|
25
|
configurator.setNamesOnly(false);
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public CsvNameExportConfigurator getConfigurator() {
|
30
|
|
31
|
return configurator;
|
32
|
}
|
33
|
|
34
|
|
35
|
|
36
|
/*
|
37
|
* (non-Javadoc)
|
38
|
*
|
39
|
* @see eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#addPages()
|
40
|
*/
|
41
|
@Override
|
42
|
public void addPages() {
|
43
|
//TODO create page with drop down menu for export for single classification.
|
44
|
// super.addPages();
|
45
|
|
46
|
|
47
|
//standard page
|
48
|
page = ExportToFileDestinationWizardPage.CsvPrint();
|
49
|
|
50
|
addPage(page);
|
51
|
}
|
52
|
/*
|
53
|
* (non-Javadoc)
|
54
|
*
|
55
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
56
|
*/
|
57
|
@Override
|
58
|
public boolean performFinish() {
|
59
|
String urlString = page.getFolderText() + File.separator
|
60
|
+ page.getExportFileName();
|
61
|
|
62
|
final Combo combo = page.getCombo();
|
63
|
final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
|
64
|
if(combo != null){
|
65
|
int selectionIndex = combo.getSelectionIndex();
|
66
|
HashSet<UUID> set = new HashSet<UUID>();
|
67
|
if(selectionIndex == -1){
|
68
|
for(Classification c:listClassifications){
|
69
|
set.add(c.getUuid());
|
70
|
}
|
71
|
}else{
|
72
|
for(Classification c:listClassifications){
|
73
|
if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
|
74
|
set.add(c.getUuid());
|
75
|
}
|
76
|
}
|
77
|
|
78
|
configurator.setHasHeaderLines(true);
|
79
|
|
80
|
}
|
81
|
} else{
|
82
|
configurator.setClassificationUUID(listClassifications.get(0).getUuid());
|
83
|
}
|
84
|
|
85
|
if(CdmStore.getCurrentSessionManager().isRemoting()) {
|
86
|
// create job
|
87
|
Job job = CdmStore.getExportManager().createIOServiceJob(configurator, new File(urlString));
|
88
|
// configure the job
|
89
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
90
|
job.setUser(true);
|
91
|
// schedule job
|
92
|
job.schedule();
|
93
|
} else {
|
94
|
configurator.setDestination(new File(urlString));
|
95
|
CdmStore.getExportManager().run(configurator);
|
96
|
}
|
97
|
return true;
|
98
|
}
|
99
|
|
100
|
}
|