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
.Control
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
19 import org
.eclipse
.swt
.widgets
.Text
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
25 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
26 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
27 import eu
.etaxonomy
.taxeditor
.newWizard
.NewPersonWizard
;
28 import eu
.etaxonomy
.taxeditor
.newWizard
.NewTeamWizard
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 * <p>FilteredAgentSelectionDialog class.</p>
35 * @created Sep 10, 2009
38 public class AgentSelectionDialog
extends
39 AbstractFilteredCdmResourceSelectionDialog
<AgentBase
> {
44 protected static final String PERSON
= "Person";
48 protected static final String TEAM
= "Team";
50 protected static boolean selectTeamMember
;
55 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
56 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
57 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
58 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
60 public static AgentBase
select(Shell shell
, ConversationHolder conversation
, AgentBase entity
, boolean selectTeamMember
) {
61 AgentSelectionDialog dialog
= new AgentSelectionDialog(shell
, conversation
,
62 "Choose Agent", false, AgentSelectionDialog
.class.getCanonicalName(), entity
, selectTeamMember
);
63 return getSelectionFromDialog(dialog
);
67 * <p>Constructor for FilteredAgentSelectionDialog.</p>
69 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
70 * @param title a {@link java.lang.String} object.
71 * @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
72 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
73 * @param multi a boolean.
74 * @param settings a {@link java.lang.String} object.
76 protected AgentSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
, boolean multi
, String settings
, AgentBase agent
, boolean selectTeamMember
) {
77 super(shell
, conversation
, title
, multi
, settings
, agent
);
78 this.selectTeamMember
= selectTeamMember
;
87 public class DetailsLabelProvider
extends LabelProvider
{
89 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
92 public String
getText(Object element
) {
93 AgentBase agent
= getCdmObjectByUuid(((UuidAndTitleCache
<AgentBase
>) element
).getUuid());
94 if (agent
instanceof INomenclaturalAuthor
) {
95 return "Nomenclatural title: '" + ((INomenclaturalAuthor
) agent
).getNomenclaturalTitle() + "'";
97 return "'" + agent
.getTitleCache() + "' is not a nomenclatural author.";
103 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
107 protected AgentBase
getPersistentObject(UUID cdmUuid
) {
108 return CdmStore
.getService(IAgentService
.class).load(cdmUuid
);
113 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
114 if(TEAM
.equals(parameter
)){
115 return new NewTeamWizard();
117 else if(PERSON
.equals(parameter
)){
118 return new NewPersonWizard();
121 throw new IllegalArgumentException("Could not determine the desired wizard.");
127 protected String
getNewWizardLinkText() {
128 if (this.selectTeamMember
){
129 return String
.format("Create a new <a>%1s</a>", PERSON
);
131 return String
.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM
, PERSON
);
135 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
138 protected SelectionListener
getNewWizardLinkSelectionListener() {
139 return super.getNewWizardLinkSelectionListener();
144 protected void initModel() {
145 Control control
= getPatternControl();
146 String pattern
= null;
147 if (control
!= null){
148 pattern
= ((Text
)control
).getText();
152 model
= CdmStore
.getService(IAgentService
.class).getUuidAndTitleCache(limitOfInitialElements
, pattern
);