1 package eu
.etaxonomy
.taxeditor
.editor
.view
.dataimport
;
3 import java
.io
.IOException
;
5 import org
.apache
.http
.client
.ClientProtocolException
;
6 import org
.apache
.log4j
.Logger
;
7 import org
.eclipse
.core
.commands
.AbstractHandler
;
8 import org
.eclipse
.core
.commands
.ExecutionEvent
;
9 import org
.eclipse
.core
.commands
.ExecutionException
;
10 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
11 import org
.eclipse
.core
.runtime
.IStatus
;
12 import org
.eclipse
.core
.runtime
.Status
;
13 import org
.eclipse
.core
.runtime
.jobs
.Job
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
16 import org
.eclipse
.ui
.IWorkbenchWindow
;
17 import org
.eclipse
.ui
.PartInitException
;
18 import org
.eclipse
.ui
.PlatformUI
;
20 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
21 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.DataSetResponse
;
22 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.GbifQueryServiceWrapper
;
23 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.GbifResponse
;
24 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 public class QueryOriginalRecordCommand
extends AbstractHandler
{
28 private final Logger logger
= Logger
.getLogger(QueryOriginalRecordCommand
.class);
31 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
34 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
35 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
36 final ISelection selection
= window
.getActivePage().getSelection();
37 if(selection
instanceof StructuredSelection
){
38 StructuredSelection structuredSelection
= (StructuredSelection
)selection
;
39 if(structuredSelection
.size()==1){
40 Object next
= structuredSelection
.iterator().next();
41 if(next
instanceof GbifResponse
){
43 DataSetResponse response
= new GbifQueryServiceWrapper().queryOriginalDataSet((GbifResponse
)next
);
44 final BioCaseEditorInput input
= new BioCaseEditorInput(new OccurenceQuery(response
.getUnitId()), response
.getEndpoint());
45 EditorUtil
.open(input
);
46 Job queryJob
= new Job("Querying for original record...") {
49 protected IStatus
run(IProgressMonitor monitor
) {
51 return Status
.OK_STATUS
;
55 } catch (ClientProtocolException e
) {
56 logger
.error("Query for single record failed.", e
);
57 } catch (IOException e
) {
58 logger
.error("Query for single record failed.", e
);
59 } catch (PartInitException e
) {
60 logger
.error("Could not open editor.", e
);