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