Project

General

Profile

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

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

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

    
37
        private CdmLightExportConfigurator configurator;
38
        private ExportToFileDestinationWizardPage page;
39
        
40

    
41

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

    
44
        @Override
45
        public void init(IWorkbench workbench, IStructuredSelection selection) {
46
            configurator = new CdmLightExportConfigurator(null);
47
        }
48

    
49

    
50
        @Override
51
        public CdmLightExportConfigurator getConfigurator() {
52
            return configurator;
53
        }
54

    
55

    
56
        @Override
57
        public boolean performFinish() {
58
            String urlString = page.getFolderText() + File.separator;
59
                    //+ page.getExportFileName();
60

    
61
            final Combo combo = page.getCombo();
62
            final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
63
            if(combo != null){
64
                int selectionIndex = combo.getSelectionIndex();
65
                HashSet<UUID> set = new HashSet<UUID>();
66
                if(selectionIndex == -1){
67
                    for(Classification c:listClassifications){
68
                        set.add(c.getUuid());
69
                    }
70
                }else{
71
                    for(Classification c:listClassifications){
72
                        if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
73
                            set.add(c.getUuid());
74
                        }
75
                    }
76
                    configurator.setClassificationUuids(set);
77

    
78
                }
79
            }
80

    
81
            // create job
82
            Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
83
            // configure the job
84
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
85
            job.setUser(true);
86
            // schedule job
87
            job.schedule();
88
            PreferencesUtil.getPreferenceStore().setValue("exportFolder", page.getFolderText());
89
            return true;
90
        }
91

    
92
        @Override
93
        public void addPages() {
94
            //TODO create page with drop down menu for export for single classification.
95
        	super.addPages();
96

    
97

    
98
            //standard page
99
            page =  ExportToFileDestinationWizardPage.OutputModel(configurator);
100

    
101
            addPage(page);
102
        }
103
        
104

    
105

    
106
}
(8-8/30)