2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.ui
.IMemento
;
17 import org
.eclipse
.ui
.IPersistable
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
22 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class ChecklistEditorInput
extends CdmEntitySessionInput
implements IPersistable
{
39 * The selected classification
41 private TaxonNode taxonNode
= null;
43 private List
<TaxonBase
> taxa
= new ArrayList();
45 private Classification classification
= null;
47 private final ConversationHolder conversation
;
49 private List
<TaxonBase
> taxaToSave
= new ArrayList();
53 * Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
57 public ChecklistEditorInput(TaxonNode taxonNode
){
59 this.conversation
= CdmStore
.createConversation();
61 this.taxonNode
=CdmStore
.getService(ITaxonNodeService
.class).load(taxonNode
.getUuid(), getTaxonNodePropertyPaths());
62 getChildTaxa(taxonNode
);
63 classification
= taxonNode
.getClassification();
71 private void getChildTaxa(TaxonNode taxonNode2
) {
72 taxonNode2
.removeNullValueFromChildren();
73 if (taxonNode2
.hasChildNodes()){
74 for (TaxonNode node
: taxonNode2
.getChildNodes()){
75 node
= CdmStore
.getService(ITaxonNodeService
.class).load(node
.getUuid(), getTaxonNodePropertyPaths());
76 taxa
.add(HibernateProxyHelper
.deproxy(node
.getTaxon(), Taxon
.class));
85 * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
86 * @param classificationUuid
88 public ChecklistEditorInput(Classification classification
) {
90 this.conversation
= CdmStore
.createConversation();
92 this.classification
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().load(classification
.getUuid());
93 getChildTaxa(classification
.getRootNode());
99 public List
<TaxonBase
> getTaxa() {
103 public String
getName() {
104 if(taxonNode
!= null && taxonNode
.getTaxon()!=null){
105 return taxonNode
.getTaxon().getName().getTitleCache();
107 return classification
.getTitleCache();
113 * @return the taxonNode
115 public TaxonNode
getTaxonNode() {
120 * @return classification
122 public Classification
getClassification(){
123 return classification
;
127 // * @return the conversationHolder
129 // public ConversationHolder getConversationHolder() {
130 // return conversationHolder;
136 // * @see java.lang.Object#hashCode()
139 // public int hashCode() {
140 // final int prime = 31;
142 // result = prime * result + ((classification == null) ? 0 : classification.hashCode());
143 // result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
148 * @see java.lang.Object#equals(java.lang.Object)
151 public boolean equals(Object obj
) {
158 if (getClass() != obj
.getClass()) {
161 ChecklistEditorInput other
= (ChecklistEditorInput
) obj
;
162 if (classification
== null) {
163 if (other
.classification
!= null) {
166 } else if (!classification
.equals(other
.classification
)) {
169 if (taxonNode
== null) {
170 if (other
.taxonNode
!= null) {
173 } else if (!taxonNode
.equals(other
.taxonNode
)) {
180 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
183 public void saveState(IMemento memento
) {
184 UUID uuid
= classification
.getUuid();
188 public void merge() {
189 if (!getCdmEntitySession().isActive()){
190 getCdmEntitySession().bind();
192 CdmStore
.getService(ITaxonService
.class).merge(taxaToSave
, true);
196 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
199 public List
<TaxonNode
> getRootEntities() {
200 return Arrays
.asList(taxonNode
);
204 * @return the conversation
206 public ConversationHolder
getConversation() {
210 private List
<String
> getTaxonNodePropertyPaths() {
211 List
<String
> taxonNodePropertyPaths
= new ArrayList
<String
>();
212 for(String propertyPath
: getTaxonBasePropertyPaths()) {
213 taxonNodePropertyPaths
.add("taxon." + propertyPath
); //$NON-NLS-1$
215 return taxonNodePropertyPaths
;
218 private List
<String
> getTaxonBasePropertyPaths() {
219 List
<String
> taxonBasePropertyPaths
= Arrays
.asList(new String
[] {
221 "createdBy", //$NON-NLS-1$
222 "updatedBy", //$NON-NLS-1$
223 "annotations", //$NON-NLS-1$
224 "markers", //$NON-NLS-1$
225 "credits", //$NON-NLS-1$
226 "extensions", //$NON-NLS-1$
227 "rights", //$NON-NLS-1$
228 "sources", //$NON-NLS-1$
229 "descriptions", //$NON-NLS-1$
230 "relationsToThisTaxon", //$NON-NLS-1$
231 "relationsFromThisTaxon", //$NON-NLS-1$
232 "taxonNodes", //$NON-NLS-1$
233 "descriptions.descriptionElements.feature", //$NON-NLS-1$
234 "descriptions.descriptionElements.area", //$NON-NLS-1$
235 "descriptions.descriptionElements.status", //$NON-NLS-1$
236 "descriptions.markers", //$NON-NLS-1$
237 "name.descriptions", //$NON-NLS-1$
238 "name.typeDesignations", //$NON-NLS-1$
239 "name.status", //$NON-NLS-1$
240 "name.nomenclaturalReference.inReference", //$NON-NLS-1$
241 "name.taxonBases.taxonNodes", //$NON-NLS-1$
242 "name.relationsFromThisName", //$NON-NLS-1$
243 "name.relationsToThisName", //$NON-NLS-1$
244 "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status", //$NON-NLS-1$
245 "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName", //$NON-NLS-1$
246 "synonymRelations.synonym.name.status.type", //$NON-NLS-1$
247 "synonymRelations.synonym.name.relationsToThisName.fromName", //$NON-NLS-1$
248 "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship", //$NON-NLS-1$
249 "synonymRelations.synonym.name.nomenclaturalReference.authorship", //$NON-NLS-1$
250 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations" //$NON-NLS-1$
253 return taxonBasePropertyPaths
;
257 public void setTaxa(List
<TaxonBase
> taxonList
) {
258 this.taxa
= taxonList
;
266 public void addTaxonToSave(Taxon element
) {
267 this.taxaToSave
.add(element
);
272 // public void dispose(){
273 // conversation.unbind();
274 // conversation.close();
275 // getCdmEntitySession().dispose();