2 * Copyright (C) 2016 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
;
13 import java
.text
.Collator
;
14 import java
.util
.Comparator
;
16 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
17 import org
.eclipse
.jface
.viewers
.LabelProvider
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
23 import eu
.etaxonomy
.cdm
.persistence
.dto
.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
.preference
.IPreferenceKeys
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class NomenclaturalAuthorSelectionDialog
extends AgentSelectionDialog
{
47 protected NomenclaturalAuthorSelectionDialog(Shell shell
, //ConversationHolder conversation,
49 boolean multi
, String settings
, AgentBase agent
, boolean teamMemberSelection
) {
50 super(shell
, //conversation,
51 title
, multi
, settings
, agent
, teamMemberSelection
);
52 // TODO Auto-generated constructor stub
56 protected void callService(String pattern
) {
57 model
= CdmStore
.getService(IAgentService
.class).getUuidAndAbbrevTitleCache(limitOfInitialElements
, pattern
, null);
62 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
63 if(TEAM
.equals(parameter
)){
64 return new NewTeamWizard(true);
66 else if(PERSON
.equals(parameter
)){
67 return new NewPersonWizard();
70 throw new IllegalArgumentException("Could not determine the desired wizard.");
78 protected ILabelProvider
createListLabelProvider() {
79 return new FilteredCdmResourceAbbrevLabelProvider();
85 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
86 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
87 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
88 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
90 public static AgentBase
select(Shell shell
, //ConversationHolder conversation,
91 AgentBase entity
, boolean teamMemberSelection
) {
92 NomenclaturalAuthorSelectionDialog dialog
= new NomenclaturalAuthorSelectionDialog(shell
, //conversation,
93 "Choose Agent", false, NomenclaturalAuthorSelectionDialog
.class.getCanonicalName(), entity
, teamMemberSelection
);
94 return getSelectionFromDialog(dialog
);
100 * @param cdmObject a T object.
101 * @return a {@link java.lang.String} object.
104 protected String
getTitle(AgentBase cdmObject
) {
105 if(cdmObject
== null){
109 if (cdmObject
instanceof TeamOrPersonBase
) {
110 return ((TeamOrPersonBase
) cdmObject
).getNomenclaturalTitle();
111 } else if (cdmObject
instanceof AgentBase
){
112 return ((TeamOrPersonBase
) cdmObject
).getTitleCache();
115 throw new IllegalArgumentException("Generic method only" +
116 " supports cdmObject of type IIdentifiableEntity." +
117 " Please implement specific method in subclass.");
122 public class FilteredCdmResourceAbbrevLabelProvider
extends LabelProvider
{
124 public String
getText(Object element
) {
125 if (element
== null) {
128 UuidAndTitleCache uuidAndTitleCache
= (UuidAndTitleCache
) element
;
129 String titleCache
= uuidAndTitleCache
.getTitleCache();
130 String abbrevTitleCache
= uuidAndTitleCache
.getAbbrevTitleCache();
131 if (!titleCache
.equals(abbrevTitleCache
)){
132 abbrevTitleCache
+= " - " + titleCache
;
134 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG
)){
135 abbrevTitleCache
+= " ["+uuidAndTitleCache
.getId()+"]";
137 return abbrevTitleCache
;
143 // protected ItemsFilter createFilter() {
144 // return new ItemsFilter() {
147 // * Always returns false to enforce refiltering even if the pattern is equal
150 // public boolean equalsFilter(ItemsFilter filter) {
155 // public boolean isConsistentItem(Object item) {
160 // public boolean matchItem(Object item) {
161 // String textTitleCache = null;
162 // String abbrevTitleCache = null;
163 // if(item instanceof UuidAndTitleCache){
164 // if (((UuidAndTitleCache) item).getAbbrevTitleCache() != null){
165 // abbrevTitleCache = ((UuidAndTitleCache) item).getAbbrevTitleCache();
167 // if (((UuidAndTitleCache) item).getTitleCache() != null ){
168 // textTitleCache = ((UuidAndTitleCache) item).getTitleCache();
170 // }else if(item instanceof String){
171 // textTitleCache = (String) item;
174 // return (matches(textTitleCache) || matches(abbrevTitleCache)) ;
182 protected Comparator
getItemsComparator() {
183 return new Comparator
<UuidAndTitleCache
>() {
185 public int compare(UuidAndTitleCache entity1
,
186 UuidAndTitleCache entity2
) {
188 if (entity1
.getUuid().equals(entity2
.getUuid())){
191 Collator collator
= Collator
.getInstance();
192 String compareString1
= "";
193 if (entity1
.getAbbrevTitleCache() != null){
194 compareString1
= entity1
.getAbbrevTitleCache();
196 if (entity1
.getTitleCache() != null){
197 compareString1
+= entity1
.getTitleCache();
201 String compareString2
= "";
202 if (entity2
.getAbbrevTitleCache() != null){
203 compareString2
= entity2
.getAbbrevTitleCache();
205 if (entity2
.getTitleCache() != null){
206 compareString2
+= entity2
.getTitleCache();
210 int result
=collator
.compare(compareString1
, compareString2
);
212 result
= entity1
.getUuid().compareTo(entity2
.getUuid());