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.e4.out.cdmlight;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
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
|
import org.eclipse.swt.widgets.Combo;
|
25
|
|
26
|
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
|
27
|
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
29
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
30
|
import eu.etaxonomy.taxeditor.io.e4.out.AbstractExportWizardE4;
|
31
|
import eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage;
|
32
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
33
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
34
|
|
35
|
/**
|
36
|
* @author k.luther
|
37
|
* @date 21.03.2017
|
38
|
*
|
39
|
*/
|
40
|
public class CdmLightExportWizardE4 extends
|
41
|
AbstractExportWizardE4<CdmLightExportConfigurator> {
|
42
|
|
43
|
|
44
|
private CdmLightExportConfigurator configurator;
|
45
|
private ExportToFileDestinationWizardPage page;
|
46
|
|
47
|
@Inject
|
48
|
public CdmLightExportWizardE4(IEclipseContext context,
|
49
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
|
50
|
super(context, selection);
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public void init() {
|
55
|
configurator = new CdmLightExportConfigurator(null);
|
56
|
if (selection instanceof TreeSelection && !selection.isEmpty()){
|
57
|
TaxonNodeDto node = (TaxonNodeDto)selection.getFirstElement();
|
58
|
if (node.getParentUUID() == null){
|
59
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(node.getClassificationUUID()));
|
60
|
}else{
|
61
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(node.getUuid()));
|
62
|
}
|
63
|
|
64
|
}
|
65
|
}
|
66
|
|
67
|
|
68
|
@Override
|
69
|
public CdmLightExportConfigurator getConfigurator() {
|
70
|
return configurator;
|
71
|
}
|
72
|
|
73
|
|
74
|
@Override
|
75
|
public boolean performFinish() {
|
76
|
String urlString = page.getFolderText() + File.separator;
|
77
|
//+ page.getExportFileName();
|
78
|
|
79
|
final Combo combo = page.getCombo();
|
80
|
final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
|
81
|
if(combo != null){
|
82
|
int selectionIndex = combo.getSelectionIndex();
|
83
|
HashSet<UUID> set = new HashSet<UUID>();
|
84
|
if(selectionIndex == -1){
|
85
|
for(Classification c:listClassifications){
|
86
|
set.add(c.getUuid());
|
87
|
}
|
88
|
}else{
|
89
|
for(Classification c:listClassifications){
|
90
|
if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
|
91
|
set.add(c.getUuid());
|
92
|
|
93
|
if (!page.getCheckUseSelectedTaxonNode()){
|
94
|
configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(c.getUuid()));
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
|
99
|
|
100
|
}
|
101
|
}
|
102
|
configurator.getTaxonNodeFilter().setIncludeUnpublished(page.isExportUnpublishedData());
|
103
|
CdmStore.getExportManager().runMoniteredOperation(configurator, urlString);
|
104
|
// create job
|
105
|
// Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
|
106
|
// // configure the job
|
107
|
// job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
108
|
// job.setUser(true);
|
109
|
// // schedule job
|
110
|
// job.schedule();
|
111
|
PreferencesUtil.getPreferenceStore().setValue("exportFolder", page.getFolderText());
|
112
|
return true;
|
113
|
}
|
114
|
|
115
|
@Override
|
116
|
public void addPages() {
|
117
|
//standard page
|
118
|
page = ExportToFileDestinationWizardPage.OutputModel(configurator);
|
119
|
|
120
|
addPage(page);
|
121
|
super.addPages();
|
122
|
}
|
123
|
|
124
|
}
|