1 |
f3e1e1fa
|
Katja Luther
|
/**
|
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 |
10b4eb6d
|
Katja Luther
|
import org.eclipse.jface.viewers.TreeSelection;
|
19 |
f3e1e1fa
|
Katja Luther
|
import org.eclipse.swt.widgets.Combo;
|
20 |
|
|
import org.eclipse.ui.IWorkbench;
|
21 |
|
|
import org.eclipse.ui.progress.IProgressConstants;
|
22 |
|
|
|
23 |
10b4eb6d
|
Katja Luther
|
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
|
24 |
f6b1d0ad
|
Katja Luther
|
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
|
25 |
f3e1e1fa
|
Katja Luther
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
26 |
10b4eb6d
|
Katja Luther
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
27 |
0b4f079d
|
Katja Luther
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
28 |
f3e1e1fa
|
Katja Luther
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* @author k.luther
|
32 |
|
|
* @date 21.03.2017
|
33 |
|
|
*
|
34 |
|
|
*/
|
35 |
f6b1d0ad
|
Katja Luther
|
public class CdmLightExportWizard extends
|
36 |
|
|
AbstractExportWizard<CdmLightExportConfigurator> {
|
37 |
f3e1e1fa
|
Katja Luther
|
|
38 |
f6b1d0ad
|
Katja Luther
|
private CdmLightExportConfigurator configurator;
|
39 |
f3e1e1fa
|
Katja Luther
|
private ExportToFileDestinationWizardPage page;
|
40 |
69e82edd
|
Katja Luther
|
|
41 |
c56148f4
|
Katja Luther
|
|
42 |
f3e1e1fa
|
Katja Luther
|
|
43 |
|
|
private final String description = "Export the contents of the currently selected database into Comma Separated Value format.";
|
44 |
a9428319
|
Andreas Müller
|
|
45 |
f3e1e1fa
|
Katja Luther
|
@Override
|
46 |
|
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
47 |
10b4eb6d
|
Katja Luther
|
configurator = new CdmLightExportConfigurator(null);
|
48 |
|
|
if (selection instanceof TreeSelection && !selection.isEmpty()){
|
49 |
|
|
TaxonNode node = (TaxonNode)selection.getFirstElement();
|
50 |
a05f423c
|
Katja Luther
|
if (node.getParent() == null){
|
51 |
|
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(node.getClassification().getUuid()));
|
52 |
|
|
}else{
|
53 |
|
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(node.getUuid()));
|
54 |
|
|
}
|
55 |
69e82edd
|
Katja Luther
|
|
56 |
10b4eb6d
|
Katja Luther
|
}
|
57 |
69e82edd
|
Katja Luther
|
|
58 |
|
|
|
59 |
f3e1e1fa
|
Katja Luther
|
}
|
60 |
|
|
|
61 |
a9428319
|
Andreas Müller
|
|
62 |
f3e1e1fa
|
Katja Luther
|
@Override
|
63 |
f6b1d0ad
|
Katja Luther
|
public CdmLightExportConfigurator getConfigurator() {
|
64 |
f3e1e1fa
|
Katja Luther
|
return configurator;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
a9428319
|
Andreas Müller
|
|
68 |
f3e1e1fa
|
Katja Luther
|
@Override
|
69 |
|
|
public boolean performFinish() {
|
70 |
|
|
String urlString = page.getFolderText() + File.separator;
|
71 |
|
|
//+ page.getExportFileName();
|
72 |
|
|
|
73 |
|
|
final Combo combo = page.getCombo();
|
74 |
|
|
final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
|
75 |
|
|
if(combo != null){
|
76 |
|
|
int selectionIndex = combo.getSelectionIndex();
|
77 |
|
|
HashSet<UUID> set = new HashSet<UUID>();
|
78 |
|
|
if(selectionIndex == -1){
|
79 |
|
|
for(Classification c:listClassifications){
|
80 |
|
|
set.add(c.getUuid());
|
81 |
|
|
}
|
82 |
|
|
}else{
|
83 |
|
|
for(Classification c:listClassifications){
|
84 |
|
|
if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
|
85 |
|
|
set.add(c.getUuid());
|
86 |
69e82edd
|
Katja Luther
|
|
87 |
10b4eb6d
|
Katja Luther
|
if (!page.getCheckUseSelectedTaxonNode()){
|
88 |
|
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(c.getUuid()));
|
89 |
|
|
}
|
90 |
f3e1e1fa
|
Katja Luther
|
}
|
91 |
|
|
}
|
92 |
69e82edd
|
Katja Luther
|
|
93 |
f3e1e1fa
|
Katja Luther
|
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
// create job
|
98 |
|
|
Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
|
99 |
|
|
// configure the job
|
100 |
|
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
101 |
|
|
job.setUser(true);
|
102 |
|
|
// schedule job
|
103 |
|
|
job.schedule();
|
104 |
69e82edd
|
Katja Luther
|
PreferencesUtil.setStringValue("exportFolder", page.getFolderText());
|
105 |
f3e1e1fa
|
Katja Luther
|
return true;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
@Override
|
109 |
|
|
public void addPages() {
|
110 |
|
|
//standard page
|
111 |
0b4f079d
|
Katja Luther
|
page = ExportToFileDestinationWizardPage.OutputModel(configurator);
|
112 |
f3e1e1fa
|
Katja Luther
|
|
113 |
|
|
addPage(page);
|
114 |
fe505329
|
Katja Luther
|
super.addPages();
|
115 |
f3e1e1fa
|
Katja Luther
|
}
|
116 |
69e82edd
|
Katja Luther
|
|
117 |
f3e1e1fa
|
Katja Luther
|
|
118 |
|
|
|
119 |
|
|
}
|