Project

General

Profile

Download (3.72 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

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

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

    
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.swt.widgets.Combo;
21
import org.eclipse.ui.IWorkbench;
22
import org.eclipse.ui.progress.IProgressConstants;
23

    
24
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
25
import eu.etaxonomy.cdm.model.taxon.Classification;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

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

    
35
	private CsvDemoExportConfigurator configurator;
36
	private ExportToFileDestinationWizardPage page;
37

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

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

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

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

    
106
		    configurator.setDestination(new File(urlString));
107
		    CdmStore.getExportManager().run(configurator);
108
		}
109
		return true;
110
	}
111

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

    
122

    
123
		//standard page
124
		page =  ExportToFileDestinationWizardPage.Csv();
125

    
126
		addPage(page);
127
	}
128
}
(8-8/25)