Revision df366db5
Added by Katja Luther about 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmEnumSelectionDialog.java | ||
---|---|---|
49 | 49 |
|
50 | 50 |
private ConversationHolder conversation; |
51 | 51 |
|
52 |
protected List<T> model;
|
|
53 |
private String settings;
|
|
54 |
|
|
55 |
|
|
56 |
|
|
52 |
protected List<T> model; |
|
53 |
private String settings; |
|
54 |
|
|
55 |
|
|
56 |
|
|
57 | 57 |
/** |
58 | 58 |
* <p>Constructor for AbstractFilteredCdmResourceSelectionDialog.</p> |
59 | 59 |
* |
60 | 60 |
* @param shell a {@link org.eclipse.swt.widgets.Shell} object. |
61 |
* @param conversation
|
|
61 |
* @param conversation |
|
62 | 62 |
* @param title a {@link java.lang.String} object. |
63 | 63 |
* @param multi a boolean. |
64 | 64 |
* @param settings a {@link java.lang.String} object. |
65 | 65 |
* @param cdmEnum a T object. |
66 | 66 |
* @param <T> a T object. |
67 | 67 |
*/ |
68 |
protected AbstractFilteredCdmEnumSelectionDialog(Shell shell,
|
|
69 |
ConversationHolder conversation,
|
|
70 |
String title,
|
|
71 |
boolean multi,
|
|
68 |
protected AbstractFilteredCdmEnumSelectionDialog(Shell shell, |
|
69 |
ConversationHolder conversation, |
|
70 |
String title, |
|
71 |
boolean multi, |
|
72 | 72 |
String settings, |
73 | 73 |
T cdmEnum) { |
74 | 74 |
super(shell, multi); |
75 | 75 |
setTitle(title); |
76 | 76 |
setMessage("Use * for wildcard, or ? to see all entries"); |
77 | 77 |
this.settings = settings; |
78 |
|
|
78 |
|
|
79 | 79 |
this.conversation = conversation; |
80 |
|
|
80 |
|
|
81 | 81 |
init(); |
82 |
|
|
82 |
|
|
83 | 83 |
initModel(); |
84 |
|
|
84 |
|
|
85 | 85 |
String objectTitle = getTitle(cdmEnum); |
86 | 86 |
if (objectTitle != null) { |
87 | 87 |
setInitialPattern(objectTitle); |
88 | 88 |
} |
89 |
|
|
89 |
|
|
90 | 90 |
setListLabelProvider(createListLabelProvider()); |
91 | 91 |
setDetailsLabelProvider(createDetailsLabelProvider()); |
92 |
|
|
92 |
|
|
93 | 93 |
setSelectionHistory(new ResourceSelectionHistory()); |
94 | 94 |
} |
95 |
|
|
95 |
|
|
96 | 96 |
/** |
97 | 97 |
* By default, we are returning the standard list label provider |
98 |
*
|
|
99 |
* Override in subclasses if you want different behavior
|
|
100 |
*
|
|
98 |
* |
|
99 |
* Override in subclasses if you want different behavior |
|
100 |
* |
|
101 | 101 |
* @return |
102 | 102 |
*/ |
103 | 103 |
protected ILabelProvider createDetailsLabelProvider() { |
... | ... | |
105 | 105 |
} |
106 | 106 |
|
107 | 107 |
/** |
108 |
*
|
|
108 |
* |
|
109 | 109 |
* @return |
110 | 110 |
*/ |
111 | 111 |
protected ILabelProvider createListLabelProvider() { |
... | ... | |
117 | 117 |
* Will run before initModel() |
118 | 118 |
*/ |
119 | 119 |
protected void init() { |
120 |
|
|
120 |
|
|
121 | 121 |
} |
122 |
|
|
122 |
|
|
123 | 123 |
/** |
124 | 124 |
* <p>getSelectionFromDialog</p> |
125 | 125 |
* |
... | ... | |
128 | 128 |
* @return a TYPE object. |
129 | 129 |
*/ |
130 | 130 |
protected static <TYPE extends IEnumTerm> TYPE getSelectionFromDialog(AbstractFilteredCdmEnumSelectionDialog<TYPE> dialog) { |
131 |
|
|
131 |
|
|
132 | 132 |
int result = dialog.open(); |
133 |
|
|
133 |
|
|
134 | 134 |
if (result == Window.CANCEL) { |
135 | 135 |
return null; |
136 | 136 |
} |
137 |
|
|
137 |
|
|
138 | 138 |
return dialog.getSelectedEnumTerm(); |
139 | 139 |
} |
140 | 140 |
|
... | ... | |
148 | 148 |
protected String getTitle(T cdmEnum) { |
149 | 149 |
return cdmEnum.getMessage(); |
150 | 150 |
} |
151 |
|
|
151 |
|
|
152 | 152 |
|
153 | 153 |
/** {@inheritDoc} */ |
154 | 154 |
@Override |
155 | 155 |
public void refresh() { |
156 |
initModel();
|
|
156 |
initModel(); |
|
157 | 157 |
super.refresh(); |
158 | 158 |
} |
159 |
|
|
159 |
|
|
160 | 160 |
/** |
161 | 161 |
* <p>initModel</p> |
162 | 162 |
*/ |
... | ... | |
177 | 177 |
public boolean equalsFilter(ItemsFilter filter) { |
178 | 178 |
return false; |
179 | 179 |
} |
180 |
|
|
180 |
|
|
181 | 181 |
@Override |
182 | 182 |
public boolean isConsistentItem(Object item) { |
183 | 183 |
return false; |
... | ... | |
193 | 193 |
} |
194 | 194 |
return text != null ? matches(text) : false; |
195 | 195 |
} |
196 |
|
|
196 |
|
|
197 | 197 |
}; |
198 | 198 |
} |
199 |
|
|
199 |
|
|
200 | 200 |
|
201 | 201 |
/** |
202 | 202 |
* Set the filter input to the Agent's title cache |
... | ... | |
204 | 204 |
* @param cdmObject a T object. |
205 | 205 |
*/ |
206 | 206 |
protected void setPattern(T cdmObject) { |
207 |
// FilteredSelection does some very tricky caching to make sure it
|
|
208 |
// runs with high performance.
|
|
207 |
// FilteredSelection does some very tricky caching to make sure it |
|
208 |
// runs with high performance. |
|
209 | 209 |
// This works for most use cases, but we want to change the model while the dialog is open |
210 | 210 |
// and all the clever caching prevents the content provider from knowing that the model has changed |
211 |
// I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient
|
|
211 |
// I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient |
|
212 | 212 |
// way to solve the problem. |
213 | 213 |
try { |
214 | 214 |
Field lastCompletedFilter = this.getClass().getSuperclass().getSuperclass().getDeclaredField("lastCompletedFilter"); |
... | ... | |
223 | 223 |
} catch (IllegalAccessException e) { |
224 | 224 |
MessagingUtils.error(getClass(), e); |
225 | 225 |
} |
226 |
|
|
227 |
// this also is not the nicest way to do it.
|
|
226 |
|
|
227 |
// this also is not the nicest way to do it. |
|
228 | 228 |
// I am still amazed, that FilteredSelectionDialog does not offer any methods to change its data |
229 | 229 |
// once it was opened. Am I doing it wrong? |
230 | 230 |
String pattern = getTitle(cdmObject); |
231 | 231 |
((Text) getPatternControl()).setText(pattern); |
232 | 232 |
} |
233 |
|
|
233 |
|
|
234 | 234 |
/* (non-Javadoc) |
235 | 235 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor) |
236 | 236 |
*/ |
... | ... | |
240 | 240 |
ItemsFilter itemsFilter, IProgressMonitor progressMonitor) |
241 | 241 |
throws CoreException { |
242 | 242 |
try { |
243 |
if(model != null){
|
|
243 |
if(model != null){ |
|
244 | 244 |
progressMonitor.beginTask("Looking for entities", model.size()); |
245 | 245 |
for(T element : model){ |
246 | 246 |
contentProvider.add(element, itemsFilter); |
... | ... | |
288 | 288 |
@Override |
289 | 289 |
protected Comparator getItemsComparator() { |
290 | 290 |
return new Comparator<IEnumTerm>() { |
291 |
public int compare(IEnumTerm entity1, |
|
291 |
@Override |
|
292 |
public int compare(IEnumTerm entity1, |
|
292 | 293 |
IEnumTerm entity2) { |
293 |
Collator collator = Collator.getInstance(); |
|
294 |
return collator.compare(entity1.getMessage(), entity2.getMessage()); |
|
294 |
if (entity1.equals(entity2)){ |
|
295 |
return 0; |
|
296 |
} |
|
297 |
Collator collator = Collator.getInstance(); |
|
298 |
|
|
299 |
int result = collator.compare(entity1.getMessage(), entity2.getMessage()); |
|
300 |
if (result == 0){ |
|
301 |
return entity1.getUuid().compareTo(entity2.getUuid()); |
|
302 |
} |
|
303 |
return result; |
|
295 | 304 |
} |
296 | 305 |
}; |
297 | 306 |
} |
... | ... | |
304 | 313 |
protected IStatus validateItem(Object item) { |
305 | 314 |
return Status.OK_STATUS; |
306 | 315 |
} |
307 |
|
|
316 |
|
|
308 | 317 |
/** |
309 | 318 |
* <p>getSelectedUuidAndTitleCache</p> |
310 | 319 |
* |
... | ... | |
314 | 323 |
Object[] result = getResult(); |
315 | 324 |
return result[0] == null ? null : (T) result[0]; |
316 | 325 |
} |
317 |
|
|
326 |
|
|
318 | 327 |
/** |
319 | 328 |
* <p>Getter for the field <code>settings</code>.</p> |
320 | 329 |
* |
... | ... | |
326 | 335 |
} |
327 | 336 |
return settings; |
328 | 337 |
} |
329 |
|
|
338 |
|
|
330 | 339 |
/** |
331 |
*
|
|
340 |
* |
|
332 | 341 |
* @author n.hoffmann |
333 | 342 |
* @created Oct 19, 2009 |
334 | 343 |
* @version 1.0 |
... | ... | |
337 | 346 |
/* |
338 | 347 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#restoreItemFromMemento(org.eclipse.ui.IMemento) |
339 | 348 |
*/ |
340 |
protected Object restoreItemFromMemento(IMemento element) { |
|
349 |
@Override |
|
350 |
protected Object restoreItemFromMemento(IMemento element) { |
|
341 | 351 |
return element.getString("resource"); //$NON-NLS-1$ |
342 | 352 |
} |
343 | 353 |
/* |
344 | 354 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#storeItemToMemento(java.lang.Object, |
345 | 355 |
* org.eclipse.ui.IMemento) |
346 | 356 |
*/ |
347 |
protected void storeItemToMemento(Object item, IMemento element) { |
|
357 |
@Override |
|
358 |
protected void storeItemToMemento(Object item, IMemento element) { |
|
348 | 359 |
element.putString("resource", item.toString()); //$NON-NLS-1$ |
349 | 360 |
} |
350 | 361 |
} |
351 |
|
|
362 |
|
|
352 | 363 |
/** |
353 | 364 |
* <p>getNewWizardLinkText</p> |
354 | 365 |
* |
355 | 366 |
* @return a {@link java.lang.String} object. |
356 | 367 |
*/ |
357 | 368 |
protected abstract String getNewWizardLinkText(); |
358 |
|
|
369 |
|
|
359 | 370 |
/** |
360 | 371 |
* <p>getNewEntityWizard</p> |
361 |
* @param parameter
|
|
372 |
* @param parameter |
|
362 | 373 |
* @return a {@link eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard} object. |
363 | 374 |
*/ |
364 | 375 |
protected abstract AbstractNewEntityWizard getNewEntityWizard(String parameter); |
365 |
|
|
376 |
|
|
366 | 377 |
public class FilteredCdmResourceLabelProvider extends LabelProvider { |
367 |
public String getText(Object element) { |
|
378 |
@Override |
|
379 |
public String getText(Object element) { |
|
368 | 380 |
if (element == null) { |
369 | 381 |
return null; |
370 | 382 |
} |
371 | 383 |
return ((IEnumTerm) element).getMessage(); |
372 |
}
|
|
384 |
} |
|
373 | 385 |
}; |
374 | 386 |
|
375 | 387 |
/* (non-Javadoc) |
... | ... | |
386 | 398 |
} |
387 | 399 |
return null; |
388 | 400 |
} |
389 |
|
|
401 |
|
|
390 | 402 |
protected SelectionListener getNewWizardLinkSelectionListener(){ |
391 | 403 |
return new SelectionAdapter() { |
392 |
|
|
404 |
|
|
393 | 405 |
/* (non-Javadoc) |
394 | 406 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
395 | 407 |
*/ |
396 | 408 |
@Override |
397 | 409 |
public void widgetSelected(SelectionEvent e) { |
398 |
|
|
410 |
|
|
399 | 411 |
AbstractNewEntityWizard wizard = getNewEntityWizard(e.text); |
400 | 412 |
wizard.init(null, null); |
401 | 413 |
WizardDialog dialog = new WizardDialog(getShell(), wizard); |
402 | 414 |
int status = dialog.open(); |
403 |
|
|
415 |
|
|
404 | 416 |
if (status == IStatus.OK) { |
405 |
|
|
417 |
|
|
406 | 418 |
T entity = (T) wizard.getEntity(); |
407 | 419 |
|
408 | 420 |
refresh(); |
... | ... | |
412 | 424 |
} |
413 | 425 |
}; |
414 | 426 |
} |
415 |
|
|
427 |
|
|
416 | 428 |
/** |
417 | 429 |
* <p>getConversationHolder</p> |
418 | 430 |
* |
419 | 431 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
420 | 432 |
*/ |
421 |
public ConversationHolder getConversationHolder() { |
|
433 |
@Override |
|
434 |
public ConversationHolder getConversationHolder() { |
|
422 | 435 |
return conversation; |
423 | 436 |
} |
424 |
|
|
437 |
|
|
425 | 438 |
/** {@inheritDoc} */ |
426 |
public void update(CdmDataChangeMap changeEvents) {} |
|
439 |
@Override |
|
440 |
public void update(CdmDataChangeMap changeEvents) {} |
|
427 | 441 |
|
428 | 442 |
} |
Also available in: Unified diff
ref #4232: some more comparators to adapt