From e765dbb37667f5b9ac288f0114cd62f46605a70b Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Wed, 25 May 2016 10:19:40 +0200 Subject: [PATCH] selectiondialog for nomenclatural authors should work on nomenclatural title --- .../NomenclaturalAuthorSelectionDialog.java | 84 +++++++++++++++++++ .../selection/SelectionDialogFactory.java | 6 +- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NomenclaturalAuthorSelectionDialog.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NomenclaturalAuthorSelectionDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NomenclaturalAuthorSelectionDialog.java new file mode 100644 index 000000000..6ccfbc3ef --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NomenclaturalAuthorSelectionDialog.java @@ -0,0 +1,84 @@ +// $Id$ +/** +* Copyright (C) 2016 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.ui.dialog.selection; + +import org.eclipse.swt.widgets.Shell; + +import eu.etaxonomy.cdm.api.conversation.ConversationHolder; +import eu.etaxonomy.cdm.api.service.IAgentService; +import eu.etaxonomy.cdm.model.agent.AgentBase; +import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + * @author k.luther + * @date 25.05.2016 + * + */ +public class NomenclaturalAuthorSelectionDialog extends AgentSelectionDialog { + + + /** + * @param shell + * @param conversation + * @param title + * @param multi + * @param settings + * @param agent + */ + protected NomenclaturalAuthorSelectionDialog(Shell shell, ConversationHolder conversation, String title, + boolean multi, String settings, AgentBase agent) { + super(shell, conversation, title, multi, settings, agent); + // TODO Auto-generated constructor stub + } + + @Override + protected void initModel() { + model = CdmStore.getService(IAgentService.class).getUuidAndAbbrevTitleCache(null, null); + } + + /** + *

select

+ * + * @param shell a {@link org.eclipse.swt.widgets.Shell} object. + * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. + * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object. + * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object. + */ + public static AgentBase select(Shell shell, ConversationHolder conversation, AgentBase entity) { + NomenclaturalAuthorSelectionDialog dialog = new NomenclaturalAuthorSelectionDialog(shell, conversation, + "Choose Agent", false, NomenclaturalAuthorSelectionDialog.class.getCanonicalName(), entity); + return getSelectionFromDialog(dialog); + } + + /** + *

getTitle

+ * + * @param cdmObject a T object. + * @return a {@link java.lang.String} object. + */ + @Override + protected String getTitle(AgentBase cdmObject) { + if(cdmObject == null){ + return ""; + } + + if (cdmObject instanceof TeamOrPersonBase) { + return ((TeamOrPersonBase) cdmObject).getNomenclaturalTitle(); + } else if (cdmObject instanceof AgentBase){ + return ((TeamOrPersonBase) cdmObject).getTitleCache(); + } + + throw new IllegalArgumentException("Generic method only" + + " supports cdmObject of type IIdentifiableEntity." + + " Please implement specific method in subclass."); + } + +} diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java index a90ce1c9b..70cdd0fb3 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java @@ -44,6 +44,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; import eu.etaxonomy.taxeditor.ui.element.IEntityElement; +import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement; /** * @author n.hoffmann @@ -82,10 +83,13 @@ public class SelectionDialogFactory { if(clazz.equals(Team.class)){ return (T) TeamSelectionDialog.select(shell, conversation, (Team) currentSelection); } - if(clazz.equals(TeamOrPersonBase.class)){ + if(clazz.equals(TeamOrPersonBase.class) && parentElement instanceof AuthorshipDetailElement){ + return (T) NomenclaturalAuthorSelectionDialog.select(shell, conversation, (AgentBase) currentSelection); + }else if(clazz.equals(TeamOrPersonBase.class)){ //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545) return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection); } + if(clazz.equals(AgentBase.class)){ return (T) AgentSelectionDialog.select(shell, conversation, (AgentBase) currentSelection); } -- 2.34.1