Handle "Finish" button correctly for import wizards
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / AbcdImportWizard.java
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
18 import org.apache.log4j.Logger;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.ui.IWorkbench;
21
22 import eu.etaxonomy.cdm.database.DbSchemaValidation;
23 import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
24 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25 import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
28
29 /**
30 * <p>AbcdImportWizard class.</p>
31 *
32 * @author n.hoffmann
33 * @created Jun 16, 2010
34 * @version 1.0
35 */
36 public class AbcdImportWizard extends AbstractImportWizard<Abcd206ImportConfigurator> {
37
38 private static final Logger logger = Logger.getLogger(AbcdImportWizard.class);
39
40 private Abcd206ImportConfigurator configurator;
41 private ImportFromFileDataSourceWizardPage dataSourcePage;
42 private ClassificationChooserWizardPage classificationChooserWizardPage;
43
44 /* (non-Javadoc)
45 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
46 */
47 /** {@inheritDoc} */
48 @Override
49 public Abcd206ImportConfigurator getConfigurator() {
50 return configurator;
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.jface.wizard.Wizard#performFinish()
55 */
56 /** {@inheritDoc} */
57 @Override
58 public boolean performFinish() {
59 URI source = dataSourcePage.getUri();
60 configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
61
62 if(classificationChooserWizardPage.getClassification()!=null){
63 configurator.setClassificationUuid(classificationChooserWizardPage.getClassification().getUuid());
64 }
65
66 if(CdmStore.getCurrentSessionManager().isRemoting()) {
67 //Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
68 //CdmStore.getImportManager().run(job);
69 CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
70 } else {
71 try {
72 configurator.setSource(new FileInputStream(new File(source)));
73 } catch (FileNotFoundException e) {
74 MessagingUtils.errorDialog("File not found.", this, "Import file was not found.", TaxeditorStorePlugin.PLUGIN_ID, e, false);
75 logger.error("File not found!", e);
76 return false;
77 }
78 CdmStore.getImportManager().run(configurator);
79 }
80 return true;
81
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().AbcdConfigurator();
92 }
93
94 /* (non-Javadoc)
95 * @see eu.etaxonomy.taxeditor.io.AbstractImportWizard#addPages()
96 */
97 /** {@inheritDoc} */
98 @Override
99 public void addPages() {
100 super.addPages();
101
102 classificationChooserWizardPage = ClassificationChooserWizardPage.createPage();
103 dataSourcePage = ImportFromFileDataSourceWizardPage.XML();
104 addPage(classificationChooserWizardPage);
105 addPage(dataSourcePage);
106 }
107 }