minor
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / dataimport / wizard / SpecimenSearchWizard.java
1 // $Id$
2 /**
3 * Copyright (C) 2013 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 package eu.etaxonomy.taxeditor.dataimport.wizard;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.core.runtime.jobs.Job;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.wizard.Wizard;
19 import org.eclipse.ui.IImportWizard;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.PartInitException;
23 import org.eclipse.ui.PlatformUI;
24
25 import eu.etaxonomy.cdm.ext.biocase.BioCaseQuery;
26 import eu.etaxonomy.taxeditor.dataimport.DataImportEditor;
27 import eu.etaxonomy.taxeditor.dataimport.DerivedUnitEditorInput;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * Wizard for querying BioCASe provider.
32 * @author pplitzner
33 * @date 11.09.2013
34 *
35 */
36 public class SpecimenSearchWizard extends Wizard implements IImportWizard {
37 @SuppressWarnings("unused")
38 private static final Logger logger = Logger.getLogger(SpecimenSearchWizard.class);
39
40 private BioCaseQuery query;
41 private SpecimenSearchWizardPage searchPage;
42
43 /**
44 * Creates a new SpecimenSearchWizard
45 */
46 public SpecimenSearchWizard() {
47 //default constructor needed for RCP extension points
48
49 //check if connected to a data source. If not this will open an error dialog
50 CdmStore.getCurrentApplicationConfiguration();
51 this.setWindowTitle("Search Specimens");
52 }
53
54
55 /* (non-Javadoc)
56 * @see org.eclipse.jface.wizard.Wizard#performFinish()
57 */
58 @Override
59 public boolean performFinish() {
60 final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
61
62 query = searchPage.getQuery();
63 final DerivedUnitEditorInput input = new DerivedUnitEditorInput(query);
64 Job queryJob = new Job("Query Biocase") {
65
66 @Override
67 protected IStatus run(IProgressMonitor monitor) {
68 input.query();
69 return Status.OK_STATUS;
70 }
71 };
72 queryJob.schedule();
73 try {
74 page.openEditor(input, DataImportEditor.ID, true);
75 } catch ( PartInitException e ) {
76 //Put your exception handler here if you wish to
77 }
78 return true;
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.wizard.Wizard#addPages()
83 */
84 @Override
85 public void addPages() {
86 addPage(searchPage);
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
91 */
92 @Override
93 public void init(IWorkbench workbench, IStructuredSelection selection) {
94 query = new BioCaseQuery();
95 searchPage = new SpecimenSearchWizardPage("Specimen Search");
96 }
97
98 /**
99 * Return a {@link BioCaseQuery} with the parameters entered in the wizard
100 * @return the query
101 */
102 public BioCaseQuery getQuery() {
103 return query;
104 }
105
106 }