Project

General

Profile

Download (3.23 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
import org.apache.log4j.Logger;
17

    
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

    
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30

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

    
40
	private NormalExplicitImportConfigurator configurator;
41

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

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

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

    
66
		try {
67
			fis = new FileInputStream(file);
68
		} catch (FileNotFoundException e) {
69
			logger.error("Error while reading file" + source.toString());
70
		}
71
			
72
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
73
	    CdmStore.getImportManager().run(job);
74
		
75
		return true;
76
	}
77

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

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

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