had to rename the packages to make them compliant with buckminster
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / TaxonEditorInput.java
diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java
deleted file mode 100644 (file)
index 78bd8d3..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.editor;
-
-import java.util.UUID;
-
-import org.apache.log4j.Logger;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IPersistableElement;
-
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.taxon.ITreeNode;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-/**
- * @author n.hoffmann
- * @created 19.03.2009
- * @version 1.0
- */
-public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPersistableElement {
-       private static final Logger logger = Logger
-                       .getLogger(TaxonEditorInput.class);
-
-       private ConversationHolder conversation;
-
-       private TaxonNode taxonNode;
-       
-       private TaxonEditorInput(TaxonNode taxonNode, ConversationHolder conversation){
-               this.taxonNode = taxonNode;
-               this.conversation = conversation;
-       }
-       
-    /**
-     * 
-     * @param taxonNodeUuid
-     * @param conversation
-     * @return
-     */
-    public static TaxonEditorInput NewInstance(UUID taxonNodeUuid){
-       ConversationHolder conversation = CdmStore.NewTransactionalConversation();
-       
-       TaxonNode taxonNode = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNodeUuid);
-               
-               if(taxonNode == null){
-                       MessageDialog.openWarning(EditorUtil.getShell(), "Not yet implemented", "Selected element is not type TaxonBase.");
-                       return null;
-               }
-               
-               // FIXME had to disable synonym handling for now while implementing taxonNode
-//             if (taxonBase instanceof Synonym) {
-//                     // TODO: in case of pro parte synonym or any other where we might have multiple
-//                     // accepted taxa we have to provide a mechanism that can deal with that
-//                     // TODO set focus to the synonym
-//                     Set<Taxon> acceptedTaxa = ((Synonym) taxonBase).getAcceptedTaxa();
-//                     if(acceptedTaxa.size() != 1){
-//                             String message;
-//                             if(acceptedTaxa.size() == 0){
-//                                     message = "There is no accepted taxon for the chosen synonym. ";
-//                             }else{
-//                                     message = "Multiple taxa found for the chosen synonym.";
-//                             }
-//                             MessageDialog.openWarning(EditorUtil.getShell(), "Not yet implemented", message);
-//                             return null;
-//                     }else{
-//                             taxon = acceptedTaxa.toArray(new Taxon[0])[0];
-//                     }
-//             } else {
-//                     taxon = (Taxon) taxonBase;
-//             }       
-               
-               
-               logger.trace(TaxonEditorInput.class.getSimpleName() + " created");
-               
-       return new TaxonEditorInput(taxonNode, conversation);
-    }
-    
-    public static TaxonEditorInput NewEmptyInstance(UUID parentNodeUuid){
-       ConversationHolder conversation = CdmStore.NewTransactionalConversation();
-               
-               TaxonNameBase<?, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null);
-               ITreeNode parentNode = CdmStore.getTaxonTreeService().getTreeNodeByUuid(parentNodeUuid);
-               
-               Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference());
-               TaxonNode newTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference(), null);
-               
-               // add the new taxon to the editors persistence context
-               CdmStore.getTaxonTreeService().saveTaxonNode(newTaxonNode);
-               // we pass on the conversation, will be closed when the editor is closed
-               return new TaxonEditorInput(newTaxonNode, conversation);
-    }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#exists()
-        */
-       public boolean exists() {
-               return taxonNode != null;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
-        */
-       public ImageDescriptor getImageDescriptor() {
-               return null;
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getName()
-        */
-       public String getName() {
-               TaxonNameBase<?, ?> name = getTaxon().getName();
-               if (name == null || name.getTitleCache() == null) {
-                       return "New taxon";
-               } else {
-                       return name.getTitleCache();
-               }       
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getPersistable()
-        */
-       public IPersistableElement getPersistable() {
-               ConversationHolder internalConversation = null;
-               if(conversation.isClosed())
-                       internalConversation = CdmStore.NewTransactionalConversation();
-               try{
-                       boolean isPersistable = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()) != null;
-                       if (isPersistable) {
-                               return this;
-                       } else {
-                               return null;
-                       }
-               }finally{
-                       if(internalConversation != null)
-                               internalConversation.close();
-               }
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getToolTipText()
-        */
-       public String getToolTipText() {
-               return getName();
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
-        */
-       public Object getAdapter(Class adapter) {
-
-               if (adapter == Taxon.class) {
-                       return taxonNode.getTaxon();
-               }
-               
-               if (adapter == TaxonNode.class) {
-                       return taxonNode;
-               }
-               
-               return null;
-       }
-       
-    /**
-     * Overrides equals to ensure that a taxon can only be edited by
-     * one editor at a time.
-     * 
-     * @return boolean
-     */        
-       public boolean equals(Object obj) {
-               if (obj.getClass().equals(TaxonEditorInput.class) 
-                               && getTaxon().equals(((TaxonEditorInput) obj).getTaxon()))
-                       return true;
-               return false;
-       }
-
-       /**
-        * @return the taxon
-        */
-       public Taxon getTaxon(){
-               return taxonNode.getTaxon();
-       }
-       
-       /**
-        * @return the taxonNode
-        */
-       public TaxonNode getTaxonNode() {
-               return taxonNode;
-       }
-       
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
-        */
-       public ConversationHolder getConversationHolder() {
-               return conversation;
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
-        */
-       public void update(CdmDataChangeMap events) {
-               // FIXME update the editor input
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IPersistableElement#getFactoryId()
-        */
-       public String getFactoryId() {
-               return TaxonEditorInputFactory.getFactoryId();
-       }
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
-        */
-       public void saveState(IMemento memento) {
-               TaxonEditorInputFactory.saveState(memento, this);
-       }
-}