Project

General

Profile

Download (3.08 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
package eu.etaxonomy.taxeditor.io.wizard;
10

    
11
import java.io.File;
12
import java.io.FileInputStream;
13
import java.io.FileNotFoundException;
14
import java.io.IOException;
15

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

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

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

    
38
	private NormalExplicitImportConfigurator configurator;
39

    
40
	private ImportFromFileDataSourceWizardPage dataSourcePage;
41
	private static final Logger logger = Logger.getLogger(ExcelNormalExplicitTaxaImportWizard.class);
42

    
43
	@Override
44
	public NormalExplicitImportConfigurator getConfigurator() {
45
		return configurator;
46
	}
47

    
48
	@Override
49
	public boolean performFinish() {
50
		URI source = dataSourcePage.getUri();
51
		configurator.setSource(source);
52
		configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
53
		configurator.setSourceReferenceTitle(dataSourcePage.getTextReferenceString().getText());
54
		File file = new File(source.getJavaUri());
55
		FileInputStream fis = null;
56

    
57
		try {
58
			fis = new FileInputStream(file);
59
		} catch (FileNotFoundException e) {
60
			logger.error("Error while reading file" + source.toString());
61
		}
62
		try {
63
            configurator.setStream(IOUtils.toByteArray(fis));
64
        } catch (IOException e) {
65
            // TODO Auto-generated catch block
66
            e.printStackTrace();
67
        }
68
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
69
	    CdmStore.getImportManager().run(job);
70

    
71
		return true;
72
	}
73

    
74
	@Override
75
    public void init(IWorkbench workbench, IStructuredSelection selection) {
76
		super.init(workbench, selection);
77
		configurator =  CdmStore.getImportManager().NormalExplicitConfigurator();
78
		if (selection instanceof TreeSelection && !selection.isEmpty()){
79
			TaxonNode node = (TaxonNode)selection.getFirstElement();
80
			configurator.setParentUUID(node.getTaxon().getUuid());
81
			configurator.setClassificationUuid(node.getClassification().getUuid());
82
		}
83
	}
84

    
85
	@Override
86
	public void addPages() {
87
		super.addPages();
88

    
89
		dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose NormalExplicit",
90
				"Please choose an xls file in the NormalExplicit format.", new String[]{"*.xlsx", "*.xls", "*.*"});
91
		addPage(dataSourcePage);
92
	}
93
}
(16-16/30)