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