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.core.runtime.Assert;
|
17
|
import org.eclipse.core.runtime.ListenerList;
|
18
|
import org.eclipse.jface.viewers.IColorProvider;
|
19
|
import org.eclipse.jface.viewers.IFontProvider;
|
20
|
import org.eclipse.jface.viewers.ILabelDecorator;
|
21
|
import org.eclipse.jface.viewers.ILabelProvider;
|
22
|
import org.eclipse.jface.viewers.ILabelProviderListener;
|
23
|
import org.eclipse.jface.viewers.LabelProvider;
|
24
|
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
|
25
|
import org.eclipse.jface.viewers.StyledCellLabelProvider;
|
26
|
import org.eclipse.jface.viewers.StyledString;
|
27
|
import org.eclipse.jface.viewers.ViewerCell;
|
28
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
29
|
import org.eclipse.swt.SWT;
|
30
|
import org.eclipse.swt.graphics.Color;
|
31
|
import org.eclipse.swt.graphics.Font;
|
32
|
import org.eclipse.swt.graphics.GC;
|
33
|
import org.eclipse.swt.graphics.Image;
|
34
|
import org.eclipse.swt.graphics.Rectangle;
|
35
|
import org.eclipse.swt.widgets.Control;
|
36
|
import org.eclipse.swt.widgets.Display;
|
37
|
import org.eclipse.swt.widgets.Shell;
|
38
|
import org.eclipse.swt.widgets.Text;
|
39
|
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
|
40
|
import org.eclipse.ui.internal.WorkbenchImages;
|
41
|
|
42
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
43
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
44
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
45
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
46
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
47
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
48
|
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
|
49
|
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
|
50
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
51
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
52
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
53
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.FilteredCdmResourceLabelProvider;
|
54
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsFilter;
|
55
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsListSeparator;
|
56
|
|
57
|
/**
|
58
|
* @author k.luther
|
59
|
* @date 25.05.2016
|
60
|
*
|
61
|
*/
|
62
|
public class NomenclaturalAuthorSelectionDialog extends AgentSelectionDialog {
|
63
|
|
64
|
|
65
|
/**
|
66
|
* @param shell
|
67
|
* @param conversation
|
68
|
* @param title
|
69
|
* @param multi
|
70
|
* @param settings
|
71
|
* @param agent
|
72
|
*/
|
73
|
protected NomenclaturalAuthorSelectionDialog(Shell shell, ConversationHolder conversation, String title,
|
74
|
boolean multi, String settings, AgentBase agent, boolean teamMemberSelection) {
|
75
|
super(shell, conversation, title, multi, settings, agent, teamMemberSelection);
|
76
|
// TODO Auto-generated constructor stub
|
77
|
}
|
78
|
|
79
|
@Override
|
80
|
protected void initModel() {
|
81
|
Control control = getPatternControl();
|
82
|
String pattern = null;
|
83
|
if (control != null){
|
84
|
pattern = ((Text)control).getText();
|
85
|
}
|
86
|
|
87
|
model = CdmStore.getService(IAgentService.class).getUuidAndAbbrevTitleCache(limitOfInitialElements, pattern, null);
|
88
|
}
|
89
|
|
90
|
/** {@inheritDoc} */
|
91
|
@Override
|
92
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
93
|
if(TEAM.equals(parameter)){
|
94
|
return new NewTeamWizard(true);
|
95
|
}
|
96
|
else if(PERSON.equals(parameter)){
|
97
|
return new NewPersonWizard();
|
98
|
}
|
99
|
else{
|
100
|
throw new IllegalArgumentException("Could not determine the desired wizard.");
|
101
|
}
|
102
|
}
|
103
|
/**
|
104
|
*
|
105
|
* @return
|
106
|
*/
|
107
|
@Override
|
108
|
protected ILabelProvider createListLabelProvider() {
|
109
|
return new FilteredCdmResourceAbbrevLabelProvider();
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* <p>select</p>
|
114
|
*
|
115
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
116
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
117
|
* @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
118
|
* @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
|
119
|
*/
|
120
|
public static AgentBase select(Shell shell, ConversationHolder conversation, AgentBase entity, boolean teamMemberSelection) {
|
121
|
NomenclaturalAuthorSelectionDialog dialog = new NomenclaturalAuthorSelectionDialog(shell, conversation,
|
122
|
"Choose Agent", false, NomenclaturalAuthorSelectionDialog.class.getCanonicalName(), entity, teamMemberSelection);
|
123
|
return getSelectionFromDialog(dialog);
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* <p>getTitle</p>
|
128
|
*
|
129
|
* @param cdmObject a T object.
|
130
|
* @return a {@link java.lang.String} object.
|
131
|
*/
|
132
|
@Override
|
133
|
protected String getTitle(AgentBase cdmObject) {
|
134
|
if(cdmObject == null){
|
135
|
return "";
|
136
|
}
|
137
|
|
138
|
if (cdmObject instanceof TeamOrPersonBase) {
|
139
|
return ((TeamOrPersonBase) cdmObject).getNomenclaturalTitle();
|
140
|
} else if (cdmObject instanceof AgentBase){
|
141
|
return ((TeamOrPersonBase) cdmObject).getTitleCache();
|
142
|
}
|
143
|
|
144
|
throw new IllegalArgumentException("Generic method only" +
|
145
|
" supports cdmObject of type IIdentifiableEntity." +
|
146
|
" Please implement specific method in subclass.");
|
147
|
}
|
148
|
|
149
|
|
150
|
|
151
|
public class FilteredCdmResourceAbbrevLabelProvider extends LabelProvider {
|
152
|
@Override
|
153
|
public String getText(Object element) {
|
154
|
if (element == null) {
|
155
|
return null;
|
156
|
}
|
157
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
|
158
|
String titleCache = uuidAndTitleCache.getTitleCache();
|
159
|
String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
|
160
|
if (!titleCache.equals(abbrevTitleCache)){
|
161
|
abbrevTitleCache += " - " + titleCache;
|
162
|
}
|
163
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
|
164
|
abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
|
165
|
}
|
166
|
return abbrevTitleCache;
|
167
|
}
|
168
|
};
|
169
|
|
170
|
/** {@inheritDoc} */
|
171
|
@Override
|
172
|
protected ItemsFilter createFilter() {
|
173
|
return new ItemsFilter() {
|
174
|
|
175
|
/**
|
176
|
* Always returns false to enforce refiltering even if the pattern is equal
|
177
|
*/
|
178
|
@Override
|
179
|
public boolean equalsFilter(ItemsFilter filter) {
|
180
|
return false;
|
181
|
}
|
182
|
|
183
|
@Override
|
184
|
public boolean isConsistentItem(Object item) {
|
185
|
return false;
|
186
|
}
|
187
|
|
188
|
@Override
|
189
|
public boolean matchItem(Object item) {
|
190
|
String textTitleCache = null;
|
191
|
String abbrevTitleCache = null;
|
192
|
if(item instanceof UuidAndTitleCache){
|
193
|
if (((UuidAndTitleCache) item).getAbbrevTitleCache() != null){
|
194
|
abbrevTitleCache = ((UuidAndTitleCache) item).getAbbrevTitleCache();
|
195
|
}
|
196
|
if (((UuidAndTitleCache) item).getTitleCache() != null ){
|
197
|
textTitleCache = ((UuidAndTitleCache) item).getTitleCache();
|
198
|
}
|
199
|
}else if(item instanceof String){
|
200
|
textTitleCache = (String) item;
|
201
|
}
|
202
|
|
203
|
return (matches(textTitleCache) || matches(abbrevTitleCache)) ;
|
204
|
|
205
|
}
|
206
|
|
207
|
};
|
208
|
}
|
209
|
|
210
|
@Override
|
211
|
protected Comparator getItemsComparator() {
|
212
|
return new Comparator<UuidAndTitleCache>() {
|
213
|
@Override
|
214
|
public int compare(UuidAndTitleCache entity1,
|
215
|
UuidAndTitleCache entity2) {
|
216
|
Collator collator = Collator.getInstance();
|
217
|
String compareString1 = "";
|
218
|
if (entity1.getAbbrevTitleCache() != null){
|
219
|
compareString1 = entity1.getAbbrevTitleCache();
|
220
|
}
|
221
|
if (entity1.getTitleCache() != null){
|
222
|
compareString1 += entity1.getTitleCache();
|
223
|
}
|
224
|
|
225
|
|
226
|
String compareString2 = "";
|
227
|
if (entity2.getAbbrevTitleCache() != null){
|
228
|
compareString2 = entity2.getAbbrevTitleCache();
|
229
|
}
|
230
|
if (entity2.getTitleCache() != null){
|
231
|
compareString2 += entity2.getTitleCache();
|
232
|
}
|
233
|
|
234
|
|
235
|
return collator.compare(compareString1, compareString2);
|
236
|
}
|
237
|
};
|
238
|
}
|
239
|
|
240
|
|
241
|
}
|