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
.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
;
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
.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
;
37 public class ChecklistEditorInput
extends CdmEntitySessionInput
implements IEditorInput
, IPersistable
{
40 * The selected classification
42 private TaxonNode taxonNode
= null;
44 private final List
<TaxonBase
> taxa
= new ArrayList
<TaxonBase
>();
46 private Classification classification
= null;
48 private final ConversationHolder conversation
;
52 * Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
56 public ChecklistEditorInput(TaxonNode taxonNode
){
58 this.conversation
= CdmStore
.createConversation();
59 this.taxonNode
=CdmStore
.getService(ITaxonNodeService
.class).load(taxonNode
.getUuid(), getTaxonNodePropertyPaths());
60 // getChildTaxa(taxonNode);
61 classification
= taxonNode
.getClassification();
69 private void getChildTaxa(TaxonNode taxonNode2
) {
70 taxonNode2
.removeNullValueFromChildren();
71 if (taxonNode2
.hasChildNodes()){
72 for (TaxonNode node
: taxonNode2
.getChildNodes()){
73 taxa
.add(node
.getTaxon());
82 * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
83 * @param classificationUuid
85 public ChecklistEditorInput(Classification classification
) {
87 this.conversation
= CdmStore
.createConversation();
88 this.classification
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().load(classification
.getUuid());
95 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
98 public Object
getAdapter(Class adapter
) {
99 // TODO Auto-generated method stub
104 * @see org.eclipse.ui.IEditorInput#exists()
107 public boolean exists() {
112 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
115 public ImageDescriptor
getImageDescriptor() {
116 // TODO Auto-generated method stub
121 * @see org.eclipse.ui.IEditorInput#getName()
124 public String
getName() {
125 if(taxonNode
!= null){
126 return taxonNode
.getTaxon().getName().getTitleCache();
128 return classification
.getTitleCache();
133 * @see org.eclipse.ui.IEditorInput#getPersistable()
136 public IPersistableElement
getPersistable() {
141 * @see org.eclipse.ui.IEditorInput#getToolTipText()
144 public String
getToolTipText() {
145 return classification
.getTitleCache();
149 * @return the taxonNode
151 public TaxonNode
getTaxonNode() {
156 * @return classification
158 public Classification
getClassification(){
159 return classification
;
163 // * @return the conversationHolder
165 // public ConversationHolder getConversationHolder() {
166 // return conversationHolder;
172 * @see java.lang.Object#hashCode()
175 public int hashCode() {
176 final int prime
= 31;
178 result
= prime
* result
+ ((classification
== null) ?
0 : classification
.hashCode());
179 result
= prime
* result
+ ((taxonNode
== null) ?
0 : taxonNode
.hashCode());
184 * @see java.lang.Object#equals(java.lang.Object)
187 public boolean equals(Object obj
) {
194 if (getClass() != obj
.getClass()) {
197 ChecklistEditorInput other
= (ChecklistEditorInput
) obj
;
198 if (classification
== null) {
199 if (other
.classification
!= null) {
202 } else if (!classification
.equals(other
.classification
)) {
205 if (taxonNode
== null) {
206 if (other
.taxonNode
!= null) {
209 } else if (!taxonNode
.equals(other
.taxonNode
)) {
216 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
219 public void saveState(IMemento memento
) {
220 UUID uuid
= classification
.getUuid();
224 public void merge() {
225 for (TaxonBase taxon
:taxa
){
226 CdmStore
.getService(ITaxonService
.class).merge(taxon
, true);
229 // CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
233 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
236 public List
<TaxonNode
> getRootEntities() {
237 return Arrays
.asList(taxonNode
);
241 * @return the conversation
243 public ConversationHolder
getConversation() {
247 private List
<String
> getTaxonNodePropertyPaths() {
248 List
<String
> taxonNodePropertyPaths
= new ArrayList
<String
>();
249 for(String propertyPath
: getTaxonBasePropertyPaths()) {
250 taxonNodePropertyPaths
.add("taxon." + propertyPath
);
252 return taxonNodePropertyPaths
;
255 private List
<String
> getTaxonBasePropertyPaths() {
256 List
<String
> taxonBasePropertyPaths
= Arrays
.asList(new String
[] {
267 "relationsToThisTaxon",
268 "relationsFromThisTaxon",
270 "descriptions.descriptionElements.feature",
271 "descriptions.descriptionElements.area",
272 "descriptions.descriptionElements.status",
273 "descriptions.markers",
275 "name.typeDesignations",
277 "name.nomenclaturalReference.inReference",
278 "name.taxonBases.taxonNodes",
279 "name.relationsFromThisName",
280 "name.relationsToThisName",
281 "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status",
282 "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName",
283 "synonymRelations.synonym.name.status.type",
284 "synonymRelations.synonym.name.relationsToThisName.fromName",
285 "synonymRelations.synonym.name.nomenclaturalReference.inReference.authorship",
286 "synonymRelations.synonym.name.nomenclaturalReference.authorship",
287 "synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations"
290 return taxonBasePropertyPaths
;
294 // public void dispose(){
295 // conversation.unbind();
296 // conversation.close();
297 // getCdmEntitySession().dispose();