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.IWorkbenchPage;
|
23
|
import org.eclipse.ui.PartInitException;
|
24
|
|
25
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
26
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
/**
|
30
|
* Wizard for querying specimen provider.
|
31
|
* @author pplitzner
|
32
|
* @date 11.09.2013
|
33
|
*
|
34
|
*/
|
35
|
public class SpecimenSearchWizard extends Wizard implements IImportWizard {
|
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
|
providerSelectionPage.getController().saveLastState();
|
61
|
|
62
|
DataImportView<?> dataImportView = null;
|
63
|
query = searchPage.getQuery();
|
64
|
try {
|
65
|
switch (providerSelectionPage.getQueryType()) {
|
66
|
case BIOCASE:
|
67
|
SpecimenImportView specimenImportView = (SpecimenImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
68
|
.showView(SpecimenImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
69
|
specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
|
70
|
dataImportView = specimenImportView;
|
71
|
break;
|
72
|
case GBIF:
|
73
|
dataImportView = (GbifResponseImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
74
|
.showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
75
|
break;
|
76
|
}
|
77
|
} catch ( PartInitException e ) {
|
78
|
logger.error("Could not open import view for query: " + query.toString(), e);
|
79
|
}
|
80
|
if(dataImportView!=null){
|
81
|
dataImportView.setQuery(query);
|
82
|
// dataImportView.query();
|
83
|
// Display.getDefault().asyncExec(new Runnable() {
|
84
|
//
|
85
|
// @Override
|
86
|
// public void run() {
|
87
|
// CdmStore.getContextManager().notifyContextRefresh();
|
88
|
// }
|
89
|
// });
|
90
|
Job queryJob = new QueryJob("Query specimen provider", dataImportView);
|
91
|
queryJob.schedule();
|
92
|
}
|
93
|
return true;
|
94
|
}
|
95
|
|
96
|
/* (non-Javadoc)
|
97
|
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
98
|
*/
|
99
|
@Override
|
100
|
public void addPages() {
|
101
|
addPage(providerSelectionPage);
|
102
|
addPage(searchPage);
|
103
|
}
|
104
|
|
105
|
/* (non-Javadoc)
|
106
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
107
|
*/
|
108
|
@Override
|
109
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
110
|
providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
|
111
|
searchPage = new SpecimenSearchWizardPage("Specimen Search");
|
112
|
}
|
113
|
|
114
|
private class QueryJob extends Job{
|
115
|
|
116
|
private final DataImportView<?> view;
|
117
|
|
118
|
/**
|
119
|
* @param name
|
120
|
*/
|
121
|
public QueryJob(String name, DataImportView<?> view) {
|
122
|
super(name);
|
123
|
this.view = view;
|
124
|
}
|
125
|
|
126
|
/* (non-Javadoc)
|
127
|
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
128
|
*/
|
129
|
@Override
|
130
|
protected IStatus run(IProgressMonitor monitor) {
|
131
|
view.getConversationHolder().bind();
|
132
|
view.query();
|
133
|
Display.getDefault().asyncExec(new Runnable() {
|
134
|
|
135
|
@Override
|
136
|
public void run() {
|
137
|
CdmStore.getContextManager().notifyContextRefresh();
|
138
|
}
|
139
|
});
|
140
|
return Status.OK_STATUS;
|
141
|
}
|
142
|
|
143
|
}
|
144
|
}
|