Project

General

Profile

Download (4.23 KB) Statistics
| Branch: | Tag: | Revision:
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.core.runtime.jobs.Job;
20
import org.eclipse.e4.core.contexts.IEclipseContext;
21
import org.eclipse.e4.core.di.annotations.Optional;
22
import org.eclipse.e4.ui.services.IServiceConstants;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.TreeSelection;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.ui.progress.IProgressConstants;
27

    
28
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
29
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
30
import eu.etaxonomy.cdm.model.taxon.Classification;
31
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
32
import eu.etaxonomy.taxeditor.io.e4.out.AbstractExportWizardE4;
33
import eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage;
34
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

    
37
/**
38
 * @author k.luther
39
 * @date 21.03.2017
40
 *
41
 */
42
public class CdmLightExportWizardE4 extends
43
AbstractExportWizardE4<CdmLightExportConfigurator> {
44

    
45

    
46
    private CdmLightExportConfigurator configurator;
47
    private ExportToFileDestinationWizardPage page;
48

    
49
    @Inject
50
    public CdmLightExportWizardE4(IEclipseContext context,
51
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
52
        super(context, selection);
53
    }
54

    
55
    @Override
56
    public void init() {
57
        configurator = new CdmLightExportConfigurator(null);
58
        if (selection instanceof TreeSelection && !selection.isEmpty()){
59
            TaxonNode node = (TaxonNode)selection.getFirstElement();
60
            if (node.getParent() == null){
61
                configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(node.getClassification().getUuid()));
62
            }else{
63
                configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(node.getUuid()));
64
            }
65

    
66
        }
67
    }
68

    
69

    
70
    @Override
71
    public CdmLightExportConfigurator getConfigurator() {
72
        return configurator;
73
    }
74

    
75

    
76
    @Override
77
    public boolean performFinish() {
78
        String urlString = page.getFolderText() + File.separator;
79
        //+ page.getExportFileName();
80

    
81
        final Combo combo = page.getCombo();
82
        final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
83
        if(combo != null){
84
            int selectionIndex = combo.getSelectionIndex();
85
            HashSet<UUID> set = new HashSet<UUID>();
86
            if(selectionIndex == -1){
87
                for(Classification c:listClassifications){
88
                    set.add(c.getUuid());
89
                }
90
            }else{
91
                for(Classification c:listClassifications){
92
                    if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
93
                        set.add(c.getUuid());
94

    
95
                        if (!page.getCheckUseSelectedTaxonNode()){
96
                            configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(c.getUuid()));
97
                        }
98
                    }
99
                }
100

    
101

    
102
            }
103
        }
104
        configurator.getTaxonNodeFilter().setIncludeUnpublished(page.isExportUnpublishedData());
105

    
106
        // create job
107
        Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
108
        // configure the job
109
        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
110
        job.setUser(true);
111
        // schedule job
112
        job.schedule();
113
        PreferencesUtil.getPreferenceStore().setValue("exportFolder", page.getFolderText());
114
        return true;
115
    }
116

    
117
    @Override
118
    public void addPages() {
119
        //standard page
120
        page =  ExportToFileDestinationWizardPage.OutputModel(configurator);
121

    
122
        addPage(page);
123
        super.addPages();
124
    }
125

    
126
}
(1-1/2)