1
|
/**
|
2
|
* Copyright (C) 2013 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.view.checklist;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.jface.resource.ImageDescriptor;
|
17
|
import org.eclipse.ui.IEditorInput;
|
18
|
import org.eclipse.ui.IMemento;
|
19
|
import org.eclipse.ui.IPersistable;
|
20
|
import org.eclipse.ui.IPersistableElement;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
23
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
24
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
25
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
30
|
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
|
31
|
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
*
|
36
|
* @author a.oppermann
|
37
|
* @date 25.04.2014
|
38
|
*
|
39
|
*/
|
40
|
public class ChecklistEditorInput extends CdmEntitySessionInput implements IEditorInput, IPersistable {
|
41
|
|
42
|
/**
|
43
|
* The selected classification
|
44
|
*/
|
45
|
private TaxonNode taxonNode = null;
|
46
|
|
47
|
private List<Taxon> taxa = new ArrayList<Taxon>();
|
48
|
|
49
|
private Classification classification = null;
|
50
|
|
51
|
private final ConversationHolder conversation;
|
52
|
|
53
|
|
54
|
/**
|
55
|
* Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
|
56
|
* and its childNodes.
|
57
|
* @param taxonNode
|
58
|
*/
|
59
|
public ChecklistEditorInput(TaxonNode taxonNode){
|
60
|
super(false);
|
61
|
this.conversation = CdmStore.createConversation();
|
62
|
initSession();
|
63
|
this.taxonNode =CdmStore.getService(ITaxonNodeService.class).load(taxonNode.getUuid(), getTaxonNodePropertyPaths());
|
64
|
getChildTaxa(taxonNode);
|
65
|
classification = taxonNode.getClassification();
|
66
|
|
67
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
* @param taxonNode2
|
72
|
*/
|
73
|
private void getChildTaxa(TaxonNode taxonNode2) {
|
74
|
taxonNode2.removeNullValueFromChildren();
|
75
|
if (taxonNode2.hasChildNodes()){
|
76
|
for (TaxonNode node: taxonNode2.getChildNodes()){
|
77
|
node = CdmStore.getService(ITaxonNodeService.class).load(node.getUuid(), getTaxonNodePropertyPaths());
|
78
|
taxa.add(HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class));
|
79
|
getChildTaxa(node);
|
80
|
}
|
81
|
}
|
82
|
|
83
|
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Creates an editor input for the {@link ChecklistView} with the currently selected classification.
|
88
|
* @param classificationUuid
|
89
|
*/
|
90
|
public ChecklistEditorInput(Classification classification) {
|
91
|
super(true);
|
92
|
this.conversation = CdmStore.createConversation();
|
93
|
initSession();
|
94
|
this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
|
95
|
getChildTaxa(classification.getRootNode());
|
96
|
|
97
|
}
|
98
|
|
99
|
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
103
|
*/
|
104
|
@Override
|
105
|
public Object getAdapter(Class adapter) {
|
106
|
// TODO Auto-generated method stub
|
107
|
return null;
|
108
|
}
|
109
|
|
110
|
/* (non-Javadoc)
|
111
|
* @see org.eclipse.ui.IEditorInput#exists()
|
112
|
*/
|
113
|
@Override
|
114
|
public boolean exists() {
|
115
|
return false;
|
116
|
}
|
117
|
|
118
|
/* (non-Javadoc)
|
119
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
120
|
*/
|
121
|
@Override
|
122
|
public ImageDescriptor getImageDescriptor() {
|
123
|
// TODO Auto-generated method stub
|
124
|
return null;
|
125
|
}
|
126
|
|
127
|
public List<Taxon> getTaxa() {
|
128
|
return taxa;
|
129
|
}
|
130
|
|
131
|
/* (non-Javadoc)
|
132
|
* @see org.eclipse.ui.IEditorInput#getName()
|
133
|
*/
|
134
|
@Override
|
135
|
public String getName() {
|
136
|
if(taxonNode != null){
|
137
|
return taxonNode.getTaxon().getName().getTitleCache();
|
138
|
}else{
|
139
|
return classification.getTitleCache();
|
140
|
}
|
141
|
}
|
142
|
|
143
|
/* (non-Javadoc)
|
144
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
145
|
*/
|
146
|
@Override
|
147
|
public IPersistableElement getPersistable() {
|
148
|
return null;
|
149
|
}
|
150
|
|
151
|
/* (non-Javadoc)
|
152
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
153
|
*/
|
154
|
@Override
|
155
|
public String getToolTipText() {
|
156
|
return classification.getTitleCache();
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* @return the taxonNode
|
161
|
*/
|
162
|
public TaxonNode getTaxonNode() {
|
163
|
return taxonNode;
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* @return classification
|
168
|
*/
|
169
|
public Classification getClassification(){
|
170
|
return classification;
|
171
|
}
|
172
|
|
173
|
// /**
|
174
|
// * @return the conversationHolder
|
175
|
// */
|
176
|
// public ConversationHolder getConversationHolder() {
|
177
|
// return conversationHolder;
|
178
|
// }
|
179
|
|
180
|
|
181
|
|
182
|
/* (non-Javadoc)
|
183
|
* @see java.lang.Object#hashCode()
|
184
|
*/
|
185
|
@Override
|
186
|
public int hashCode() {
|
187
|
final int prime = 31;
|
188
|
int result = 1;
|
189
|
result = prime * result + ((classification == null) ? 0 : classification.hashCode());
|
190
|
result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
|
191
|
return result;
|
192
|
}
|
193
|
|
194
|
/* (non-Javadoc)
|
195
|
* @see java.lang.Object#equals(java.lang.Object)
|
196
|
*/
|
197
|
@Override
|
198
|
public boolean equals(Object obj) {
|
199
|
if (this == obj) {
|
200
|
return true;
|
201
|
}
|
202
|
if (obj == null) {
|
203
|
return false;
|
204
|
}
|
205
|
if (getClass() != obj.getClass()) {
|
206
|
return false;
|
207
|
}
|
208
|
ChecklistEditorInput other = (ChecklistEditorInput) obj;
|
209
|
if (classification == null) {
|
210
|
if (other.classification != null) {
|
211
|
return false;
|
212
|
}
|
213
|
} else if (!classification.equals(other.classification)) {
|
214
|
return false;
|
215
|
}
|
216
|
if (taxonNode == null) {
|
217
|
if (other.taxonNode != null) {
|
218
|
return false;
|
219
|
}
|
220
|
} else if (!taxonNode.equals(other.taxonNode)) {
|
221
|
return false;
|
222
|
}
|
223
|
return true;
|
224
|
}
|
225
|
|
226
|
/* (non-Javadoc)
|
227
|
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
|
228
|
*/
|
229
|
@Override
|
230
|
public void saveState(IMemento memento) {
|
231
|
UUID uuid = classification.getUuid();
|
232
|
}
|
233
|
|
234
|
@Override
|
235
|
public void merge() {
|
236
|
for (TaxonBase taxon:this.taxa){
|
237
|
CdmStore.getService(ITaxonService.class).merge(taxon, true);
|
238
|
}
|
239
|
|
240
|
|
241
|
}
|
242
|
|
243
|
/* (non-Javadoc)
|
244
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
245
|
*/
|
246
|
@Override
|
247
|
public List<TaxonNode> getRootEntities() {
|
248
|
return Arrays.asList(taxonNode);
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* @return the conversation
|
253
|
*/
|
254
|
public ConversationHolder getConversation() {
|
255
|
return conversation;
|
256
|
}
|
257
|
|
258
|
private List<String> getTaxonNodePropertyPaths() {
|
259
|
List<String> taxonNodePropertyPaths = new ArrayList<String>();
|
260
|
for(String propertyPath : getTaxonBasePropertyPaths()) {
|
261
|
taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
|
262
|
}
|
263
|
return taxonNodePropertyPaths;
|
264
|
}
|
265
|
|
266
|
private List<String> getTaxonBasePropertyPaths() {
|
267
|
List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
|
268
|
"sec", //$NON-NLS-1$
|
269
|
"createdBy", //$NON-NLS-1$
|
270
|
"updatedBy", //$NON-NLS-1$
|
271
|
"annotations", //$NON-NLS-1$
|
272
|
"markers", //$NON-NLS-1$
|
273
|
"credits", //$NON-NLS-1$
|
274
|
"extensions", //$NON-NLS-1$
|
275
|
"rights", //$NON-NLS-1$
|
276
|
"sources", //$NON-NLS-1$
|
277
|
"descriptions", //$NON-NLS-1$
|
278
|
"relationsToThisTaxon", //$NON-NLS-1$
|
279
|
"relationsFromThisTaxon", //$NON-NLS-1$
|
280
|
"taxonNodes", //$NON-NLS-1$
|
281
|
"descriptions.descriptionElements.feature", //$NON-NLS-1$
|
282
|
"descriptions.descriptionElements.area", //$NON-NLS-1$
|
283
|
"descriptions.descriptionElements.status", //$NON-NLS-1$
|
284
|
"descriptions.markers", //$NON-NLS-1$
|
285
|
"name.descriptions", //$NON-NLS-1$
|
286
|
"name.typeDesignations", //$NON-NLS-1$
|
287
|
"name.status", //$NON-NLS-1$
|
288
|
"name.nomenclaturalReference.inReference", //$NON-NLS-1$
|
289
|
"name.taxonBases.taxonNodes", //$NON-NLS-1$
|
290
|
"name.relationsFromThisName", //$NON-NLS-1$
|
291
|
"name.relationsToThisName", //$NON-NLS-1$
|
292
|
"name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status", //$NON-NLS-1$
|
293
|
"name.homotypicalGroup.typifiedNames.relationsToThisName.fromName", //$NON-NLS-1$
|
294
|
"synonymRelations.synonym.name.status.type", //$NON-NLS-1$
|
295
|
"synonymRelations.synonym.name.relationsToThisName.fromName", //$NON-NLS-1$
|
296
|
"synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship", //$NON-NLS-1$
|
297
|
"synonymRelations.synonym.name.nomenclaturalReference.authorship", //$NON-NLS-1$
|
298
|
"synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations" //$NON-NLS-1$
|
299
|
});
|
300
|
|
301
|
return taxonBasePropertyPaths;
|
302
|
}
|
303
|
|
304
|
|
305
|
public void setTaxa(List<Taxon> taxonList) {
|
306
|
this.taxa = taxonList;
|
307
|
|
308
|
}
|
309
|
|
310
|
// @Override
|
311
|
// public void dispose(){
|
312
|
// conversation.unbind();
|
313
|
// conversation.close();
|
314
|
// getCdmEntitySession().dispose();
|
315
|
// super.dispose();
|
316
|
// }
|
317
|
|
318
|
}
|