1674cb69e6aa60532fe02966b36293f15530019e
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / dataimport / DerivedUnitEditorInput.java
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.dataimport;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.net.URISyntaxException;
15 import java.util.Collection;
16
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;
23
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;
32
33 /**
34 * @author pplitzner
35 * @date 20.09.2013
36 *
37 */
38 public class DerivedUnitEditorInput implements IEditorInput {
39
40 private static Logger logger = Logger.getLogger(DerivedUnitEditorInput.class);
41
42 private final BioCaseQuery query;
43
44 private Collection<SpecimenOrObservationBase> results;
45
46 private final ConversationHolder conversationHolder;
47
48 /**
49 * @param results
50 */
51 public DerivedUnitEditorInput(BioCaseQuery query) {
52 this.conversationHolder = CdmStore.createConversation();
53 this.query = query;
54 }
55
56 public void query(){
57 String errorMessage = "Could not execute query " + DerivedUnitEditorInput.this.query;
58 try {
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);
64
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);
78 }
79
80 Display.getDefault().asyncExec(new Runnable() {
81
82 @Override
83 public void run() {
84 CdmStore.getContextManager().notifyContextRefresh();
85 }
86 });
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
91 */
92 @Override
93 public Object getAdapter(Class adapter) {
94 // TODO Auto-generated method stub
95 return null;
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.ui.IEditorInput#exists()
100 */
101 @Override
102 public boolean exists() {
103 return false;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
108 */
109 @Override
110 public ImageDescriptor getImageDescriptor() {
111 // TODO Auto-generated method stub
112 return null;
113 }
114
115 /* (non-Javadoc)
116 * @see org.eclipse.ui.IEditorInput#getName()
117 */
118 @Override
119 public String getName() {
120 return query.toString();
121 }
122
123 /* (non-Javadoc)
124 * @see org.eclipse.ui.IEditorInput#getPersistable()
125 */
126 @Override
127 public IPersistableElement getPersistable() {
128 return null;
129 }
130
131 /* (non-Javadoc)
132 * @see org.eclipse.ui.IEditorInput#getToolTipText()
133 */
134 @Override
135 public String getToolTipText() {
136 return query.toString();
137 }
138
139 /**
140 * @return the results
141 */
142 public Collection<SpecimenOrObservationBase> getResults() {
143 return results;
144 }
145
146 /**
147 * @return the conversationHolder
148 */
149 public ConversationHolder getConversationHolder() {
150 return conversationHolder;
151 }
152
153 /* (non-Javadoc)
154 * @see java.lang.Object#hashCode()
155 */
156 @Override
157 public int hashCode() {
158 final int prime = 31;
159 int result = 1;
160 result = prime * result + ((query == null) ? 0 : query.hashCode());
161 return result;
162 }
163
164 /* (non-Javadoc)
165 * @see java.lang.Object#equals(java.lang.Object)
166 */
167 @Override
168 public boolean equals(Object obj) {
169 if (this == obj) {
170 return true;
171 }
172 if (obj == null) {
173 return false;
174 }
175 if (getClass() != obj.getClass()) {
176 return false;
177 }
178 DerivedUnitEditorInput other = (DerivedUnitEditorInput) obj;
179 if (query == null) {
180 if (other.query != null) {
181 return false;
182 }
183 } else if (!query.equals(other.query)) {
184 return false;
185 }
186 return true;
187 }
188
189 }