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.editor.view.checklist;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.eclipse.jface.resource.ImageDescriptor;
|
18
|
import org.eclipse.ui.IEditorInput;
|
19
|
import org.eclipse.ui.IMemento;
|
20
|
import org.eclipse.ui.IPersistable;
|
21
|
import org.eclipse.ui.IPersistableElement;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
24
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
25
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
26
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
28
|
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
|
29
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
* @author a.oppermann
|
34
|
* @date 25.04.2014
|
35
|
*
|
36
|
*/
|
37
|
public class ChecklistEditorInput extends CdmEntitySessionInput implements IEditorInput, IPersistable {
|
38
|
|
39
|
/**
|
40
|
* The selected classification
|
41
|
*/
|
42
|
private TaxonNode taxonNode = null;
|
43
|
|
44
|
private final List<TaxonBase> taxa = new ArrayList<TaxonBase>();
|
45
|
|
46
|
private Classification classification = null;
|
47
|
|
48
|
private final ConversationHolder conversation;
|
49
|
|
50
|
|
51
|
/**
|
52
|
* Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
|
53
|
* and its childNodes.
|
54
|
* @param taxonNode
|
55
|
*/
|
56
|
public ChecklistEditorInput(TaxonNode taxonNode){
|
57
|
super(true);
|
58
|
this.conversation = CdmStore.createConversation();
|
59
|
this.taxonNode = CdmStore.getCurrentApplicationConfiguration().getTaxonNodeService().load(taxonNode.getUuid());
|
60
|
// getChildTaxa(taxonNode);
|
61
|
classification = taxonNode.getClassification();
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* @param taxonNode2
|
66
|
*/
|
67
|
private void getChildTaxa(TaxonNode taxonNode2) {
|
68
|
taxonNode2.removeNullValueFromChildren();
|
69
|
if (taxonNode2.hasChildNodes()){
|
70
|
for (TaxonNode node: taxonNode2.getChildNodes()){
|
71
|
taxa.add(node.getTaxon());
|
72
|
getChildTaxa(node);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Creates an editor input for the {@link ChecklistView} with the currently selected classification.
|
81
|
* @param classificationUuid
|
82
|
*/
|
83
|
public ChecklistEditorInput(Classification classification) {
|
84
|
super(true);
|
85
|
this.conversation = CdmStore.createConversation();
|
86
|
this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
|
87
|
|
88
|
}
|
89
|
|
90
|
|
91
|
|
92
|
/* (non-Javadoc)
|
93
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
94
|
*/
|
95
|
@Override
|
96
|
public Object getAdapter(Class adapter) {
|
97
|
// TODO Auto-generated method stub
|
98
|
return null;
|
99
|
}
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.ui.IEditorInput#exists()
|
103
|
*/
|
104
|
@Override
|
105
|
public boolean exists() {
|
106
|
return false;
|
107
|
}
|
108
|
|
109
|
/* (non-Javadoc)
|
110
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
111
|
*/
|
112
|
@Override
|
113
|
public ImageDescriptor getImageDescriptor() {
|
114
|
// TODO Auto-generated method stub
|
115
|
return null;
|
116
|
}
|
117
|
|
118
|
/* (non-Javadoc)
|
119
|
* @see org.eclipse.ui.IEditorInput#getName()
|
120
|
*/
|
121
|
@Override
|
122
|
public String getName() {
|
123
|
if(taxonNode != null){
|
124
|
return taxonNode.getTaxon().getName().getTitleCache();
|
125
|
}else{
|
126
|
return classification.getTitleCache();
|
127
|
}
|
128
|
}
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
132
|
*/
|
133
|
@Override
|
134
|
public IPersistableElement getPersistable() {
|
135
|
return null;
|
136
|
}
|
137
|
|
138
|
/* (non-Javadoc)
|
139
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
140
|
*/
|
141
|
@Override
|
142
|
public String getToolTipText() {
|
143
|
return classification.getTitleCache();
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* @return the taxonNode
|
148
|
*/
|
149
|
public TaxonNode getTaxonNode() {
|
150
|
return taxonNode;
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* @return classification
|
155
|
*/
|
156
|
public Classification getClassification(){
|
157
|
return classification;
|
158
|
}
|
159
|
|
160
|
// /**
|
161
|
// * @return the conversationHolder
|
162
|
// */
|
163
|
// public ConversationHolder getConversationHolder() {
|
164
|
// return conversationHolder;
|
165
|
// }
|
166
|
|
167
|
|
168
|
|
169
|
/* (non-Javadoc)
|
170
|
* @see java.lang.Object#hashCode()
|
171
|
*/
|
172
|
@Override
|
173
|
public int hashCode() {
|
174
|
final int prime = 31;
|
175
|
int result = 1;
|
176
|
result = prime * result + ((classification == null) ? 0 : classification.hashCode());
|
177
|
result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
|
178
|
return result;
|
179
|
}
|
180
|
|
181
|
/* (non-Javadoc)
|
182
|
* @see java.lang.Object#equals(java.lang.Object)
|
183
|
*/
|
184
|
@Override
|
185
|
public boolean equals(Object obj) {
|
186
|
if (this == obj) {
|
187
|
return true;
|
188
|
}
|
189
|
if (obj == null) {
|
190
|
return false;
|
191
|
}
|
192
|
if (getClass() != obj.getClass()) {
|
193
|
return false;
|
194
|
}
|
195
|
ChecklistEditorInput other = (ChecklistEditorInput) obj;
|
196
|
if (classification == null) {
|
197
|
if (other.classification != null) {
|
198
|
return false;
|
199
|
}
|
200
|
} else if (!classification.equals(other.classification)) {
|
201
|
return false;
|
202
|
}
|
203
|
if (taxonNode == null) {
|
204
|
if (other.taxonNode != null) {
|
205
|
return false;
|
206
|
}
|
207
|
} else if (!taxonNode.equals(other.taxonNode)) {
|
208
|
return false;
|
209
|
}
|
210
|
return true;
|
211
|
}
|
212
|
|
213
|
/* (non-Javadoc)
|
214
|
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
|
215
|
*/
|
216
|
@Override
|
217
|
public void saveState(IMemento memento) {
|
218
|
UUID uuid = classification.getUuid();
|
219
|
}
|
220
|
|
221
|
@Override
|
222
|
public void merge() {
|
223
|
for (TaxonBase taxon:taxa){
|
224
|
CdmStore.getService(ITaxonService.class).merge(taxon, true);
|
225
|
}
|
226
|
|
227
|
// CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
|
228
|
}
|
229
|
|
230
|
/* (non-Javadoc)
|
231
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
232
|
*/
|
233
|
@Override
|
234
|
public List<TaxonNode> getRootEntities() {
|
235
|
return Arrays.asList(taxonNode);
|
236
|
}
|
237
|
|
238
|
/**
|
239
|
* @return the conversation
|
240
|
*/
|
241
|
public ConversationHolder getConversation() {
|
242
|
return conversation;
|
243
|
}
|
244
|
|
245
|
}
|