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
.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
.getCurrentApplicationConfiguration().getTaxonNodeService().load(taxonNode
.getUuid());
60 // getChildTaxa(taxonNode);
61 classification
= taxonNode
.getClassification();
67 private void getChildTaxa(TaxonNode taxonNode2
) {
68 taxonNode2
.removeNullValueFromChildren();
69 if (taxonNode2
.hasChildNodes()){
70 for (TaxonNode node
: taxonNode2
.getChildNodes()){
71 taxa
.add(node
.getTaxon());
80 * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
81 * @param classificationUuid
83 public ChecklistEditorInput(Classification classification
) {
85 this.conversation
= CdmStore
.createConversation();
86 this.classification
= CdmStore
.getCurrentApplicationConfiguration().getClassificationService().load(classification
.getUuid());
93 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
96 public Object
getAdapter(Class adapter
) {
97 // TODO Auto-generated method stub
102 * @see org.eclipse.ui.IEditorInput#exists()
105 public boolean exists() {
110 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
113 public ImageDescriptor
getImageDescriptor() {
114 // TODO Auto-generated method stub
119 * @see org.eclipse.ui.IEditorInput#getName()
122 public String
getName() {
123 if(taxonNode
!= null){
124 return taxonNode
.getTaxon().getName().getTitleCache();
126 return classification
.getTitleCache();
131 * @see org.eclipse.ui.IEditorInput#getPersistable()
134 public IPersistableElement
getPersistable() {
139 * @see org.eclipse.ui.IEditorInput#getToolTipText()
142 public String
getToolTipText() {
143 return classification
.getTitleCache();
147 * @return the taxonNode
149 public TaxonNode
getTaxonNode() {
154 * @return classification
156 public Classification
getClassification(){
157 return classification
;
161 // * @return the conversationHolder
163 // public ConversationHolder getConversationHolder() {
164 // return conversationHolder;
170 * @see java.lang.Object#hashCode()
173 public int hashCode() {
174 final int prime
= 31;
176 result
= prime
* result
+ ((classification
== null) ?
0 : classification
.hashCode());
177 result
= prime
* result
+ ((taxonNode
== null) ?
0 : taxonNode
.hashCode());
182 * @see java.lang.Object#equals(java.lang.Object)
185 public boolean equals(Object obj
) {
192 if (getClass() != obj
.getClass()) {
195 ChecklistEditorInput other
= (ChecklistEditorInput
) obj
;
196 if (classification
== null) {
197 if (other
.classification
!= null) {
200 } else if (!classification
.equals(other
.classification
)) {
203 if (taxonNode
== null) {
204 if (other
.taxonNode
!= null) {
207 } else if (!taxonNode
.equals(other
.taxonNode
)) {
214 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
217 public void saveState(IMemento memento
) {
218 UUID uuid
= classification
.getUuid();
222 public void merge() {
223 for (TaxonBase taxon
:taxa
){
224 CdmStore
.getService(ITaxonService
.class).merge(taxon
, true);
227 // CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
231 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
234 public List
<TaxonNode
> getRootEntities() {
235 return Arrays
.asList(taxonNode
);
239 * @return the conversation
241 public ConversationHolder
getConversation() {