X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/b4ca72feefd93388d62fc4e988192c6b31c5450d..0819c19db63cc608e26f924eb554e61f4d0638bd:/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java index 6db78f03d..a42076cf1 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/TaxonEditorInput.java @@ -1,15 +1,19 @@ /** -* 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. -*/ + * 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.ArrayList; +import java.util.Arrays; import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; @@ -24,8 +28,8 @@ import eu.etaxonomy.cdm.api.service.IClassificationService; import eu.etaxonomy.cdm.api.service.ITaxonNodeService; import eu.etaxonomy.cdm.api.service.ITaxonService; import eu.etaxonomy.cdm.model.common.CdmBase; -import eu.etaxonomy.cdm.model.name.TaxonNameBase; -import eu.etaxonomy.cdm.model.taxon.ITreeNode; +import eu.etaxonomy.cdm.model.name.TaxonName; +import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonBase; @@ -33,10 +37,13 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; +import eu.etaxonomy.taxeditor.editor.l10n.Messages; import eu.etaxonomy.taxeditor.model.DataChangeBridge; +import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.store.CdmStore; + /** *
TaxonEditorInput class.
* @@ -44,58 +51,168 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * @created 19.03.2009 * @version 1.0 */ -public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPersistableElement { - - private ConversationHolder conversation; - - private TaxonNode taxonNode; - - private TaxonEditorInputDataChangeBehaviour dataChangeBehavior; - - private TaxonBase initiallySelectedTaxonBase; - - private TaxonEditorInput(TaxonNode taxonNode, ConversationHolder conversation){ - this.conversation = conversation; - this.taxonNode = taxonNode; - } - - - - /** - *NewInstance
- * - * @param taxonNodeUuid a {@link java.util.UUID} object. - * @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. - * @throws java.lang.Exception if any. - */ - public static TaxonEditorInput NewInstance(UUID taxonNodeUuid) throws Exception{ - try{ - ConversationHolder conversation = CdmStore.createConversation(); - return NewInstance(taxonNodeUuid, conversation); - }catch(Exception e){ - throw e; - } - } - +public class TaxonEditorInput extends CdmEntitySessionInput implements IEditorInput, IConversationEnabled, IPersistableElement { + + private static final String INCORRECT_STATE = Messages.TaxonEditorInput_INCORRECT_STATE; + + private final ConversationHolder conversation; + + private TaxonNode taxonNode; + + private TaxonEditorInputDataChangeBehaviour dataChangeBehavior; + + private TaxonBase initiallySelectedTaxonBase; + + private enum CdmType { + TAXON_NODE, + TAXON_BASE, + PARENT_TAXON_NODE + } + + private TaxonEditorInput(UUID uuid, CdmType type) { + super(true); + this.conversation = CdmStore.createConversation(); + switch(type) { + case PARENT_TAXON_NODE: + initForParentTaxonNode(uuid); + break; + case TAXON_BASE: + initForTaxonBase(uuid); + break; + case TAXON_NODE: + initForTaxonNode(uuid); + break; + } + } + + private void init(TaxonNode taxonNode) { + this.taxonNode = taxonNode; + } + + + /** + *NewInstance
+ * + * @param taxonNodeUuid a {@link java.util.UUID} object. + * @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. + * @throws java.lang.Exception if any. + */ + private void initForTaxonNode(UUID taxonNodeUuid) { + + + TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, getTaxonNodePropertyPaths()); + + if(taxonNode == null){ + MessagingUtils.warningDialog(Messages.TaxonEditorInput_NOT_IMPLEMENTED, TaxonEditorInput.class, Messages.TaxonEditorInput_NOT_IMPLEMENTED_MESSAGE); + } + init(taxonNode); + + } + + private void initForTaxonBase(UUID taxonBaseUuid) { + TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonBaseUuid, getTaxonBasePropertyPaths()); + if (taxonBase != null){ + if(taxonBase.isInstanceOf(Taxon.class)){ + Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class); + + if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){ + // TODO get accepted taxon + MessagingUtils.info(Messages.TaxonEditorInput_OPEN_MISSAPPLIED_NAME); + + SetNewEmptyInstance
+ * + * @param parentNodeUuid a {@link java.util.UUID} object. + * @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. + */ + private void initForParentTaxonNode(UUID parentNodeUuid){ + + + TaxonName name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null); + ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid); + + Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference()); + TaxonNode newTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference()); + + // add the new taxon to the editors persistence context + UUID newTaxonNodeUuid = CdmStore.getService(ITaxonNodeService.class).save(newTaxonNode).getUuid(); + + initForTaxonNode(newTaxonNodeUuid); + } + + + + + private void setInputForMultipleNodes(ConversationHolder conversation, SetNewInstance
+ * + * @param taxonNodeUuid a {@link java.util.UUID} object. + * @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. + * @throws java.lang.Exception if any. */ - private static TaxonEditorInput NewInstance(UUID taxonNodeUuid, ConversationHolder conversation){ - - - TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeUuid, null); - - if(taxonNode == null){ - EditorUtil.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase."); - return null; - } - - return new TaxonEditorInput(taxonNode, conversation); + public static TaxonEditorInput NewInstance(UUID taxonNodeUuid) throws Exception { + return new TaxonEditorInput(taxonNodeUuid, CdmType.TAXON_NODE); + } - + /** *NewInstanceFromTaxonBase
* @@ -103,80 +220,10 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe * @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. */ public static TaxonEditorInput NewInstanceFromTaxonBase(UUID taxonBaseUuid){ - ConversationHolder conversation = CdmStore.createConversation(); - - TaxonEditorInput input = null; - - TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid); - if(taxonBase.isOrphaned()) { - EditorUtil.warningDialog("Orphaned Taxon", TaxonEditorInput.class, "This is an orphaned taxon i.e. a taxon that is not connected to a classification and not having any taxonomic relationships. Editing of orphaned taxon is currently not supported."); - } - else if(taxonBase.isInstanceOf(Taxon.class)){ - Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class); - - if (taxon.isMisapplication()){ - // TODO get accepted taxon - EditorUtil.info("trying to open Mispplied Name "); - - SetNewEmptyInstance
* @@ -184,215 +231,286 @@ public class TaxonEditorInput implements IEditorInput, IConversationEnabled, IPe * @return a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput} object. */ public static TaxonEditorInput NewEmptyInstance(UUID parentNodeUuid){ - ConversationHolder conversation = CdmStore.createConversation(); - - TaxonNameBase, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null); - ITreeNode parentNode = CdmStore.getService(IClassificationService.class).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 - UUID newTaxonNodeUuid = CdmStore.getService(ITaxonNodeService.class).save(newTaxonNode); - - return new TaxonEditorInput(newTaxonNode, conversation); + return new TaxonEditorInput(parentNodeUuid, CdmType.PARENT_TAXON_NODE); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#exists() + */ + /** + *exists
+ * + * @return a boolean. + */ + @Override + public boolean exists() { + return taxonNode != null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getImageDescriptor() + */ + /** + *getImageDescriptor
+ * + * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object. + */ + @Override + public ImageDescriptor getImageDescriptor() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getName() + */ + /** + *getName
+ * + * @return a {@link java.lang.String} object. + */ + @Override + public String getName() { + if(getTaxon() == null){ + return null; + } + TaxonName name = getTaxon().getName(); + if (name == null || name.getTitleCache() == null) { + return Messages.TaxonEditorInput_NEW_TAXON; + } else { + return name.getTitleCache(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getPersistable() + */ + /** + *getPersistable
+ * + * @return a {@link org.eclipse.ui.IPersistableElement} object. + */ + @Override + public IPersistableElement getPersistable() { + // if(CdmStore.isActive()){ + // TaxonNode test = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()); + // boolean isPersistable = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()) != null; + // if (isPersistable) { + // return this; + // } + // } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getToolTipText() + */ + /** + *getToolTipText
+ * + * @return a {@link java.lang.String} object. + */ + @Override + public String getToolTipText() { + return getName(); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + /** {@inheritDoc} */ + @Override + public Object getAdapter(Class adapter) { + + if (adapter == Taxon.class) { + return getTaxon(); + } + + if (adapter == TaxonNode.class) { + return taxonNode; + } + + return null; + } + + /** + * {@inheritDoc} + * + * Overrides equals to ensure that a taxon can only be edited by + * one editor at a time. + */ + @Override + public boolean equals(Object obj) { + if (TaxonEditorInput.class.equals(obj.getClass()) + && getTaxon() != null + && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())) { + if (((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){ + setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase()); + } + return true; + } + return false; + } + + /** + *getTaxon
+ * + * @return the taxon + */ + public Taxon getTaxon(){ + Taxon taxon = CdmBase.deproxy(taxonNode.getTaxon(), Taxon.class); + return taxon; + } + + /** + *Getter for the field taxonNode
.
getConversationHolder
+ * + * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. + */ + @Override + public ConversationHolder getConversationHolder() { + return conversation; + } + + /* + * (non-Javadoc) + * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent) + */ + /** {@inheritDoc} */ + @Override + public void update(CdmDataChangeMap events) { + if(dataChangeBehavior == null){ + dataChangeBehavior = new TaxonEditorInputDataChangeBehaviour(this); + } + + DataChangeBridge.handleDataChange(events, dataChangeBehavior); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPersistableElement#getFactoryId() + */ + /** + *getFactoryId
+ * + * @return a {@link java.lang.String} object. + */ + @Override + public String getFactoryId() { + return TaxonEditorInputFactory.getFactoryId(); } - - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#exists() - */ - /** - *exists
- * - * @return a boolean. - */ - public boolean exists() { - return taxonNode != null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getImageDescriptor() - */ - /** - *getImageDescriptor
- * - * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object. - */ - public ImageDescriptor getImageDescriptor() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getName() - */ - /** - *getName
- * - * @return a {@link java.lang.String} object. - */ - public String getName() { - if(getTaxon() == null){ - return null; - } - 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() - */ - /** - *getPersistable
- * - * @return a {@link org.eclipse.ui.IPersistableElement} object. - */ - public IPersistableElement getPersistable() { -// if(CdmStore.isActive()){ -// TaxonNode test = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()); -// boolean isPersistable = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()) != null; -// if (isPersistable) { -// return this; -// } -// } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getToolTipText() - */ - /** - *getToolTipText
- * - * @return a {@link java.lang.String} object. - */ - public String getToolTipText() { - return getName(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - /** {@inheritDoc} */ - public Object getAdapter(Class adapter) { - - if (adapter == Taxon.class) { - return taxonNode.getTaxon(); - } - - if (adapter == TaxonNode.class) { - return taxonNode; - } - - return null; - } - - /** - * {@inheritDoc} - * - * Overrides equals to ensure that a taxon can only be edited by - * one editor at a time. - */ - public boolean equals(Object obj) { - if (TaxonEditorInput.class.equals(obj.getClass()) - && getTaxon() != null - && getTaxon().equals(((TaxonEditorInput) obj).getTaxon())){ - if(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){ - setInitiallySelectedTaxonBase(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase()); - } - return true; - } - return false; - } - - /** - *getTaxon
- * - * @return the taxon - */ - public Taxon getTaxon(){ - return taxonNode.getTaxon(); - } - - /** - *Getter for the field taxonNode
.
getConversationHolder
- * - * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. - */ - public ConversationHolder getConversationHolder() { - return conversation; - } - - /* - * (non-Javadoc) - * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent) - */ - /** {@inheritDoc} */ - public void update(CdmDataChangeMap events) { - if(dataChangeBehavior == null){ - dataChangeBehavior = new TaxonEditorInputDataChangeBehaviour(this); - } - - DataChangeBridge.handleDataChange(events, dataChangeBehavior); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPersistableElement#getFactoryId() - */ - /** - *getFactoryId
- * - * @return a {@link java.lang.String} object. - */ - public String getFactoryId() { - return TaxonEditorInputFactory.getFactoryId(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento) - */ - /** {@inheritDoc} */ - public void saveState(IMemento memento) { - TaxonEditorInputFactory.saveState(memento, this); - } - - + + /* (non-Javadoc) + * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento) + */ + /** {@inheritDoc} */ + @Override + public void saveState(IMemento memento) { + TaxonEditorInputFactory.saveState(memento, this); + } + + /** *Setter for the field initiallySelectedTaxonBase
.
Getter for the field initiallySelectedTaxonBase
.
Getter for the field initiallySelectedTaxonBase
.