/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
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.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
+
/**
* <p>TaxonEditorInput class.</p>
*
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;
}
-
-
+
+
/**
* <p>NewInstance</p>
*
throw e;
}
}
-
+
/**
- *
+ *
* @param taxonNodeUuid
* @param conversation
* @return
*/
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.");
+ MessagingUtils.warningDialog("Not yet implemented", TaxonEditorInput.class, "Selected element is not type TaxonBase.");
return null;
- }
-
+ }
+
return new TaxonEditorInput(taxonNode, conversation);
}
-
+
/**
* <p>NewInstanceFromTaxonBase</p>
*
*/
public static TaxonEditorInput NewInstanceFromTaxonBase(UUID taxonBaseUuid){
ConversationHolder conversation = CdmStore.createConversation();
-
+
TaxonEditorInput input = null;
-
+
TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
-
- if(taxonBase instanceof Taxon){
- Taxon taxon = (Taxon) taxonBase;
-
- if (taxon.isMisapplication()){
- // TODO get accepted taxon
- EditorUtil.info("trying to open Mispplied Name ");
-
- Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
- Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
- for(TaxonRelationship relation : relations){
- if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
- acceptedTaxa.add(relation.getToTaxon());
- }
- }
- input = getInputForMultipleTaxa(conversation, acceptedTaxa);
-
- }else{
- input = getInputForMultipleNodes(conversation, taxon.getTaxonNodes());
- }
- }else if(taxonBase instanceof Synonym){
- Synonym synonym = (Synonym) taxonBase;
-
- Set<Taxon> taxa = synonym.getAcceptedTaxa();
- input = getInputForMultipleTaxa(conversation, taxa);
+ if (taxonBase != null){
+ if(taxonBase.isOrphaned()) {
+ MessagingUtils.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.getTaxonNodes().size() == 0 && taxon.isMisapplication()){
+ // TODO get accepted taxon
+ MessagingUtils.info("trying to open Mispplied Name ");
+
+ Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
+ Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
+ for(TaxonRelationship relation : relations){
+ if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+ acceptedTaxa.add(relation.getToTaxon());
+ }
+ }
+ input = getInputForMultipleTaxa(conversation, acceptedTaxa);
+
+ }else{
+ input = getInputForMultipleNodes(conversation, taxon.getTaxonNodes());
+ }
+ }else if(taxonBase instanceof Synonym){
+ Synonym synonym = (Synonym) taxonBase;
+
+ Set<Taxon> taxa = synonym.getAcceptedTaxa();
+ input = getInputForMultipleTaxa(conversation, taxa);
+ }
+ if (input != null){
+ input.setInitiallySelectedTaxonBase(taxonBase);
+ }
}
- input.setInitiallySelectedTaxonBase(taxonBase);
-
+
return input;
}
-
+
private static TaxonEditorInput getInputForMultipleNodes(ConversationHolder conversation, Set<TaxonNode> taxonNodes){
if(taxonNodes.size() == 1){
TaxonNode taxonNode = taxonNodes.iterator().next();
}else if(taxonNodes.size() > 1){
TaxonNode taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(taxonNodes);
if(taxonNode != null){
- return NewInstance(taxonNode.getUuid(), conversation);
+ return NewInstance(taxonNode.getUuid(), conversation);
}
}else if(taxonNodes.size() == 0){
// this is an undesired state
- EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
+ MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "The accepted taxon is not part of any classification. This should not have happened.");
}
return null;
}
-
+
private static TaxonEditorInput getInputForMultipleTaxa(ConversationHolder conversation, Set<Taxon> taxa){
if(taxa.size() == 1){
Taxon taxon = taxa.iterator().next();
Set<TaxonNode> nodes = taxon.getTaxonNodes();
return getInputForMultipleNodes(conversation, nodes);
}else if(taxa.size() > 1){
- // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
- EditorUtil.warningDialog("Not implemented yet", TaxonEditorInput.class, "There are multiple accepted taxa for the current selection. We currently do not know which one you want to open." +
- " This case is not handled yet by the software.");
+ Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
+ for ( Taxon taxon : taxa ){
+ taxonNodes.addAll(taxon.getTaxonNodes());
+ }
+ return getInputForMultipleNodes(conversation, taxonNodes);
}else if(taxa.size() == 0){
// this is an undesired state
- EditorUtil.warningDialog("Incorrect state", TaxonEditorInput.class, "Trying to open accepted taxon for a synonym or misapplication but" +
+ MessagingUtils.warningDialog("Incorrect state", TaxonEditorInput.class, "Trying to open accepted taxon for a synonym or misapplication but" +
" no accepted taxa are present. This should not have happened.");
}
return null;
}
-
+
/**
* <p>NewEmptyInstance</p>
*
*/
public static TaxonEditorInput NewEmptyInstance(UUID parentNodeUuid){
ConversationHolder conversation = CdmStore.createConversation();
-
+
TaxonNameBase<?, ?> name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null);
- ITreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid);
-
+ ITaxonTreeNode parentNode = CdmStore.getService(IClassificationService.class).getTreeNodeByUuid(parentNodeUuid);
+
Taxon newTaxon = Taxon.NewInstance(name, parentNode.getReference());
- TaxonNode newTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference(), null);
-
+ 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);
-
+
return new TaxonEditorInput(newTaxonNode, conversation);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.ui.IEditorInput#exists()
*/
*
* @return a boolean.
*/
- public boolean exists() {
+ @Override
+ public boolean exists() {
return taxonNode != null;
}
*
* @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
*/
- public ImageDescriptor getImageDescriptor() {
+ @Override
+ public ImageDescriptor getImageDescriptor() {
return null;
}
*
* @return a {@link java.lang.String} object.
*/
- public String getName() {
+ @Override
+ public String getName() {
if(getTaxon() == null){
return null;
}
return "New taxon";
} else {
return name.getTitleCache();
- }
+ }
}
/* (non-Javadoc)
*
* @return a {@link org.eclipse.ui.IPersistableElement} object.
*/
- public IPersistableElement getPersistable() {
+ @Override
+ public IPersistableElement getPersistable() {
// if(CdmStore.isActive()){
// TaxonNode test = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid());
// boolean isPersistable = CdmStore.getTaxonTreeService().getTaxonNodeByUuid(taxonNode.getUuid()) != null;
*
* @return a {@link java.lang.String} object.
*/
- public String getToolTipText() {
+ @Override
+ public String getToolTipText() {
return getName();
}
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
/** {@inheritDoc} */
- public Object getAdapter(Class adapter) {
+ @Override
+ 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())
+ @Override
+ public boolean equals(Object obj) {
+ if (TaxonEditorInput.class.equals(obj.getClass())
&& getTaxon() != null
&& getTaxon().equals(((TaxonEditorInput) obj).getTaxon())){
if(((TaxonEditorInput) obj).getInitiallySelectedTaxonBase() != null){
public Taxon getTaxon(){
return taxonNode.getTaxon();
}
-
+
/**
* <p>Getter for the field <code>taxonNode</code>.</p>
*
public TaxonNode getTaxonNode() {
return taxonNode;
}
-
+
/*
* (non-Javadoc)
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
*
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
*/
- public ConversationHolder getConversationHolder() {
+ @Override
+ public ConversationHolder getConversationHolder() {
return conversation;
}
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
*/
/** {@inheritDoc} */
- public void update(CdmDataChangeMap events) {
+ @Override
+ public void update(CdmDataChangeMap events) {
if(dataChangeBehavior == null){
dataChangeBehavior = new TaxonEditorInputDataChangeBehaviour(this);
}
-
+
DataChangeBridge.handleDataChange(events, dataChangeBehavior);
}
*
* @return a {@link java.lang.String} object.
*/
- public String getFactoryId() {
+ @Override
+ public String getFactoryId() {
return TaxonEditorInputFactory.getFactoryId();
}
* @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
*/
/** {@inheritDoc} */
- public void saveState(IMemento memento) {
+ @Override
+ public void saveState(IMemento memento) {
TaxonEditorInputFactory.saveState(memento, this);
}
-
+
/**
* <p>Setter for the field <code>initiallySelectedTaxonBase</code>.</p>
*
public TaxonBase getInitiallySelectedTaxonBase() {
return initiallySelectedTaxonBase;
}
-
+
@Override
public String toString() {
return String.format("%s[%s]", this.getClass().getSimpleName(), getTaxon());