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.dwca;
|
11
|
|
12
|
import java.io.File;
|
13
|
import java.util.Iterator;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import javax.inject.Inject;
|
17
|
import javax.inject.Named;
|
18
|
|
19
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
20
|
import org.eclipse.e4.core.di.annotations.Optional;
|
21
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
22
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
23
|
import org.eclipse.jface.viewers.TreeSelection;
|
24
|
|
25
|
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
|
26
|
import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
|
27
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
28
|
import eu.etaxonomy.taxeditor.io.e4.out.AbstractExportWizardE4;
|
29
|
import eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage;
|
30
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
* @author pplitzner
|
35
|
* @since Oct 6, 2017
|
36
|
*
|
37
|
*/
|
38
|
public class DarwinCoreArchiveExportWizardE4 extends
|
39
|
AbstractExportWizardE4<DwcaTaxExportConfigurator> {
|
40
|
|
41
|
private DwcaTaxExportConfigurator configurator;
|
42
|
private ExportToFileDestinationWizardPage page;
|
43
|
|
44
|
@Inject
|
45
|
public DarwinCoreArchiveExportWizardE4(IEclipseContext context,
|
46
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
|
47
|
super(context, selection);
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void init() {
|
52
|
configurator = DwcaTaxExportConfigurator.NewInstance(null, null, null);
|
53
|
if (selection instanceof TreeSelection && !selection.isEmpty()){
|
54
|
Iterator it = selection.iterator();
|
55
|
|
56
|
while(it.hasNext()){
|
57
|
Object obj = it.next();
|
58
|
if (obj instanceof TaxonNodeDto){
|
59
|
TaxonNodeDto node = (TaxonNodeDto) obj;
|
60
|
if (node.getParentUUID() == null){
|
61
|
if (configurator.getTaxonNodeFilter() == null){
|
62
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(node.getClassificationUUID()));
|
63
|
}else{
|
64
|
configurator.getTaxonNodeFilter().orClassification(node.getClassificationUUID());
|
65
|
}
|
66
|
}else{
|
67
|
if (configurator.getTaxonNodeFilter() == null){
|
68
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(node.getUuid()));
|
69
|
}else{
|
70
|
configurator.getTaxonNodeFilter().orSubtree(node.getUuid());
|
71
|
}
|
72
|
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
|
77
|
}
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public DwcaTaxExportConfigurator getConfigurator() {
|
82
|
return configurator;
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public boolean performFinish() {
|
87
|
String urlString = page.getFolderText() + File.separator
|
88
|
+ page.getExportFileName();
|
89
|
|
90
|
if (!page.getCheckUseSelectedTaxonNode()){
|
91
|
configurator.getTaxonNodeFilter().reset();
|
92
|
if (!page.getCheckUseAllClassifications()){
|
93
|
configurator.getTaxonNodeFilter().orClassification(page.getSelectedClassificationUUID());
|
94
|
}else{
|
95
|
for (UUID classificationUuid: page.getAllClassificationUuids()){
|
96
|
configurator.getTaxonNodeFilter().orClassification(classificationUuid);
|
97
|
}
|
98
|
|
99
|
}
|
100
|
}
|
101
|
CdmStore.getExportManager().runMoniteredOperation(configurator, urlString);
|
102
|
return true;
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public void addPages() {
|
107
|
page = ExportToFileDestinationWizardPage.Dwca(configurator);
|
108
|
addPage(page);
|
109
|
super.addPages();
|
110
|
}
|
111
|
}
|