3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.dataimport
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
14 import java
.net
.URISyntaxException
;
15 import java
.util
.List
;
17 import org
.apache
.http
.client
.ClientProtocolException
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.core
.runtime
.jobs
.Job
;
23 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
24 import org
.eclipse
.swt
.widgets
.Display
;
25 import org
.eclipse
.ui
.IEditorInput
;
26 import org
.eclipse
.ui
.IPersistableElement
;
28 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQuery
;
29 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQueryServiceWrapper
;
30 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
31 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
32 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
33 import eu
.etaxonomy
.taxeditor
.dataimport
.transientServices
.TransientCdmRepository
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 public class DerivedUnitEditorInput
implements IEditorInput
{
43 private static Logger logger
= Logger
.getLogger(DerivedUnitEditorInput
.class);
45 private final BioCaseQuery query
;
47 private List
<SpecimenOrObservationBase
> results
;
52 public DerivedUnitEditorInput(BioCaseQuery query
) {
54 Display
.getCurrent().asyncExec(new Runnable() {
58 String errorMessage
= "Could not execute query " + DerivedUnitEditorInput
.this.query
;
60 InputStream resultStream
= new BioCaseQueryServiceWrapper().query(DerivedUnitEditorInput
.this.query
);
61 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
62 TransientCdmRepository repo
=
63 new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
64 configurator
.setCdmAppController(repo
);
66 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
67 importer
.invoke(configurator
);
68 results
= repo
.getUnits();
69 // Abcd206Import abcd206Import = new Abcd206Import();
70 // Abcd206ImportState state = new Abcd206ImportState(configurator);
71 // abcd206Import.invoke(state);
72 // state.countTrees();
73 } catch (ClientProtocolException e
) {
74 logger
.error(errorMessage
, e
);
75 } catch (IOException e
) {
76 logger
.error(errorMessage
, e
);
77 } catch (URISyntaxException e
) {
78 logger
.error(errorMessage
, e
);
80 // return new BioCaseQueryServiceWrapper().dummyData();
86 Job queryJob
= new Job("Query Biocase") {
89 protected IStatus
run(IProgressMonitor monitor
) {
90 String errorMessage
= "Could not execute query " + DerivedUnitEditorInput
.this.query
;
92 InputStream resultStream
= new BioCaseQueryServiceWrapper().query(DerivedUnitEditorInput
.this.query
);
93 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
94 TransientCdmRepository repo
=
95 new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
96 configurator
.setCdmAppController(repo
);
98 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
99 importer
.invoke(configurator
);
100 results
= repo
.getUnits();
101 // Abcd206Import abcd206Import = new Abcd206Import();
102 // Abcd206ImportState state = new Abcd206ImportState(configurator);
103 // abcd206Import.invoke(state);
104 // state.countTrees();
105 } catch (ClientProtocolException e
) {
106 logger
.error(errorMessage
, e
);
107 } catch (IOException e
) {
108 logger
.error(errorMessage
, e
);
109 } catch (URISyntaxException e
) {
110 logger
.error(errorMessage
, e
);
113 Display
.getDefault().asyncExec(new Runnable() {
117 CdmStore
.getContextManager().notifyContextRefresh();
121 return Status
.OK_STATUS
;
127 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
130 public Object
getAdapter(Class adapter
) {
131 // TODO Auto-generated method stub
136 * @see org.eclipse.ui.IEditorInput#exists()
139 public boolean exists() {
144 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
147 public ImageDescriptor
getImageDescriptor() {
148 // TODO Auto-generated method stub
153 * @see org.eclipse.ui.IEditorInput#getName()
156 public String
getName() {
157 return query
.toString();
161 * @see org.eclipse.ui.IEditorInput#getPersistable()
164 public IPersistableElement
getPersistable() {
169 * @see org.eclipse.ui.IEditorInput#getToolTipText()
172 public String
getToolTipText() {
173 return query
.toString();
177 * @return the results
179 public List
<SpecimenOrObservationBase
> getResults() {
184 * @see java.lang.Object#hashCode()
187 public int hashCode() {
188 final int prime
= 31;
190 result
= prime
* result
+ ((query
== null) ?
0 : query
.hashCode());
195 * @see java.lang.Object#equals(java.lang.Object)
198 public boolean equals(Object obj
) {
205 if (getClass() != obj
.getClass()) {
208 DerivedUnitEditorInput other
= (DerivedUnitEditorInput
) obj
;
210 if (other
.query
!= null) {
213 } else if (!query
.equals(other
.query
)) {