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
.Collection
;
17 import org
.apache
.http
.client
.ClientProtocolException
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.ui
.IEditorInput
;
22 import org
.eclipse
.ui
.IPersistableElement
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
25 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQuery
;
26 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQueryServiceWrapper
;
27 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
28 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
30 import eu
.etaxonomy
.taxeditor
.dataimport
.transientServices
.TransientCdmRepository
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 public class DerivedUnitEditorInput
implements IEditorInput
{
40 private static Logger logger
= Logger
.getLogger(DerivedUnitEditorInput
.class);
42 private final BioCaseQuery query
;
44 private Collection
<SpecimenOrObservationBase
> results
;
46 private final ConversationHolder conversationHolder
;
51 public DerivedUnitEditorInput(BioCaseQuery query
) {
52 this.conversationHolder
= CdmStore
.createConversation();
57 String errorMessage
= "Could not execute query " + DerivedUnitEditorInput
.this.query
;
59 InputStream resultStream
= new BioCaseQueryServiceWrapper().query(DerivedUnitEditorInput
.this.query
);
60 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
61 TransientCdmRepository repo
=
62 new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
63 configurator
.setCdmAppController(repo
);
65 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
66 importer
.invoke(configurator
);
67 results
= repo
.getUnits();
68 // Abcd206Import abcd206Import = new Abcd206Import();
69 // Abcd206ImportState state = new Abcd206ImportState(configurator);
70 // abcd206Import.invoke(state);
71 // state.countTrees();
72 } catch (ClientProtocolException e
) {
73 logger
.error(errorMessage
, e
);
74 } catch (IOException e
) {
75 logger
.error(errorMessage
, e
);
76 } catch (URISyntaxException e
) {
77 logger
.error(errorMessage
, e
);
80 Display
.getDefault().asyncExec(new Runnable() {
84 CdmStore
.getContextManager().notifyContextRefresh();
90 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
93 public Object
getAdapter(Class adapter
) {
94 // TODO Auto-generated method stub
99 * @see org.eclipse.ui.IEditorInput#exists()
102 public boolean exists() {
107 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
110 public ImageDescriptor
getImageDescriptor() {
111 // TODO Auto-generated method stub
116 * @see org.eclipse.ui.IEditorInput#getName()
119 public String
getName() {
120 return query
.toString();
124 * @see org.eclipse.ui.IEditorInput#getPersistable()
127 public IPersistableElement
getPersistable() {
132 * @see org.eclipse.ui.IEditorInput#getToolTipText()
135 public String
getToolTipText() {
136 return query
.toString();
140 * @return the results
142 public Collection
<SpecimenOrObservationBase
> getResults() {
147 * @return the conversationHolder
149 public ConversationHolder
getConversationHolder() {
150 return conversationHolder
;
154 * @see java.lang.Object#hashCode()
157 public int hashCode() {
158 final int prime
= 31;
160 result
= prime
* result
+ ((query
== null) ?
0 : query
.hashCode());
165 * @see java.lang.Object#equals(java.lang.Object)
168 public boolean equals(Object obj
) {
175 if (getClass() != obj
.getClass()) {
178 DerivedUnitEditorInput other
= (DerivedUnitEditorInput
) obj
;
180 if (other
.query
!= null) {
183 } else if (!query
.equals(other
.query
)) {