2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.io
.wizard
;
13 import java
.io
.FileInputStream
;
14 import java
.io
.FileNotFoundException
;
15 import java
.io
.IOException
;
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
;
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
;
33 * <p>ExcelNormalExplicitTaxaImportWizard class.</p>
36 * @created Sep 22, 2009
39 public class ExcelNormalExplicitTaxaImportWizard
extends AbstractImportWizard
<NormalExplicitImportConfigurator
>{
41 private NormalExplicitImportConfigurator configurator
;
43 private ImportFromFileDataSourceWizardPage dataSourcePage
;
44 private static final Logger logger
= Logger
.getLogger(ExcelNormalExplicitTaxaImportWizard
.class);
47 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
51 public NormalExplicitImportConfigurator
getConfigurator() {
56 * @see org.eclipse.jface.wizard.Wizard#performFinish()
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;
68 fis
= new FileInputStream(file
);
69 } catch (FileNotFoundException e
) {
70 logger
.error("Error while reading file" + source
.toString());
73 configurator
.setStream(IOUtils
.toByteArray(fis
));
74 } catch (IOException e
) {
75 // TODO Auto-generated catch block
78 Job job
= CdmStore
.getImportManager().createIOServiceJob(configurator
,file
, SOURCE_TYPE
.INPUTSTREAM
);
79 CdmStore
.getImportManager().run(job
);
85 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
89 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
90 super.init(workbench
, selection
);
91 configurator
= CdmStore
.getImportManager().NormalExplicitConfigurator();
92 if (selection
instanceof TreeSelection
&& !selection
.isEmpty()){
93 TaxonNode node
= (TaxonNode
)selection
.getFirstElement();
94 configurator
.setParentUUID(node
.getTaxon().getUuid());
95 configurator
.setClassificationUuid(node
.getClassification().getUuid());
100 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
104 public void addPages() {
107 dataSourcePage
= new ImportFromFileDataSourceWizardPage("Choose NormalExplicit",
108 "Please choose an xls file in the NormalExplicit format.", new String
[]{"*.xlsx", "*.xls", "*.*"});
109 addPage(dataSourcePage
);