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.ui.IMemento;
|
17
|
import org.eclipse.ui.IPersistable;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
20
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
21
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
26
|
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
/**
|
30
|
* @author a.oppermann
|
31
|
* @date 25.04.2014
|
32
|
*/
|
33
|
public class ChecklistEditorInput
|
34
|
extends CdmEntitySessionInput<TaxonNode>
|
35
|
implements IPersistable {
|
36
|
|
37
|
/**
|
38
|
* The selected classification
|
39
|
*/
|
40
|
private TaxonNode taxonNode = null;
|
41
|
|
42
|
private List<TaxonBase> taxa = new ArrayList<>();
|
43
|
|
44
|
private Classification classification = null;
|
45
|
|
46
|
private List<TaxonBase> taxaToSave = new ArrayList<>();
|
47
|
|
48
|
|
49
|
/**
|
50
|
* Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
|
51
|
* and its childNodes.
|
52
|
* @param taxonNode
|
53
|
*/
|
54
|
public ChecklistEditorInput(TaxonNode taxonNode){
|
55
|
super(false);
|
56
|
initSession();
|
57
|
this.taxonNode =CdmStore.getService(ITaxonNodeService.class).load(taxonNode.getUuid(), getTaxonNodePropertyPaths());
|
58
|
getChildTaxa(taxonNode);
|
59
|
classification = taxonNode.getClassification();
|
60
|
|
61
|
}
|
62
|
|
63
|
private void getChildTaxa(TaxonNode taxonNode2) {
|
64
|
// taxonNode2.removeNullValueFromChildren();
|
65
|
if (taxonNode2.hasChildNodes()){
|
66
|
for (TaxonNode node: taxonNode2.getChildNodes()){
|
67
|
node = CdmStore.getService(ITaxonNodeService.class).load(node.getUuid(), getTaxonNodePropertyPaths());
|
68
|
taxa.add(HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class));
|
69
|
getChildTaxa(node);
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Creates an editor input for the {@link ChecklistView} with the currently selected classification.
|
76
|
* @param classificationUuid
|
77
|
*/
|
78
|
public ChecklistEditorInput(Classification classification) {
|
79
|
super(true);
|
80
|
initSession();
|
81
|
this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
|
82
|
getChildTaxa(classification.getRootNode());
|
83
|
|
84
|
}
|
85
|
|
86
|
public List<TaxonBase> getTaxa() {
|
87
|
return taxa;
|
88
|
}
|
89
|
|
90
|
public String getName() {
|
91
|
if(taxonNode != null && taxonNode.getTaxon()!=null){
|
92
|
return taxonNode.getTaxon().getName().getTitleCache();
|
93
|
}else{
|
94
|
return classification.getTitleCache();
|
95
|
}
|
96
|
}
|
97
|
|
98
|
public TaxonNode getTaxonNode() {
|
99
|
return taxonNode;
|
100
|
}
|
101
|
|
102
|
public Classification getClassification(){
|
103
|
return classification;
|
104
|
}
|
105
|
|
106
|
@Override
|
107
|
public boolean equals(Object obj) {
|
108
|
if (this == obj) {
|
109
|
return true;
|
110
|
}
|
111
|
if (obj == null) {
|
112
|
return false;
|
113
|
}
|
114
|
if (getClass() != obj.getClass()) {
|
115
|
return false;
|
116
|
}
|
117
|
ChecklistEditorInput other = (ChecklistEditorInput) obj;
|
118
|
if (classification == null) {
|
119
|
if (other.classification != null) {
|
120
|
return false;
|
121
|
}
|
122
|
} else if (!classification.equals(other.classification)) {
|
123
|
return false;
|
124
|
}
|
125
|
if (taxonNode == null) {
|
126
|
if (other.taxonNode != null) {
|
127
|
return false;
|
128
|
}
|
129
|
} else if (!taxonNode.equals(other.taxonNode)) {
|
130
|
return false;
|
131
|
}
|
132
|
return true;
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public void saveState(IMemento memento) {
|
137
|
UUID uuid = classification.getUuid();
|
138
|
}
|
139
|
|
140
|
@Override
|
141
|
public void merge() {
|
142
|
if (!getCdmEntitySession().isActive()){
|
143
|
getCdmEntitySession().bind();
|
144
|
}
|
145
|
CdmStore.getService(ITaxonService.class).merge(taxaToSave, true);
|
146
|
}
|
147
|
|
148
|
@Override
|
149
|
public List<TaxonNode> getRootEntities() {
|
150
|
return Arrays.asList(taxonNode);
|
151
|
}
|
152
|
|
153
|
private List<String> getTaxonNodePropertyPaths() {
|
154
|
List<String> taxonNodePropertyPaths = new ArrayList<String>();
|
155
|
for(String propertyPath : getTaxonBasePropertyPaths()) {
|
156
|
taxonNodePropertyPaths.add("taxon." + propertyPath); //$NON-NLS-1$
|
157
|
}
|
158
|
return taxonNodePropertyPaths;
|
159
|
}
|
160
|
|
161
|
private List<String> getTaxonBasePropertyPaths() {
|
162
|
List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
|
163
|
"sec", //$NON-NLS-1$
|
164
|
"rights", //$NON-NLS-1$
|
165
|
"sources", //$NON-NLS-1$
|
166
|
"descriptions", //$NON-NLS-1$
|
167
|
"descriptions.descriptionElements.feature", //$NON-NLS-1$
|
168
|
"descriptions.descriptionElements.area", //$NON-NLS-1$
|
169
|
"descriptions.descriptionElements.status", //$NON-NLS-1$
|
170
|
"descriptions.markers", //$NON-NLS-1$
|
171
|
|
172
|
});
|
173
|
|
174
|
return taxonBasePropertyPaths;
|
175
|
}
|
176
|
|
177
|
public void setTaxa(List<TaxonBase> taxonList) {
|
178
|
this.taxa = taxonList;
|
179
|
|
180
|
}
|
181
|
|
182
|
/**
|
183
|
* @param element
|
184
|
*/
|
185
|
public void addTaxonToSave(Taxon element) {
|
186
|
this.taxaToSave.add(element);
|
187
|
|
188
|
}
|
189
|
|
190
|
// @Override
|
191
|
// public void dispose(){
|
192
|
// conversation.unbind();
|
193
|
// conversation.close();
|
194
|
// getCdmEntitySession().dispose();
|
195
|
// super.dispose();
|
196
|
// }
|
197
|
|
198
|
}
|