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.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
|
|
23
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
24
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
25
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
|
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
|
private static final Logger logger = Logger.getLogger(SpecimenSearchWizard.class);
|
36
|
|
37
|
private OccurenceQuery query = null;
|
38
|
private SpecimenProviderSelectionWizardPage providerSelectionPage;
|
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
|
searchPage.getController().saveLastSate();
|
59
|
providerSelectionPage.getController().saveLastState();
|
60
|
|
61
|
DataImportView<?> dataImportView = null;
|
62
|
query = searchPage.getQuery();
|
63
|
Abcd206ImportConfigurator configurator = CdmStore.getImportManager().AbcdConfigurator();
|
64
|
configurator.setOccurenceQuery(query);
|
65
|
configurator.setSourceUri(providerSelectionPage.getEndPoint());
|
66
|
configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
|
67
|
if(CdmStore.getCurrentSessionManager().isRemoting()) {
|
68
|
//Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
|
69
|
//CdmStore.getImportManager().run(job);
|
70
|
|
71
|
CdmStore.getImportManager().run(configurator);
|
72
|
}
|
73
|
// try {
|
74
|
// switch (providerSelectionPage.getQueryType()) {
|
75
|
// case BIOCASE:
|
76
|
// SpecimenImportView specimenImportView = (SpecimenImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
77
|
// .showView(SpecimenImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
78
|
// specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
|
79
|
// dataImportView = specimenImportView;
|
80
|
// break;
|
81
|
// case GBIF:
|
82
|
// dataImportView = (GbifResponseImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
83
|
// .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
84
|
// break;
|
85
|
// }
|
86
|
// } catch ( PartInitException e ) {
|
87
|
// logger.error("Could not open import view for query: " + query.toString(), e);
|
88
|
// }
|
89
|
// if(dataImportView!=null){
|
90
|
// dataImportView.setQuery(query);
|
91
|
//// dataImportView.query();
|
92
|
//// Display.getDefault().asyncExec(new Runnable() {
|
93
|
////
|
94
|
//// @Override
|
95
|
//// public void run() {
|
96
|
//// CdmStore.getContextManager().notifyContextRefresh();
|
97
|
//// }
|
98
|
//// });
|
99
|
Job queryJob = new QueryJob("Query specimen provider", dataImportView);
|
100
|
queryJob.schedule();
|
101
|
|
102
|
return true;
|
103
|
}
|
104
|
|
105
|
/* (non-Javadoc)
|
106
|
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
107
|
*/
|
108
|
@Override
|
109
|
public void addPages() {
|
110
|
addPage(providerSelectionPage);
|
111
|
addPage(searchPage);
|
112
|
}
|
113
|
|
114
|
/* (non-Javadoc)
|
115
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
116
|
*/
|
117
|
@Override
|
118
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
119
|
providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
|
120
|
searchPage = new SpecimenSearchWizardPage("Specimen Search");
|
121
|
}
|
122
|
|
123
|
private class QueryJob extends Job{
|
124
|
|
125
|
private final DataImportView<?> view;
|
126
|
|
127
|
/**
|
128
|
* @param name
|
129
|
*/
|
130
|
public QueryJob(String name, DataImportView<?> view) {
|
131
|
super(name);
|
132
|
this.view = view;
|
133
|
}
|
134
|
|
135
|
/* (non-Javadoc)
|
136
|
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
137
|
*/
|
138
|
@Override
|
139
|
protected IStatus run(IProgressMonitor monitor) {
|
140
|
view.getConversationHolder().bind();
|
141
|
view.query();
|
142
|
Display.getDefault().asyncExec(new Runnable() {
|
143
|
|
144
|
@Override
|
145
|
public void run() {
|
146
|
CdmStore.getContextManager().notifyContextRefresh();
|
147
|
}
|
148
|
});
|
149
|
return Status.OK_STATUS;
|
150
|
}
|
151
|
|
152
|
}
|
153
|
}
|