Project

General

Profile

Download (3.54 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.io.wizard;
11

    
12
import java.io.File;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.jface.viewers.IStructuredSelection;
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.io.csv.redlist.demo.CsvDemoExportConfigurator;
24
import eu.etaxonomy.cdm.model.taxon.Classification;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * @author a.oppermann
29
 * @created Nov. 11, 2014
30
 * @version 1.0
31
 */
32
public class CsvExportWizard extends AbstractExportWizard<CsvDemoExportConfigurator> {
33

    
34
	private CsvDemoExportConfigurator configurator;
35
	private ExportToFileDestinationWizardPage page;
36

    
37
	private final String description = "Export the contents of the currently selected database into Comma Separated Value format.";
38
	/*
39
	 * (non-Javadoc)
40
	 *
41
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
42
	 * org.eclipse.jface.viewers.IStructuredSelection)
43
	 */
44
	@Override
45
	public void init(IWorkbench workbench, IStructuredSelection selection) {
46
		configurator = CsvDemoExportConfigurator.NewInstance(null, null);
47
	}
48

    
49
	/*
50
	 * (non-Javadoc)
51
	 *
52
	 * @see
53
	 * eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#getConfigurator()
54
	 */
55
	@Override
56
	public CsvDemoExportConfigurator getConfigurator() {
57
		return configurator;
58
	}
59

    
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
64
	 */
65
	@Override
66
	public boolean performFinish() {
67
		String urlString = page.getFolderText() + File.separator
68
				+ page.getExportFileName();
69

    
70
		final Combo combo = page.getCombo();
71
		final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
72
		if(combo != null){
73
		    int selectionIndex = combo.getSelectionIndex();
74
		    HashSet<UUID> set = new HashSet<UUID>();
75
		    if(selectionIndex == -1){
76
		        for(Classification c:listClassifications){
77
		            set.add(c.getUuid());
78
		        }
79
		    }else{
80
		        for(Classification c:listClassifications){
81
		            if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
82
		                set.add(c.getUuid());
83
		            }
84
		        }
85
		        configurator.setClassificationUuids(set);
86
		        configurator.setDoTaxa(true);
87
		        configurator.setHasHeaderLines(true);
88
		        configurator.setClassification(true);
89
		        configurator.setTaxonName(true);
90
		        configurator.setAuthor(true);
91
		        configurator.setRank(true);
92
		        configurator.setLastChange(true);
93
		    }
94
		}
95
		
96
	    // create job
97
	    Job job = CdmStore.getExportManager().createIOServiceJob(configurator, new File(urlString));
98
	    // configure the job
99
	    job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
100
	    job.setUser(true);
101
	    // schedule job
102
	    job.schedule();
103
		
104
		return true;
105
	}
106

    
107
	/*
108
	 * (non-Javadoc)
109
	 *
110
	 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#addPages()
111
	 */
112
	@Override
113
	public void addPages() {
114
	    //TODO create page with drop down menu for export for single classification.
115
//		super.addPages();
116

    
117

    
118
		//standard page
119
		page =  ExportToFileDestinationWizardPage.Csv(configurator);
120

    
121
		addPage(page);
122
	}
123
}
(10-10/30)