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.net.URISyntaxException;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.apache.http.client.ClientProtocolException;
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.eclipse.jface.resource.ImageDescriptor;
|
19
|
import org.eclipse.ui.IEditorInput;
|
20
|
import org.eclipse.ui.IPersistableElement;
|
21
|
|
22
|
import eu.etaxonomy.cdm.ext.biocase.BioCaseQuery;
|
23
|
import eu.etaxonomy.cdm.ext.biocase.BioCaseQueryServiceWrapper;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
25
|
|
26
|
/**
|
27
|
* @author pplitzner
|
28
|
* @date 20.09.2013
|
29
|
*
|
30
|
*/
|
31
|
public class DataImportSpecimenEditorInput implements IEditorInput {
|
32
|
|
33
|
private static Logger logger = Logger.getLogger(DataImportSpecimenEditorInput.class);
|
34
|
|
35
|
private List<SpecimenOrObservationBase> results;
|
36
|
private BioCaseQuery query;
|
37
|
|
38
|
/**
|
39
|
* @param results
|
40
|
*/
|
41
|
public DataImportSpecimenEditorInput(BioCaseQuery query) {
|
42
|
this.query = query;
|
43
|
}
|
44
|
|
45
|
/* (non-Javadoc)
|
46
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
47
|
*/
|
48
|
@Override
|
49
|
public Object getAdapter(Class adapter) {
|
50
|
// TODO Auto-generated method stub
|
51
|
return null;
|
52
|
}
|
53
|
|
54
|
/* (non-Javadoc)
|
55
|
* @see org.eclipse.ui.IEditorInput#exists()
|
56
|
*/
|
57
|
@Override
|
58
|
public boolean exists() {
|
59
|
return false;
|
60
|
}
|
61
|
|
62
|
/* (non-Javadoc)
|
63
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
64
|
*/
|
65
|
@Override
|
66
|
public ImageDescriptor getImageDescriptor() {
|
67
|
// TODO Auto-generated method stub
|
68
|
return null;
|
69
|
}
|
70
|
|
71
|
/* (non-Javadoc)
|
72
|
* @see org.eclipse.ui.IEditorInput#getName()
|
73
|
*/
|
74
|
@Override
|
75
|
public String getName() {
|
76
|
return query.toString();
|
77
|
}
|
78
|
|
79
|
/* (non-Javadoc)
|
80
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
81
|
*/
|
82
|
@Override
|
83
|
public IPersistableElement getPersistable() {
|
84
|
return null;
|
85
|
}
|
86
|
|
87
|
/* (non-Javadoc)
|
88
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
89
|
*/
|
90
|
@Override
|
91
|
public String getToolTipText() {
|
92
|
return query.toString();
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* @return the results
|
97
|
*/
|
98
|
public List<SpecimenOrObservationBase> getResults() {
|
99
|
String errorMessage = "Could not execute query " + query;
|
100
|
try {
|
101
|
return new BioCaseQueryServiceWrapper().query(query);
|
102
|
} catch (ClientProtocolException e) {
|
103
|
logger.error(errorMessage, e);
|
104
|
} catch (IOException e) {
|
105
|
logger.error(errorMessage, e);
|
106
|
} catch (URISyntaxException e) {
|
107
|
logger.error(errorMessage, e);
|
108
|
}
|
109
|
return null;
|
110
|
}
|
111
|
|
112
|
/* (non-Javadoc)
|
113
|
* @see java.lang.Object#hashCode()
|
114
|
*/
|
115
|
@Override
|
116
|
public int hashCode() {
|
117
|
final int prime = 31;
|
118
|
int result = 1;
|
119
|
result = prime * result + ((query == null) ? 0 : query.hashCode());
|
120
|
return result;
|
121
|
}
|
122
|
|
123
|
/* (non-Javadoc)
|
124
|
* @see java.lang.Object#equals(java.lang.Object)
|
125
|
*/
|
126
|
@Override
|
127
|
public boolean equals(Object obj) {
|
128
|
if (this == obj) {
|
129
|
return true;
|
130
|
}
|
131
|
if (obj == null) {
|
132
|
return false;
|
133
|
}
|
134
|
if (getClass() != obj.getClass()) {
|
135
|
return false;
|
136
|
}
|
137
|
DataImportSpecimenEditorInput other = (DataImportSpecimenEditorInput) obj;
|
138
|
if (query == null) {
|
139
|
if (other.query != null) {
|
140
|
return false;
|
141
|
}
|
142
|
} else if (!query.equals(other.query)) {
|
143
|
return false;
|
144
|
}
|
145
|
if (results == null) {
|
146
|
if (other.results != null) {
|
147
|
return false;
|
148
|
}
|
149
|
}
|
150
|
return true;
|
151
|
}
|
152
|
|
153
|
}
|