Revert "Split up composites of FeatureTreeEditor"
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ExcelDistributionUpdateWizard.java
1 /**
2 * Copyright (C) 2017 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 package eu.etaxonomy.taxeditor.io.wizard;
10
11 import java.io.File;
12 import java.io.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.io.IOException;
15 import java.net.URI;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.UUID;
19
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;
25
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;
30
31 /**
32 * @author k.luther
33 * @date 03.05.2017
34 *
35 */
36 public class ExcelDistributionUpdateWizard extends AbstractImportWizard<ExcelDistributionUpdateConfigurator> {
37 private ExcelDistributionUpdateConfigurator configurator;
38
39 private ImportFromFileAndChooseVocIdWizardOage dataSourcePage;
40
41 private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
42
43 /* (non-Javadoc)
44 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
45 */
46 /** {@inheritDoc} */
47 @Override
48 public ExcelDistributionUpdateConfigurator getConfigurator() {
49 return configurator;
50 }
51
52 /* (non-Javadoc)
53 * @see org.eclipse.jface.wizard.Wizard#performFinish()
54 */
55 /** {@inheritDoc} */
56 @Override
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;
63
64 try {
65 fis = new FileInputStream(file);
66 } catch (FileNotFoundException e) {
67 logger.error("Error while reading file" + source.toString());
68 }
69 try {
70 configurator.setStream(IOUtils.toByteArray(fis));
71 } catch (IOException e) {
72 // TODO Auto-generated catch block
73 e.printStackTrace();
74 }
75 UUID vocUuid = dataSourcePage.getVocUuid();
76
77 configurator.setAreaVocabularyUuid(vocUuid);
78 Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
79 CdmStore.getImportManager().run(job);
80
81 return true;
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
86 */
87 /** {@inheritDoc} */
88 @Override
89 public void init(IWorkbench workbench, IStructuredSelection selection) {
90 super.init(workbench, selection);
91 configurator = CdmStore.getImportManager().ExcelDistributionUpdateConfigurator();
92
93 }
94
95 /* (non-Javadoc)
96 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
97 */
98 /** {@inheritDoc} */
99 @Override
100 public void addPages() {
101 addConfiguratorPage();
102 addDataSourcePage();
103
104
105 }
106 @Override
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);
114 }
115
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);
120 }
121
122
123 }