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