1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.taxeditor.io.wizard;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.core.runtime.jobs.Job;
|
17
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
18
|
import org.eclipse.swt.widgets.Combo;
|
19
|
import org.eclipse.ui.IWorkbench;
|
20
|
import org.eclipse.ui.progress.IProgressConstants;
|
21
|
|
22
|
import eu.etaxonomy.cdm.io.outputmodel.OutputModelConfigurator;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
|
26
|
/**
|
27
|
* @author k.luther
|
28
|
* @date 21.03.2017
|
29
|
*
|
30
|
*/
|
31
|
public class OutputModelExportWizard extends
|
32
|
AbstractExportWizard<OutputModelConfigurator> {
|
33
|
|
34
|
private OutputModelConfigurator 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
|
* (non-Javadoc)
|
40
|
*
|
41
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
|
42
|
* org.eclipse.jface.viewers.IStructuredSelection)
|
43
|
*/
|
44
|
@Override
|
45
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
46
|
configurator = new OutputModelConfigurator(null);
|
47
|
}
|
48
|
|
49
|
/*
|
50
|
* (non-Javadoc)
|
51
|
*
|
52
|
* @see
|
53
|
* eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#getConfigurator()
|
54
|
*/
|
55
|
@Override
|
56
|
public OutputModelConfigurator getConfigurator() {
|
57
|
return configurator;
|
58
|
}
|
59
|
|
60
|
/*
|
61
|
* (non-Javadoc)
|
62
|
*
|
63
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
64
|
*/
|
65
|
@Override
|
66
|
public boolean performFinish() {
|
67
|
String urlString = page.getFolderText() + File.separator;
|
68
|
//+ page.getExportFileName();
|
69
|
|
70
|
final Combo combo = page.getCombo();
|
71
|
final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
|
72
|
if(combo != null){
|
73
|
int selectionIndex = combo.getSelectionIndex();
|
74
|
HashSet<UUID> set = new HashSet<UUID>();
|
75
|
if(selectionIndex == -1){
|
76
|
for(Classification c:listClassifications){
|
77
|
set.add(c.getUuid());
|
78
|
}
|
79
|
}else{
|
80
|
for(Classification c:listClassifications){
|
81
|
if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
|
82
|
set.add(c.getUuid());
|
83
|
}
|
84
|
}
|
85
|
configurator.setClassificationUuids(set);
|
86
|
|
87
|
}
|
88
|
}
|
89
|
|
90
|
// create job
|
91
|
Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
|
92
|
// configure the job
|
93
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
94
|
job.setUser(true);
|
95
|
// schedule job
|
96
|
job.schedule();
|
97
|
|
98
|
return true;
|
99
|
}
|
100
|
|
101
|
/*
|
102
|
* (non-Javadoc)
|
103
|
*
|
104
|
* @see eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#addPages()
|
105
|
*/
|
106
|
@Override
|
107
|
public void addPages() {
|
108
|
//TODO create page with drop down menu for export for single classification.
|
109
|
// super.addPages();
|
110
|
|
111
|
|
112
|
//standard page
|
113
|
page = ExportToFileDestinationWizardPage.OutputModel();
|
114
|
|
115
|
addPage(page);
|
116
|
}
|
117
|
|
118
|
|
119
|
}
|