Project

General

Profile

Download (3.48 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.io.FileInputStream;
14
import java.io.FileNotFoundException;
15
import java.io.IOException;
16
import java.net.URI;
17

    
18
import org.apache.commons.io.IOUtils;
19
import org.apache.log4j.Logger;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.TreeSelection;
23
import org.eclipse.ui.IWorkbench;
24

    
25
import eu.etaxonomy.cdm.database.DbSchemaValidation;
26
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
27
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31

    
32
/**
33
 * <p>ExcelNormalExplicitTaxaImportWizard class.</p>
34
 *
35
 * @author n.hoffmann
36
 * @created Sep 22, 2009
37
 * @version 1.0
38
 */
39
public class ExcelNormalExplicitTaxaImportWizard extends AbstractImportWizard<NormalExplicitImportConfigurator>{
40

    
41
	private NormalExplicitImportConfigurator configurator;
42

    
43
	private ImportFromFileDataSourceWizardPage dataSourcePage;
44
	private static final Logger logger = Logger.getLogger(ExcelNormalExplicitTaxaImportWizard.class);
45

    
46
	/* (non-Javadoc)
47
	 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
48
	 */
49
	/** {@inheritDoc} */
50
	@Override
51
	public NormalExplicitImportConfigurator getConfigurator() {
52
		return configurator;
53
	}
54

    
55
	/* (non-Javadoc)
56
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
57
	 */
58
	/** {@inheritDoc} */
59
	@Override
60
	public boolean performFinish() {
61
		URI source = dataSourcePage.getUri();
62
		configurator.setSource(source);
63
		configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
64
		File file = new File(source);
65
		FileInputStream fis = null;
66

    
67
		try {
68
			fis = new FileInputStream(file);
69
		} catch (FileNotFoundException e) {
70
			logger.error("Error while reading file" + source.toString());
71
		}
72
		try {
73
            configurator.setStream(IOUtils.toByteArray(fis));
74
        } catch (IOException e) {
75
            // TODO Auto-generated catch block
76
            e.printStackTrace();
77
        }
78
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
79
	    CdmStore.getImportManager().run(job);
80

    
81
		return true;
82
	}
83

    
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
86
	 */
87
	/** {@inheritDoc} */
88
	@Override
89
    public void init(IWorkbench workbench, IStructuredSelection selection) {
90
		super.init(workbench, selection);
91
		configurator =  CdmStore.getImportManager().NormalExplicitConfigurator();
92
		if (selection instanceof TreeSelection && !selection.isEmpty()){
93
			TaxonNode node = (TaxonNode)selection.getFirstElement();
94
			configurator.setParentUUID(node.getTaxon().getUuid());
95
			configurator.setClassificationUuid(node.getClassification().getUuid());
96
		}
97
	}
98

    
99
	/* (non-Javadoc)
100
	 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
101
	 */
102
	/** {@inheritDoc} */
103
	@Override
104
	public void addPages() {
105
		super.addPages();
106

    
107
		dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose NormalExplicit",
108
				"Please choose an xls file in the NormalExplicit format.", new String[]{"*.xlsx", "*.xls", "*.*"});
109
		addPage(dataSourcePage);
110
	}
111
}
(14-14/26)