2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
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
.service
.IAgentService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.dto
.EntityDTOBase
;
21 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IdentifiedEntityDTO
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
26 import eu
.etaxonomy
.cdm
.persistence
.dto
.TeamOrPersonUuidAndTitleCache
;
27 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
28 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
29 import eu
.etaxonomy
.taxeditor
.newWizard
.NewPersonWizard
;
30 import eu
.etaxonomy
.taxeditor
.newWizard
.NewTeamWizard
;
31 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * FilteredAgentSelectionDialog class.
38 * @created Sep 10, 2009
40 public class AgentSelectionDialog
<T
extends AgentBase
>
41 extends AbstractFilteredCdmResourceSelectionDialog
<T
> {
43 protected static final String PERSON
= "New Person";
44 protected static final String TEAM
= "New Team";
46 protected static boolean selectTeamMember
;
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 <S
extends AgentBase
> S
select(Shell shell
,
57 S entity
, boolean selectTeamMember
) {
58 AgentSelectionDialog
<S
> dialog
= new AgentSelectionDialog
<>(shell
,
59 "Choose Agent", false, AgentSelectionDialog
.class.getCanonicalName(), entity
, selectTeamMember
);
60 return getSelectionFromDialog(dialog
);
64 * <p>Constructor for FilteredAgentSelectionDialog.</p>
66 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
67 * @param title a {@link java.lang.String} object.
68 * @param agent a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
69 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
70 * @param multi a boolean.
71 * @param settings a {@link java.lang.String} object.
73 protected AgentSelectionDialog(Shell shell
,
74 String title
, boolean multi
, String settings
, T agent
, boolean selectTeamMember
) {
75 super(shell
, title
, multi
, settings
, agent
);
76 this.selectTeamMember
= selectTeamMember
;
79 public class DetailsLabelProvider
extends LabelProvider
{
81 public String
getText(Object element
) {
82 T agent
= getCdmObjectByUuid(((UuidAndTitleCache
<AgentBase
>) element
).getUuid());
83 if (agent
instanceof INomenclaturalAuthor
) {
84 return "Nomenclatural title: '" + ((INomenclaturalAuthor
) agent
).getNomenclaturalTitleCache() + "'";
86 return "'" + agent
.getTitleCache() + "' is not a nomenclatural author.";
94 protected T
getPersistentObject(UUID cdmUuid
) {
95 return (T
)CdmStore
.getService(IAgentService
.class).load(cdmUuid
);
99 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
100 if(TEAM
.equals(parameter
)){
101 return new NewTeamWizard();
103 else if(PERSON
.equals(parameter
)){
104 return new NewPersonWizard();
107 throw new IllegalArgumentException("Could not determine the desired wizard.");
112 protected String
[] getNewWizardText() {
114 if (this.selectTeamMember
){
115 result
= new String
[1];
118 result
= new String
[2];
126 protected SelectionListener
getNewWizardButtonSelectionListener() {
127 return super.getNewWizardButtonSelectionListener();
131 protected void callService(String pattern
) {
132 Class
<T
> clazz
= (Class
)AgentBase
.class;
133 if (selectTeamMember
){
134 clazz
= (Class
)Person
.class;
137 model
= (List
)CdmStore
.getService(IAgentService
.class).getTeamOrPersonUuidAndTitleCache(clazz
, limitOfInitialElements
, pattern
);
140 protected ILabelProvider
createListLabelProvider() {
141 return new CollectorLabelProvider();
144 public class CollectorLabelProvider
extends LabelProvider
{
146 public String
getText(Object element
) {
147 if (element
== null) {
150 UuidAndTitleCache uuidAndTitleCache
= (UuidAndTitleCache
) element
;
151 String titleCache
= uuidAndTitleCache
.getTitleCache();
152 String abbrevTitleCache
= uuidAndTitleCache
.getAbbrevTitleCache();
153 String collectorTitleCache
= null;
154 if (element
instanceof TeamOrPersonUuidAndTitleCache
){
155 collectorTitleCache
= ((TeamOrPersonUuidAndTitleCache
)element
).getCollectorTitleCache();
157 if (!titleCache
.equals(abbrevTitleCache
)){
158 titleCache
+= " - " + abbrevTitleCache
;
160 if (collectorTitleCache
!= null && !uuidAndTitleCache
.getTitleCache().equals(collectorTitleCache
) && !abbrevTitleCache
.equals(collectorTitleCache
)){
161 titleCache
+= " - " + collectorTitleCache
;
163 if(PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowIdInSelectionDialog
.getKey())){
164 titleCache
+= " ["+uuidAndTitleCache
.getId()+"]";
166 if (element
instanceof EntityDTOBase
){
167 titleCache
+= "(" + ((IdentifiedEntityDTO
)element
).getIdentifier().getTypeLabel() +": " + ((IdentifiedEntityDTO
)element
).getIdentifier().getIdentifier() + ")";