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