Project

General

Profile

Download (3.94 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.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.jface.viewers.TreeSelection;
19
import org.eclipse.swt.widgets.Combo;
20
import org.eclipse.ui.IWorkbench;
21
import org.eclipse.ui.progress.IProgressConstants;
22

    
23
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
24
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
25
import eu.etaxonomy.cdm.model.taxon.Classification;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author k.luther
32
 * @date 21.03.2017
33
 *
34
 */
35
public class CdmLightExportWizard extends
36
     AbstractExportWizard<CdmLightExportConfigurator> {
37

    
38
        private CdmLightExportConfigurator configurator;
39
        private ExportToFileDestinationWizardPage page;
40

    
41

    
42

    
43
        private final String description = "Export the contents of the currently selected database into Comma Separated Value format.";
44

    
45
        @Override
46
        public void init(IWorkbench workbench, IStructuredSelection selection) {
47
        	configurator = new CdmLightExportConfigurator(null);
48
    		if (selection instanceof TreeSelection && !selection.isEmpty()){
49
    			TaxonNode node = (TaxonNode)selection.getFirstElement();
50
    			if (node.getParent() == null){
51
    				configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(node.getClassification().getUuid()));
52
    			}else{
53
    				configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(node.getUuid()));
54
    			}
55

    
56
    		}
57

    
58

    
59
        }
60

    
61

    
62
        @Override
63
        public CdmLightExportConfigurator getConfigurator() {
64
            return configurator;
65
        }
66

    
67

    
68
        @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

    
87
                            if (!page.getCheckUseSelectedTaxonNode()){
88
                            	configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(c.getUuid()));
89
                            }
90
                        }
91
                    }
92

    
93

    
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
            PreferencesUtil.setStringValue("exportFolder", page.getFolderText());
105
            return true;
106
        }
107

    
108
        @Override
109
        public void addPages() {
110
            //standard page
111
            page =  ExportToFileDestinationWizardPage.OutputModel(configurator);
112

    
113
            addPage(page);
114
            super.addPages();
115
        }
116

    
117

    
118

    
119
}
(8-8/30)