d6f3236ea638ddb1463fbdb70c4b48a185008dfc
[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 *
31 * @author n.hoffmann
32 * @created Jun 16, 2010
33 * @version 1.0
34 */
35 public class AbcdImportWizard extends AbstractImportWizard<Abcd206ImportConfigurator> {
36
37 private static final Logger logger = Logger.getLogger(AbcdImportWizard.class);
38
39 private Abcd206ImportConfigurator configurator;
40 private AbcdSourceSelectionPage dataSourcePage;
41 private ClassificationChooserWizardPage classificationChooserWizardPage;
42
43 /** {@inheritDoc} */
44 @Override
45 public Abcd206ImportConfigurator getConfigurator() {
46 return configurator;
47 }
48
49 /** {@inheritDoc} */
50 @Override
51 public boolean performFinish() {
52 URI source = dataSourcePage.getUri();
53 configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
54
55 if(classificationChooserWizardPage.getClassification()!=null){
56 configurator.setClassificationUuid(classificationChooserWizardPage.getClassification().getUuid());
57 }
58
59 if(CdmStore.getCurrentSessionManager().isRemoting()) {
60 //Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
61 //CdmStore.getImportManager().run(job);
62 CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
63 } else {
64 try {
65 configurator.setSource(new FileInputStream(new File(source)));
66 } catch (FileNotFoundException e) {
67 MessagingUtils.errorDialog("File not found.", this, "Import file was not found.", TaxeditorStorePlugin.PLUGIN_ID, e, false);
68 logger.error("File not found!", e);
69 return false;
70 }
71 CdmStore.getImportManager().run(configurator);
72 }
73 return true;
74
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 public void init(IWorkbench workbench, IStructuredSelection selection) {
80 super.init(workbench, selection);
81 configurator = CdmStore.getImportManager().AbcdConfigurator();
82 }
83
84 /** {@inheritDoc} */
85 @Override
86 public void addPages() {
87 super.addPages();
88
89 classificationChooserWizardPage = ClassificationChooserWizardPage.createPage();
90
91 dataSourcePage = ImportFromFileDataSourceWizardPage.XML();
92
93 addPage(classificationChooserWizardPage);
94 addPage(dataSourcePage);
95 }
96 }