Project

General

Profile

Download (4.11 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.SWT;
20
import org.eclipse.swt.widgets.Combo;
21
import org.eclipse.swt.widgets.Listener;
22
import org.eclipse.ui.IWorkbench;
23
import org.eclipse.ui.progress.IProgressConstants;
24

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

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

    
40
        private CdmLightExportConfigurator configurator;
41
        private ExportToFileDestinationWizardPage page;
42
        
43

    
44

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

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

    
63

    
64
        @Override
65
        public CdmLightExportConfigurator getConfigurator() {
66
            return configurator;
67
        }
68

    
69

    
70
        @Override
71
        public boolean performFinish() {
72
            String urlString = page.getFolderText() + File.separator;
73
                    //+ page.getExportFileName();
74

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

    
96
                }
97
            }
98

    
99
            // create job
100
            Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
101
            // configure the job
102
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
103
            job.setUser(true);
104
            // schedule job
105
            job.schedule();
106
            PreferencesUtil.getPreferenceStore().setValue("exportFolder", page.getFolderText());
107
            return true;
108
        }
109

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

    
115
            addPage(page);
116
            super.addPages();
117
        }
118
        
119

    
120

    
121
}
(8-8/30)