2 * Copyright (C) 2017 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.
9 package eu
.etaxonomy
.taxeditor
.io
.wizard
;
12 import java
.io
.FileInputStream
;
13 import java
.io
.FileNotFoundException
;
14 import java
.io
.IOException
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.commons
.io
.IOUtils
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.eclipse
.core
.runtime
.jobs
.Job
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.ui
.IWorkbench
;
26 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
27 import eu
.etaxonomy
.cdm
.io
.distribution
.excelupdate
.ExcelDistributionUpdateConfigurator
;
28 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class ExcelDistributionUpdateWizard
extends AbstractImportWizard
<ExcelDistributionUpdateConfigurator
> {
37 private ExcelDistributionUpdateConfigurator configurator
;
39 private ImportFromFileAndChooseVocIdWizardOage dataSourcePage
;
41 private static final Logger logger
= Logger
.getLogger(ExcelDistributionUpdateWizard
.class);
44 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
48 public ExcelDistributionUpdateConfigurator
getConfigurator() {
53 * @see org.eclipse.jface.wizard.Wizard#performFinish()
57 public boolean performFinish() {
58 URI source
= dataSourcePage
.getUri();
59 // configurator.setSource(source);
60 configurator
.setDbSchemaValidation(DbSchemaValidation
.CREATE
);
61 File file
= new File(source
);
62 FileInputStream fis
= null;
65 fis
= new FileInputStream(file
);
66 } catch (FileNotFoundException e
) {
67 logger
.error("Error while reading file" + source
.toString());
70 configurator
.setStream(IOUtils
.toByteArray(fis
));
71 } catch (IOException e
) {
72 // TODO Auto-generated catch block
75 UUID vocUuid
= dataSourcePage
.getVocUuid();
77 configurator
.setAreaVocabularyUuid(vocUuid
);
78 Job job
= CdmStore
.getImportManager().createIOServiceJob(configurator
);
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().ExcelDistributionUpdateConfigurator();
96 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
100 public void addPages() {
101 addConfiguratorPage();
107 protected void addConfiguratorPage(){
108 List
<String
> ignoreMethods
= new ArrayList
<>();
109 ignoreMethods
.add("setIgnoreNull");
110 ignoreMethods
.add("setInteractWithUser");
111 ignoreMethods
.add("setUseClassification");
112 pageConfiguration
= GenericConfiguratorWizardPage
.Import(CONFIGURATION_PAGE
, getConfigurator(), ignoreMethods
, Messages
.ExcelDistributionUpdateWizard_ConfiguratorWizard_label
);
113 addPage(pageConfiguration
);
116 private void addDataSourcePage(){
117 dataSourcePage
= new ImportFromFileAndChooseVocIdWizardOage("Choose Excel File",
118 "Please choose an xls file in the Distribution Update format.", new String
[]{"*.xlsx", "*.xls", "*.*"});
119 addPage(dataSourcePage
);