Project

General

Profile

Download (3.24 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.io.wizard;
12

    
13
import java.io.File;
14
import java.io.FileInputStream;
15
import java.io.FileNotFoundException;
16
import java.net.URI;
17
import org.apache.log4j.Logger;
18

    
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.TreeSelection;
22
import org.eclipse.ui.IWorkbench;
23

    
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

    
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
			
73
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
74
	    CdmStore.getImportManager().run(job);
75
		
76
		return true;
77
	}
78

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

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

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