2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.taxeditor
.editor
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
16 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IMemento
;
19 import org
.eclipse
.ui
.IPersistableElement
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
27 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 public class TaxonEditorInput
implements IEditorInput
, IConversationEnabled
, IPersistableElement
{
36 private static final Logger logger
= Logger
37 .getLogger(TaxonEditorInput
.class);
39 private ConversationHolder conversation
;
41 private TaxonNode taxonNode
;
43 private TaxonEditorInput(TaxonNode taxonNode
, ConversationHolder conversation
){
44 this.taxonNode
= taxonNode
;
45 this.conversation
= conversation
;
54 public static TaxonEditorInput
NewInstance(UUID uuid
){
55 ConversationHolder conversation
= CdmStore
.NewTransactionalConversation();
57 TaxonNode taxonNode
= CdmStore
.getTaxonService().getTaxonNodeByUuid(uuid
);
59 if(taxonNode
== null){
60 MessageDialog
.openWarning(EditorUtil
.getShell(), "Not yet implemented", "Selected element is not if type TaxonBase.");
66 // FIXME had to disable synonym handling for now while implementing taxonNode
67 // if (taxonBase instanceof Synonym) {
68 // // TODO: in case of pro parte synonym or any other where we might have multiple
69 // // accepted taxa we have to provide a mechanism that can deal with that
70 // // TODO set focus to the synonym
71 // Set<Taxon> acceptedTaxa = ((Synonym) taxonBase).getAcceptedTaxa();
72 // if(acceptedTaxa.size() != 1){
74 // if(acceptedTaxa.size() == 0){
75 // message = "There is no accepted taxon for the chosen synonym. ";
77 // message = "Multiple taxa found for the chosen synonym.";
79 // MessageDialog.openWarning(EditorUtil.getShell(), "Not yet implemented", message);
82 // taxon = acceptedTaxa.toArray(new Taxon[0])[0];
85 // taxon = (Taxon) taxonBase;
89 logger
.trace(TaxonEditorInput
.class.getSimpleName() + " created");
91 return new TaxonEditorInput(taxonNode
, conversation
);
94 public static TaxonEditorInput
NewEmptyInstance(UUID parentTaxonNodeUuid
){
95 ConversationHolder conversation
= CdmStore
.NewTransactionalConversation();
97 TaxonNameBase
<?
, ?
> name
= PreferencesUtil
.getInstanceOfPreferredNameClass();
99 Taxon newTaxon
= null;
100 TaxonNode newTaxonNode
= null;
102 // FIXME adding of root taxon nodes disabled for now. Still have to find a way to
103 // which taxonomic tree the node shoul dbe added
104 // if(parentTaxonNodeUuid == null){
105 // newTaxon = Taxon.NewInstance(name, CdmStore.getDefault().getDefaultSec());
106 // newTaxonNode = new TaxonNode();
108 TaxonNode parentTaxonNode
= CdmStore
.getTaxonService().getTaxonNodeByUuid(parentTaxonNodeUuid
);
110 newTaxon
= Taxon
.NewInstance(name
, parentTaxonNode
.getTaxon().getSec());
112 newTaxonNode
= parentTaxonNode
.addChild(newTaxon
, parentTaxonNode
.getReferenceForParentChildRelation(), parentTaxonNode
.getMicroReferenceForParentChildRelation());
114 // add the new taxon to the editors persistence context
115 CdmStore
.getTaxonService().saveTaxonNode(newTaxonNode
);
117 return new TaxonEditorInput(newTaxonNode
, conversation
);
121 * @see org.eclipse.ui.IEditorInput#exists()
123 public boolean exists() {
124 return taxonNode
!= null;
128 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
130 public ImageDescriptor
getImageDescriptor() {
135 * @see org.eclipse.ui.IEditorInput#getName()
137 public String
getName() {
138 TaxonNameBase
<?
, ?
> name
= getTaxon().getName();
139 if (name
== null || name
.getTitleCache() == null) {
142 return name
.getTitleCache();
147 * @see org.eclipse.ui.IEditorInput#getPersistable()
149 public IPersistableElement
getPersistable() {
154 * @see org.eclipse.ui.IEditorInput#getToolTipText()
156 public String
getToolTipText() {
161 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
163 public Object
getAdapter(Class adapter
) {
165 if (adapter
== Taxon
.class) {
166 return taxonNode
.getTaxon();
169 if (adapter
== TaxonNode
.class) {
177 * Overrides equals to ensure that a taxon can only be edited by
178 * one editor at a time.
182 public boolean equals(Object obj
) {
183 if (obj
.getClass().equals(TaxonEditorInput
.class)
184 && getTaxon().equals(((TaxonEditorInput
) obj
).getTaxon()))
192 public Taxon
getTaxon(){
193 return taxonNode
.getTaxon();
197 * @return the taxonNode
199 public TaxonNode
getTaxonNode() {
205 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
207 public ConversationHolder
getConversationHolder() {
213 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
215 public void update(CdmDataChangeMap events
) {
216 // FIXME update the editor input
220 * @see org.eclipse.ui.IPersistableElement#getFactoryId()
222 public String
getFactoryId() {
223 return TaxonEditorInputFactory
.getFactoryId();
227 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
229 public void saveState(IMemento memento
) {
230 TaxonEditorInputFactory
.saveState(memento
, this);