412b991dda75084aebbc0c0cc4683cb717d09ee9
[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.swt.widgets.Display;
20 import org.eclipse.ui.IImportWizard;
21 import org.eclipse.ui.IWorkbench;
22 import org.eclipse.ui.PartInitException;
23
24 import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
25 import eu.etaxonomy.taxeditor.editor.EditorUtil;
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 SpecimenProviderSelectionWizardPage providerSelectionPage;
40 private SpecimenSearchWizardPage searchPage;
41
42 /**
43 * Creates a new SpecimenSearchWizard
44 */
45 public SpecimenSearchWizard() {
46 //default constructor needed for RCP extension points
47
48 //check if connected to a data source. If not this will open an error dialog
49 CdmStore.getCurrentApplicationConfiguration();
50 this.setWindowTitle("Search Specimens");
51 }
52
53
54 /* (non-Javadoc)
55 * @see org.eclipse.jface.wizard.Wizard#performFinish()
56 */
57 @Override
58 public boolean performFinish() {
59 searchPage.getController().saveLastSate();
60
61 DataImportEditorInput<?> input = null;
62 query = searchPage.getQuery();
63 switch (providerSelectionPage.getQueryType()) {
64 case BIOCASE:
65 input = new BioCaseEditorInput(query, null);
66 break;
67 case GBIF:
68 input = new GbifImportEditorInput(query);
69 break;
70 }
71 try {
72 EditorUtil.open(input);
73 } catch ( PartInitException e ) {
74 //Put your exception handler here if you wish to
75 }
76 Job queryJob = new QueryJob("Query specimen provider", input);
77 queryJob.schedule();
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(providerSelectionPage);
87 addPage(searchPage);
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
92 */
93 @Override
94 public void init(IWorkbench workbench, IStructuredSelection selection) {
95 providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
96 searchPage = new SpecimenSearchWizardPage("Specimen Search");
97 }
98
99 private class QueryJob extends Job{
100
101 private final DataImportEditorInput<?> input;
102
103 /**
104 * @param name
105 */
106 public QueryJob(String name, DataImportEditorInput<?> input) {
107 super(name);
108 this.input = input;
109 }
110
111 /* (non-Javadoc)
112 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
113 */
114 @Override
115 protected IStatus run(IProgressMonitor monitor) {
116 input.query();
117 Display.getDefault().asyncExec(new Runnable() {
118
119 @Override
120 public void run() {
121 CdmStore.getContextManager().notifyContextRefresh();
122 }
123 });
124 return Status.OK_STATUS;
125 }
126
127 }
128 }