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
.ArrayList
;
16 import java
.util
.List
;
18 import org
.apache
.http
.client
.ClientProtocolException
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
21 import org
.eclipse
.ui
.IEditorInput
;
22 import org
.eclipse
.ui
.IPersistableElement
;
24 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQuery
;
25 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQueryServiceWrapper
;
26 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
27 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
29 import eu
.etaxonomy
.taxeditor
.dataimport
.transientServices
.TransientCdmRepository
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 public class DerivedUnitEditorInput
implements IEditorInput
{
39 private static Logger logger
= Logger
.getLogger(DerivedUnitEditorInput
.class);
41 private final BioCaseQuery query
;
43 private List
<SpecimenOrObservationBase
> results
;
48 public DerivedUnitEditorInput(BioCaseQuery query
) {
50 results
= new ArrayList
<SpecimenOrObservationBase
>();
54 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
57 public Object
getAdapter(Class adapter
) {
58 // TODO Auto-generated method stub
63 * @see org.eclipse.ui.IEditorInput#exists()
66 public boolean exists() {
71 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
74 public ImageDescriptor
getImageDescriptor() {
75 // TODO Auto-generated method stub
80 * @see org.eclipse.ui.IEditorInput#getName()
83 public String
getName() {
84 return query
.toString();
88 * @see org.eclipse.ui.IEditorInput#getPersistable()
91 public IPersistableElement
getPersistable() {
96 * @see org.eclipse.ui.IEditorInput#getToolTipText()
99 public String
getToolTipText() {
100 return query
.toString();
104 * @return the results
106 public List
<SpecimenOrObservationBase
> getResults() {
107 if(results
!=null && !results
.isEmpty()){
110 String errorMessage
= "Could not execute query " + query
;
112 InputStream resultStream
= new BioCaseQueryServiceWrapper().query(query
);
113 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
114 TransientCdmRepository repo
= new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
115 configurator
.setCdmAppController(repo
);
117 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
118 importer
.invoke(configurator
);
119 results
= repo
.getUnits();
120 // Abcd206Import abcd206Import = new Abcd206Import();
121 // Abcd206ImportState state = new Abcd206ImportState(configurator);
122 // abcd206Import.invoke(state);
123 // state.countTrees();
124 } catch (ClientProtocolException e
) {
125 logger
.error(errorMessage
, e
);
126 } catch (IOException e
) {
127 logger
.error(errorMessage
, e
);
128 } catch (URISyntaxException e
) {
129 logger
.error(errorMessage
, e
);
131 // return new BioCaseQueryServiceWrapper().dummyData();
136 * @see java.lang.Object#hashCode()
139 public int hashCode() {
140 final int prime
= 31;
142 result
= prime
* result
+ ((query
== null) ?
0 : query
.hashCode());
147 * @see java.lang.Object#equals(java.lang.Object)
150 public boolean equals(Object obj
) {
157 if (getClass() != obj
.getClass()) {
160 DerivedUnitEditorInput other
= (DerivedUnitEditorInput
) obj
;
162 if (other
.query
!= null) {
165 } else if (!query
.equals(other
.query
)) {