3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
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
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
29 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 public class ChecklistEditorInput
extends CdmEntitySessionInput
implements IEditorInput
, IPersistable
{
41 * The selected classification
43 private TaxonNode taxonNode
= null;
45 private final List
<TaxonBase
> taxa
= new ArrayList
<TaxonBase
>();
47 private Classification classification
= null;
49 private final ConversationHolder conversation
;
53 * Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
57 public ChecklistEditorInput(TaxonNode taxonNode
){
59 this.conversation
= CdmStore
.createConversation();
60 this.taxonNode
=CdmStore
.getService(ITaxonNodeService
.class).load(taxonNode
.getUuid(), getTaxonNodePropertyPaths());
61 // getChildTaxa(taxonNode);
62 classification
= taxonNode
.getClassification();
70 private void getChildTaxa(TaxonNode taxonNode2
) {
71 taxonNode2
.removeNullValueFromChildren();
72 if (taxonNode2
.hasChildNodes()){
73 for (TaxonNode node
: taxonNode2
.getChildNodes()){
74 taxa
.add(node
.getTaxon());
83 * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
84 * @param classificationUuid
86 public ChecklistEditorInput(Classification classification
) {
88 this.conversation
= CdmStore
.createConversation();
89 this.classification
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().load(classification
.getUuid());
96 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
99 public Object
getAdapter(Class adapter
) {
100 // TODO Auto-generated method stub
105 * @see org.eclipse.ui.IEditorInput#exists()
108 public boolean exists() {
113 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
116 public ImageDescriptor
getImageDescriptor() {
117 // TODO Auto-generated method stub
122 * @see org.eclipse.ui.IEditorInput#getName()
125 public String
getName() {
126 if(taxonNode
!= null){
127 return taxonNode
.getTaxon().getName().getTitleCache();
129 return classification
.getTitleCache();
134 * @see org.eclipse.ui.IEditorInput#getPersistable()
137 public IPersistableElement
getPersistable() {
142 * @see org.eclipse.ui.IEditorInput#getToolTipText()
145 public String
getToolTipText() {
146 return classification
.getTitleCache();
150 * @return the taxonNode
152 public TaxonNode
getTaxonNode() {
157 * @return classification
159 public Classification
getClassification(){
160 return classification
;
164 // * @return the conversationHolder
166 // public ConversationHolder getConversationHolder() {
167 // return conversationHolder;
173 * @see java.lang.Object#hashCode()
176 public int hashCode() {
177 final int prime
= 31;
179 result
= prime
* result
+ ((classification
== null) ?
0 : classification
.hashCode());
180 result
= prime
* result
+ ((taxonNode
== null) ?
0 : taxonNode
.hashCode());
185 * @see java.lang.Object#equals(java.lang.Object)
188 public boolean equals(Object obj
) {
195 if (getClass() != obj
.getClass()) {
198 ChecklistEditorInput other
= (ChecklistEditorInput
) obj
;
199 if (classification
== null) {
200 if (other
.classification
!= null) {
203 } else if (!classification
.equals(other
.classification
)) {
206 if (taxonNode
== null) {
207 if (other
.taxonNode
!= null) {
210 } else if (!taxonNode
.equals(other
.taxonNode
)) {
217 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
220 public void saveState(IMemento memento
) {
221 UUID uuid
= classification
.getUuid();
225 public void merge() {
226 for (TaxonBase taxon
:taxa
){
227 CdmStore
.getService(ITaxonService
.class).merge(taxon
, true);
230 // CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
234 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
237 public List
<TaxonNode
> getRootEntities() {
238 return Arrays
.asList(taxonNode
);
242 * @return the conversation
244 public ConversationHolder
getConversation() {
248 private List
<String
> getTaxonNodePropertyPaths() {
249 List
<String
> taxonNodePropertyPaths
= new ArrayList
<String
>();
250 for(String propertyPath
: getTaxonBasePropertyPaths()) {
251 taxonNodePropertyPaths
.add("taxon." + propertyPath
);
253 return taxonNodePropertyPaths
;
256 private List
<String
> getTaxonBasePropertyPaths() {
257 List
<String
> taxonBasePropertyPaths
= Arrays
.asList(new String
[] {
268 "relationsToThisTaxon",
269 "relationsFromThisTaxon",
271 "descriptions.descriptionElements.feature",
272 "descriptions.descriptionElements.area",
273 "descriptions.descriptionElements.status",
274 "descriptions.markers",
276 "name.typeDesignations",
278 "name.nomenclaturalReference.inReference",
279 "name.taxonBases.taxonNodes",
280 "name.relationsFromThisName",
281 "name.relationsToThisName",
282 "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status",
283 "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName",
284 "synonymRelations.synonym.name.status.type",
285 "synonymRelations.synonym.name.relationsToThisName.fromName",
286 "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship",
287 "synonymRelations.synonym.name.nomenclaturalReference.authorship",
288 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations"
291 return taxonBasePropertyPaths
;
295 // public void dispose(){
296 // conversation.unbind();
297 // conversation.close();
298 // getCdmEntitySession().dispose();