Project

General

Profile

Download (3.22 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.net.URI;
16

    
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.database.DbSchemaValidation;
24
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
25
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29

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

    
39
	private NormalExplicitImportConfigurator configurator;
40

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

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

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

    
65
		try {
66
			fis = new FileInputStream(file);
67
		} catch (FileNotFoundException e) {
68
			logger.error("Error while reading file" + source.toString());
69
		}
70

    
71
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,fis , SOURCE_TYPE.INPUTSTREAM);
72
	    CdmStore.getImportManager().run(job);
73

    
74
		return true;
75
	}
76

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

    
92
	/* (non-Javadoc)
93
	 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
94
	 */
95
	/** {@inheritDoc} */
96
	@Override
97
	public void addPages() {
98
		super.addPages();
99

    
100
		dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose NormalExplicit",
101
				"Please choose an xls file in the NormalExplicit format.", new String[]{"*.xlsx", "*.xls", "*.*"});
102
		addPage(dataSourcePage);
103
	}
104
}
(14-14/26)