Project

General

Profile

Download (3.57 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
		configurator.setSourceReferenceTitle(dataSourcePage.getTextReferenceString().getText());
65
		File file = new File(source);
66
		FileInputStream fis = null;
67

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

    
82
		return true;
83
	}
84

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

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

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