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
.IdentifiedEntityDTO
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
25 import eu
.etaxonomy
.cdm
.persistence
.dto
.EntityDTOBase
;
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 boolean selectTeamMember
;
51 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
52 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
53 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
55 public static <S
extends AgentBase
> S
select(Shell shell
,
56 S entity
, boolean selectTeamMember
) {
57 AgentSelectionDialog
<S
> dialog
= new AgentSelectionDialog
<>(shell
,
58 "Choose Agent", false, AgentSelectionDialog
.class.getCanonicalName(), entity
, selectTeamMember
);
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 multi a boolean.
69 * @param settings a {@link java.lang.String} object.
71 protected AgentSelectionDialog(Shell shell
,
72 String title
, boolean multi
, String settings
, T agent
, boolean selectTeamMember
) {
73 super(shell
, title
, multi
, settings
, agent
);
74 this.selectTeamMember
= selectTeamMember
;
77 public class DetailsLabelProvider
extends LabelProvider
{
79 public String
getText(Object element
) {
80 T agent
= getCdmObjectByUuid(((UuidAndTitleCache
<AgentBase
>) element
).getUuid());
81 if (agent
instanceof INomenclaturalAuthor
) {
82 return "Nomenclatural title: '" + ((INomenclaturalAuthor
) agent
).getNomenclaturalTitleCache() + "'";
84 return "'" + agent
.getTitleCache() + "' is not a nomenclatural author.";
90 protected T
getPersistentObject(UUID cdmUuid
) {
91 return (T
)CdmStore
.getService(IAgentService
.class).load(cdmUuid
);
95 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
96 if(TEAM
.equals(parameter
)){
97 return new NewTeamWizard();
99 else if(PERSON
.equals(parameter
)){
100 return new NewPersonWizard();
103 throw new IllegalArgumentException("Could not determine the desired wizard.");
108 protected String
[] getNewWizardText() {
110 if (selectTeamMember
){
111 result
= new String
[1];
114 result
= new String
[2];
122 protected SelectionListener
getNewWizardButtonSelectionListener() {
123 return super.getNewWizardButtonSelectionListener();
127 protected void callService(String pattern
) {
128 Class
<T
> clazz
= (Class
<T
>)AgentBase
.class;
129 if (selectTeamMember
){
130 clazz
= (Class
<T
>)Person
.class;
133 model
= (List
)CdmStore
.getService(IAgentService
.class).getTeamOrPersonUuidAndTitleCache(clazz
, limitOfInitialElements
, pattern
);
136 protected ILabelProvider
createListLabelProvider() {
137 return new AgentLabelProvider();
140 public class AgentLabelProvider
extends LabelProvider
{
142 public String
getText(Object element
) {
143 if (element
== null) {
146 UuidAndTitleCache
<?
> uuidAndTitleCache
= (UuidAndTitleCache
<?
>) element
;
147 String titleCache
= uuidAndTitleCache
.getTitleCache()!= null? uuidAndTitleCache
.getTitleCache(): "" ;
148 String abbrevTitleCache
= uuidAndTitleCache
.getAbbrevTitleCache()!= null? uuidAndTitleCache
.getAbbrevTitleCache(): "";
149 String collectorTitleCache
= null;
150 if (element
instanceof TeamOrPersonUuidAndTitleCache
){
151 collectorTitleCache
= ((TeamOrPersonUuidAndTitleCache
)element
).getCollectorTitleCache();
153 if (!titleCache
.equals(abbrevTitleCache
) && abbrevTitleCache
!= null){
154 titleCache
+= " - " + abbrevTitleCache
;
156 if (collectorTitleCache
!= null && !titleCache
.equals(collectorTitleCache
) && !abbrevTitleCache
.equals(collectorTitleCache
)){
157 titleCache
+= " - " + collectorTitleCache
;
159 if(PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowIdInSelectionDialog
.getKey())){
160 titleCache
+= " ["+uuidAndTitleCache
.getId()+"]";
162 if (element
instanceof EntityDTOBase
){
163 titleCache
+= "(" + ((IdentifiedEntityDTO
)element
).getIdentifier().getTypeLabel() +": " + ((IdentifiedEntityDTO
)element
).getIdentifier().getIdentifier() + ")";