cd6b6800381979f1683b86666eeebbc621134cd0
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / ExcelNormalExplicitTaxaImportWizard.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.net.URI;
15
16 import org.eclipse.core.runtime.jobs.Job;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.TreeSelection;
19 import org.eclipse.ui.IWorkbench;
20
21 import eu.etaxonomy.cdm.database.DbSchemaValidation;
22 import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
23 import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
24 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27
28 /**
29 * <p>ExcelNormalExplicitTaxaImportWizard class.</p>
30 *
31 * @author n.hoffmann
32 * @created Sep 22, 2009
33 * @version 1.0
34 */
35 public class ExcelNormalExplicitTaxaImportWizard extends AbstractImportWizard<NormalExplicitImportConfigurator>{
36
37 private NormalExplicitImportConfigurator configurator;
38
39 private ImportFromFileDataSourceWizardPage dataSourcePage;
40
41 /* (non-Javadoc)
42 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
43 */
44 /** {@inheritDoc} */
45 @Override
46 public NormalExplicitImportConfigurator getConfigurator() {
47 return configurator;
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.jface.wizard.Wizard#performFinish()
52 */
53 /** {@inheritDoc} */
54 @Override
55 public boolean performFinish() {
56 URI source = dataSourcePage.getUri();
57 configurator.setSource(source);
58 configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
59
60 if(CdmStore.getCurrentSessionManager().isRemoting()) {
61 Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.URI);
62 CdmStore.getImportManager().run(job);
63 } else {
64 CdmStore.getImportManager().run(configurator);
65 }
66
67
68 return true;
69 }
70
71 /* (non-Javadoc)
72 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
73 */
74 /** {@inheritDoc} */
75 @Override
76 public void init(IWorkbench workbench, IStructuredSelection selection) {
77 super.init(workbench, selection);
78 configurator = CdmStore.getImportManager().NormalExplicitConfigurator();
79 if (selection instanceof TreeSelection && !selection.isEmpty()){
80 TaxonNode node = (TaxonNode)selection.getFirstElement();
81 configurator.setParentUUID(node.getTaxon().getUuid());
82 configurator.setClassificationUuid(node.getClassification().getUuid());
83 }
84 }
85
86 /* (non-Javadoc)
87 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
88 */
89 /** {@inheritDoc} */
90 @Override
91 public void addPages() {
92 super.addPages();
93
94 dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose NormalExplicit",
95 "Please choose an xls file in the NormalExplicit format.", new String[]{"*.xlsx", "*.xls", "*.*"});
96 addPage(dataSourcePage);
97 }
98 }