3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
13 import java
.util
.UUID
;
15 import org
.eclipse
.jface
.viewers
.LabelProvider
;
16 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import org
.eclipse
.swt
.widgets
.Shell
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
23 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
24 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
25 import eu
.etaxonomy
.taxeditor
.newWizard
.NewPersonWizard
;
26 import eu
.etaxonomy
.taxeditor
.newWizard
.NewTeamWizard
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 * <p>FilteredAgentSelectionDialog class.</p>
33 * @created Sep 10, 2009
36 public class AgentSelectionDialog
extends
37 AbstractFilteredCdmResourceSelectionDialog
<AgentBase
> {
42 private static final String PERSON
= "Person";
46 private static final String TEAM
= "Team";
51 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
52 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
53 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
54 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
56 public static AgentBase
select(Shell shell
, ConversationHolder conversation
, AgentBase entity
) {
57 AgentSelectionDialog dialog
= new AgentSelectionDialog(shell
, conversation
,
58 "Choose Agent", false, AgentSelectionDialog
.class.getCanonicalName(), entity
);
59 return getSelectionFromDialog(dialog
);
63 * <p>Constructor for FilteredAgentSelectionDialog.</p>
65 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
66 * @param title a {@link java.lang.String} object.
67 * @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
68 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
69 * @param multi a boolean.
70 * @param settings a {@link java.lang.String} object.
72 protected AgentSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, String settings
, AgentBase agent
) {
73 super(shell
, conversation
, title
, multi
, settings
, agent
);
82 public class DetailsLabelProvider
extends LabelProvider
{
84 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
87 public String
getText(Object element
) {
88 AgentBase agent
= getCdmObjectByUuid(((UuidAndTitleCache
<AgentBase
>) element
).getUuid());
89 if (agent
instanceof INomenclaturalAuthor
) {
90 return "Nomenclatural title: '" + ((INomenclaturalAuthor
) agent
).getNomenclaturalTitle() + "'";
92 return "'" + agent
.getTitleCache() + "' is not a nomenclatural author.";
98 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
102 protected AgentBase
getPersistentObject(UUID cdmUuid
) {
103 return CdmStore
.getService(IAgentService
.class).load(cdmUuid
);
108 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
109 if(TEAM
.equals(parameter
)){
110 return new NewTeamWizard();
112 else if(PERSON
.equals(parameter
)){
113 return new NewPersonWizard();
116 throw new IllegalArgumentException("Could not determine the desired wizard.");
122 protected String
getNewWizardLinkText() {
123 return String
.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM
, PERSON
);
127 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
130 protected SelectionListener
getNewWizardLinkSelectionListener() {
131 return super.getNewWizardLinkSelectionListener();
136 protected void initModel() {
137 model
= CdmStore
.getService(IAgentService
.class).getUuidAndTitleCache();