1
|
/**
|
2
|
* Copyright (C) 2016 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.ui.dialog.selection;
|
10
|
|
11
|
|
12
|
|
13
|
import java.text.Collator;
|
14
|
import java.util.Comparator;
|
15
|
|
16
|
import org.eclipse.jface.viewers.ILabelProvider;
|
17
|
import org.eclipse.jface.viewers.LabelProvider;
|
18
|
import org.eclipse.swt.widgets.Shell;
|
19
|
|
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;
|
30
|
|
31
|
/**
|
32
|
* @author k.luther
|
33
|
* @date 25.05.2016
|
34
|
*
|
35
|
*/
|
36
|
public class NomenclaturalAuthorSelectionDialog extends AgentSelectionDialog {
|
37
|
|
38
|
|
39
|
/**
|
40
|
* @param shell
|
41
|
* @param conversation
|
42
|
* @param title
|
43
|
* @param multi
|
44
|
* @param settings
|
45
|
* @param agent
|
46
|
*/
|
47
|
protected NomenclaturalAuthorSelectionDialog(Shell shell, //ConversationHolder conversation,
|
48
|
String title,
|
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
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
protected void callService(String pattern) {
|
57
|
model = CdmStore.getService(IAgentService.class).getUuidAndAbbrevTitleCache(limitOfInitialElements, pattern, null);
|
58
|
}
|
59
|
|
60
|
/** {@inheritDoc} */
|
61
|
@Override
|
62
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
63
|
if(TEAM.equals(parameter)){
|
64
|
return new NewTeamWizard(true);
|
65
|
}
|
66
|
else if(PERSON.equals(parameter)){
|
67
|
return new NewPersonWizard();
|
68
|
}
|
69
|
else{
|
70
|
throw new IllegalArgumentException("Could not determine the desired wizard.");
|
71
|
}
|
72
|
}
|
73
|
/**
|
74
|
*
|
75
|
* @return
|
76
|
*/
|
77
|
@Override
|
78
|
protected ILabelProvider createListLabelProvider() {
|
79
|
return new FilteredCdmResourceAbbrevLabelProvider();
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* <p>select</p>
|
84
|
*
|
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.
|
89
|
*/
|
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);
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* <p>getTitle</p>
|
99
|
*
|
100
|
* @param cdmObject a T object.
|
101
|
* @return a {@link java.lang.String} object.
|
102
|
*/
|
103
|
@Override
|
104
|
protected String getTitle(AgentBase cdmObject) {
|
105
|
if(cdmObject == null){
|
106
|
return "";
|
107
|
}
|
108
|
|
109
|
if (cdmObject instanceof TeamOrPersonBase) {
|
110
|
return ((TeamOrPersonBase) cdmObject).getNomenclaturalTitle();
|
111
|
} else if (cdmObject instanceof AgentBase){
|
112
|
return ((TeamOrPersonBase) cdmObject).getTitleCache();
|
113
|
}
|
114
|
|
115
|
throw new IllegalArgumentException("Generic method only" +
|
116
|
" supports cdmObject of type IIdentifiableEntity." +
|
117
|
" Please implement specific method in subclass.");
|
118
|
}
|
119
|
|
120
|
|
121
|
|
122
|
public class FilteredCdmResourceAbbrevLabelProvider extends LabelProvider {
|
123
|
@Override
|
124
|
public String getText(Object element) {
|
125
|
if (element == null) {
|
126
|
return null;
|
127
|
}
|
128
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
|
129
|
String titleCache = uuidAndTitleCache.getTitleCache();
|
130
|
String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
|
131
|
if (!titleCache.equals(abbrevTitleCache)){
|
132
|
abbrevTitleCache += " - " + titleCache;
|
133
|
}
|
134
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
|
135
|
abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
|
136
|
}
|
137
|
return abbrevTitleCache;
|
138
|
}
|
139
|
};
|
140
|
|
141
|
/** {@inheritDoc} */
|
142
|
// @Override
|
143
|
// protected ItemsFilter createFilter() {
|
144
|
// return new ItemsFilter() {
|
145
|
//
|
146
|
// /**
|
147
|
// * Always returns false to enforce refiltering even if the pattern is equal
|
148
|
// */
|
149
|
// @Override
|
150
|
// public boolean equalsFilter(ItemsFilter filter) {
|
151
|
// return false;
|
152
|
// }
|
153
|
//
|
154
|
// @Override
|
155
|
// public boolean isConsistentItem(Object item) {
|
156
|
// return false;
|
157
|
// }
|
158
|
//
|
159
|
// @Override
|
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();
|
166
|
// }
|
167
|
// if (((UuidAndTitleCache) item).getTitleCache() != null ){
|
168
|
// textTitleCache = ((UuidAndTitleCache) item).getTitleCache();
|
169
|
// }
|
170
|
// }else if(item instanceof String){
|
171
|
// textTitleCache = (String) item;
|
172
|
// }
|
173
|
//
|
174
|
// return (matches(textTitleCache) || matches(abbrevTitleCache)) ;
|
175
|
//
|
176
|
// }
|
177
|
//
|
178
|
// };
|
179
|
// }
|
180
|
|
181
|
@Override
|
182
|
protected Comparator getItemsComparator() {
|
183
|
return new Comparator<UuidAndTitleCache>() {
|
184
|
@Override
|
185
|
public int compare(UuidAndTitleCache entity1,
|
186
|
UuidAndTitleCache entity2) {
|
187
|
|
188
|
if (entity1.getUuid().equals(entity2.getUuid())){
|
189
|
return 0;
|
190
|
}
|
191
|
Collator collator = Collator.getInstance();
|
192
|
String compareString1 = "";
|
193
|
if (entity1.getAbbrevTitleCache() != null){
|
194
|
compareString1 = entity1.getAbbrevTitleCache();
|
195
|
}
|
196
|
if (entity1.getTitleCache() != null){
|
197
|
compareString1 += entity1.getTitleCache();
|
198
|
}
|
199
|
|
200
|
|
201
|
String compareString2 = "";
|
202
|
if (entity2.getAbbrevTitleCache() != null){
|
203
|
compareString2 = entity2.getAbbrevTitleCache();
|
204
|
}
|
205
|
if (entity2.getTitleCache() != null){
|
206
|
compareString2 += entity2.getTitleCache();
|
207
|
}
|
208
|
|
209
|
|
210
|
int result =collator.compare(compareString1, compareString2);
|
211
|
if (result == 0){
|
212
|
result = entity1.getUuid().compareTo(entity2.getUuid());
|
213
|
}
|
214
|
return result;
|
215
|
}
|
216
|
};
|
217
|
}
|
218
|
|
219
|
|
220
|
}
|