Revision d41c6a72
Added by Katja Luther over 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java | ||
---|---|---|
21 | 21 |
import org.eclipse.core.runtime.IProgressMonitor; |
22 | 22 |
import org.eclipse.core.runtime.IStatus; |
23 | 23 |
import org.eclipse.core.runtime.OperationCanceledException; |
24 |
import org.eclipse.core.runtime.Status; |
|
25 | 24 |
import org.eclipse.jface.dialogs.IDialogSettings; |
26 | 25 |
import org.eclipse.jface.viewers.ILabelProvider; |
27 | 26 |
import org.eclipse.jface.viewers.LabelProvider; |
27 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
28 | 28 |
import org.eclipse.jface.window.Window; |
29 | 29 |
import org.eclipse.jface.wizard.WizardDialog; |
30 | 30 |
import org.eclipse.swt.SWT; |
... | ... | |
36 | 36 |
import org.eclipse.swt.widgets.Control; |
37 | 37 |
import org.eclipse.swt.widgets.Link; |
38 | 38 |
import org.eclipse.swt.widgets.Shell; |
39 |
import org.eclipse.swt.widgets.Text; |
|
40 |
import org.eclipse.ui.IMemento; |
|
41 | 39 |
|
42 | 40 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
43 | 41 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
... | ... | |
46 | 44 |
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity; |
47 | 45 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
48 | 46 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
47 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
|
49 | 48 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
50 | 49 |
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard; |
51 | 50 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
... | ... | |
60 | 59 |
* @version 1.0 |
61 | 60 |
*/ |
62 | 61 |
public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmBase> extends |
63 |
CdmFilteredItemsSelectionDialog implements IConversationEnabled {
|
|
62 |
SearchDialog implements IConversationEnabled {
|
|
64 | 63 |
|
65 | 64 |
private final ConversationHolder conversation; |
66 | 65 |
|
... | ... | |
69 | 68 |
private final String settings; |
70 | 69 |
protected final int limitOfInitialElements = 100; |
71 | 70 |
|
71 |
private T selectedObject; |
|
72 |
|
|
72 | 73 |
protected T cdmBaseToBeFiltered; |
73 | 74 |
|
74 | 75 |
|
... | ... | |
85 | 86 |
*/ |
86 | 87 |
protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, String settings, T cdmObject) { |
87 | 88 |
super(shell, multi); |
89 |
setShellStyle(SWT.DIALOG_TRIM); |
|
88 | 90 |
setTitle(title); |
89 |
setMessage("Use * for wildcard, or ? to see all entries");
|
|
91 |
setMessage(Messages.SearchDialog_patternLabel);
|
|
90 | 92 |
this.settings = settings; |
91 | 93 |
|
92 | 94 |
this.conversation = conversation; |
... | ... | |
94 | 96 |
Cursor cursor = shell.getCursor(); |
95 | 97 |
shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); |
96 | 98 |
init(); |
97 |
// initModel(); |
|
98 | 99 |
shell.setCursor(cursor); |
99 |
String objectTitle = getTitle(cdmObject); |
|
100 |
// if (objectTitle != null) { |
|
101 |
// setInitialPattern(objectTitle); |
|
102 |
// } |
|
103 |
|
|
104 | 100 |
setListLabelProvider(createListLabelProvider()); |
105 |
setDetailsLabelProvider(createDetailsLabelProvider()); |
|
106 | 101 |
|
107 |
setSelectionHistory(new ResourceSelectionHistory()); |
|
108 | 102 |
} |
109 | 103 |
|
110 | 104 |
/** |
... | ... | |
142 | 136 |
* @return a TYPE object. |
143 | 137 |
*/ |
144 | 138 |
protected static <TYPE extends CdmBase> TYPE getSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog<TYPE> dialog) { |
145 |
//dialog.setInitialPattern(""); |
|
146 | 139 |
int result = dialog.open(); |
147 | 140 |
|
148 | 141 |
if (result == Window.CANCEL) { |
... | ... | |
180 | 173 |
*/ |
181 | 174 |
abstract protected T getPersistentObject(UUID uuid); |
182 | 175 |
|
183 |
/** |
|
184 |
* @param cdmObject |
|
185 |
*/ |
|
186 |
// protected void addObjectToModel(T cdmObject) { |
|
187 |
// model.add(new UuidAndTitleCache(cdmObject.getClass(), cdmObject.getUuid(), getTitle(cdmObject))); |
|
188 |
// transientCdmObjects.add(cdmObject); |
|
189 |
// } |
|
190 | 176 |
|
191 | 177 |
/** |
192 | 178 |
* <p>isObjectTransient</p> |
... | ... | |
227 | 213 |
|
228 | 214 |
|
229 | 215 |
|
230 |
/* (non-Javadoc) |
|
231 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter() |
|
232 |
*/ |
|
233 |
/** {@inheritDoc} */ |
|
234 |
@Override |
|
235 |
protected ItemsFilter createFilter() { |
|
236 |
return new ItemsFilter() { |
|
237 | 216 |
|
238 |
/** |
|
239 |
* Always returns false to enforce refiltering even if the pattern is equal |
|
240 |
*/ |
|
241 |
@Override |
|
242 |
public boolean equalsFilter(ItemsFilter filter) { |
|
243 |
return false; |
|
244 |
} |
|
245 |
|
|
246 |
@Override |
|
247 |
public boolean isConsistentItem(Object item) { |
|
248 |
return false; |
|
249 |
} |
|
250 |
|
|
251 |
@Override |
|
252 |
public boolean matchItem(Object item) { |
|
253 |
String text = null; |
|
254 |
if(item instanceof UuidAndTitleCache){ |
|
255 |
text = ((UuidAndTitleCache) item).getTitleCache(); |
|
256 |
}else if(item instanceof String){ |
|
257 |
text = (String) item; |
|
258 |
} |
|
259 |
return text != null ? matches(text) : false; |
|
260 |
} |
|
261 |
|
|
262 |
}; |
|
263 |
} |
|
264 | 217 |
|
265 | 218 |
|
266 | 219 |
/** |
... | ... | |
269 | 222 |
* @param cdmObject a T object. |
270 | 223 |
*/ |
271 | 224 |
protected void setPattern(T cdmObject) { |
272 |
// FilteredSelection does some very tricky caching to make sure it |
|
273 |
// runs with high performance. |
|
274 |
// This works for most use cases, but we want to change the model while the dialog is open |
|
275 |
// and all the clever caching prevents the content provider from knowing that the model has changed |
|
276 |
// I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient |
|
277 |
// way to solve the problem. |
|
278 |
// try { |
|
279 |
// Field lastCompletedFilter = this.getClass().getSuperclass().getSuperclass().getDeclaredField("lastCompletedFilter"); |
|
280 |
// lastCompletedFilter.setAccessible(true); |
|
281 |
// lastCompletedFilter.set(this, null); |
|
282 |
// } catch (SecurityException e) { |
|
283 |
// MessagingUtils.error(getClass(), e); |
|
284 |
// } catch (NoSuchFieldException e) { |
|
285 |
// MessagingUtils.error(getClass(), e); |
|
286 |
// } catch (IllegalArgumentException e) { |
|
287 |
// MessagingUtils.error(getClass(), e); |
|
288 |
// } catch (IllegalAccessException e) { |
|
289 |
// MessagingUtils.error(getClass(), e); |
|
290 |
// } |
|
291 |
|
|
292 |
// this also is not the nicest way to do it. |
|
293 |
// I am still amazed, that FilteredSelectionDialog does not offer any methods to change its data |
|
294 |
// once it was opened. Am I doing it wrong? |
|
295 | 225 |
String pattern = getTitle(cdmObject); |
296 |
((Text) getPatternControl()).setText(pattern);
|
|
226 |
getSearchField().setText(pattern);
|
|
297 | 227 |
} |
298 | 228 |
|
299 | 229 |
|
... | ... | |
302 | 232 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor) |
303 | 233 |
*/ |
304 | 234 |
/** {@inheritDoc} */ |
235 |
|
|
305 | 236 |
@Override |
306 |
protected void fillContentProvider(AbstractContentProvider contentProvider, |
|
307 |
ItemsFilter itemsFilter, IProgressMonitor progressMonitor) |
|
237 |
protected void fillContentProvider(IProgressMonitor progressMonitor) |
|
308 | 238 |
throws CoreException { |
309 | 239 |
try { |
310 | 240 |
if(model != null){ |
311 |
progressMonitor.beginTask("Looking for entities", model.size()); |
|
312 |
filterExcludedObjects(); |
|
241 |
if (progressMonitor != null){ |
|
242 |
progressMonitor.beginTask("Looking for entities", model.size()); |
|
243 |
} |
|
244 |
contentProvider.reset(); |
|
313 | 245 |
Iterator<UuidAndTitleCache<T>> iterator = model.iterator(); |
314 | 246 |
UuidAndTitleCache<T> element; |
315 | 247 |
while(iterator.hasNext()){ |
316 | 248 |
element = iterator.next(); |
317 | 249 |
if (!element.equals(cdmBaseToBeFiltered)){ |
318 |
contentProvider.add(element, itemsFilter); |
|
250 |
contentProvider.add(element); |
|
251 |
} |
|
252 |
if (progressMonitor != null){ |
|
253 |
if (progressMonitor.isCanceled()) { |
|
254 |
throw new OperationCanceledException(); |
|
255 |
} |
|
256 |
progressMonitor.worked(1); |
|
319 | 257 |
} |
320 |
if (progressMonitor.isCanceled()) { |
|
321 |
throw new OperationCanceledException(); |
|
322 |
} |
|
323 |
progressMonitor.worked(1); |
|
324 | 258 |
} |
259 |
this.refresh(); |
|
325 | 260 |
}else{ |
326 | 261 |
MessagingUtils.warn(getClass(), "Model for Filtered Selection is null:" + this.getClass().getSimpleName()); |
327 | 262 |
} |
328 | 263 |
} |
329 | 264 |
finally { |
330 |
progressMonitor.done(); |
|
265 |
if (progressMonitor != null) { |
|
266 |
progressMonitor.done(); |
|
267 |
} |
|
331 | 268 |
} |
332 | 269 |
} |
333 | 270 |
|
... | ... | |
335 | 272 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getDialogSettings() |
336 | 273 |
*/ |
337 | 274 |
/** {@inheritDoc} */ |
338 |
@Override |
|
275 |
|
|
339 | 276 |
protected IDialogSettings getDialogSettings() { |
340 | 277 |
IDialogSettings settings = TaxeditorStorePlugin.getDefault().getDialogSettings().getSection(getSettings()); |
341 | 278 |
|
... | ... | |
349 | 286 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getElementName(java.lang.Object) |
350 | 287 |
*/ |
351 | 288 |
/** {@inheritDoc} */ |
352 |
@Override |
|
289 |
|
|
353 | 290 |
public String getElementName(Object item) { |
354 | 291 |
return ((UuidAndTitleCache) item).getTitleCache(); |
355 | 292 |
} |
... | ... | |
358 | 295 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getItemsComparator() |
359 | 296 |
*/ |
360 | 297 |
/** {@inheritDoc} */ |
361 |
@Override |
|
298 |
|
|
362 | 299 |
protected Comparator getItemsComparator() { |
363 | 300 |
return new Comparator<UuidAndTitleCache>() { |
364 | 301 |
@Override |
... | ... | |
377 | 314 |
}; |
378 | 315 |
} |
379 | 316 |
|
380 |
/* (non-Javadoc) |
|
381 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#validateItem(java.lang.Object) |
|
382 |
*/ |
|
383 |
/** {@inheritDoc} */ |
|
384 |
@Override |
|
385 |
protected IStatus validateItem(Object item) { |
|
386 |
return Status.OK_STATUS; |
|
387 |
} |
|
388 | 317 |
|
389 | 318 |
/** |
390 | 319 |
* <p>getSelectedUuidAndTitleCache</p> |
... | ... | |
392 | 321 |
* @return a {@link eu.etaxonomy.cdm.model.common.UuidAndTitleCache} object. |
393 | 322 |
*/ |
394 | 323 |
protected UuidAndTitleCache getSelectedUuidAndTitleCache() { |
395 |
Object[] result = getResult(); |
|
396 |
return result[0] == null ? null : (UuidAndTitleCache) result[0]; |
|
324 |
Object result = getResult(); |
|
325 |
if (result instanceof UuidAndTitleCache){ |
|
326 |
return (UuidAndTitleCache) result; |
|
327 |
} |
|
328 |
return null; |
|
397 | 329 |
} |
398 | 330 |
|
399 | 331 |
/** |
332 |
* @return |
|
333 |
*/ |
|
334 |
private Object getResult() { |
|
335 |
StructuredSelection selection = getCurrentSelection(); |
|
336 |
return selection.getFirstElement(); |
|
337 |
} |
|
338 |
|
|
339 |
/** |
|
400 | 340 |
* <p>Getter for the field <code>settings</code>.</p> |
401 | 341 |
* |
402 | 342 |
* @return a {@link java.lang.String} object. |
... | ... | |
408 | 348 |
return settings; |
409 | 349 |
} |
410 | 350 |
|
411 |
/** |
|
412 |
* |
|
413 |
* @author n.hoffmann |
|
414 |
* @created Oct 19, 2009 |
|
415 |
* @version 1.0 |
|
416 |
*/ |
|
417 |
private class ResourceSelectionHistory extends SelectionHistory { |
|
418 |
/* |
|
419 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#restoreItemFromMemento(org.eclipse.ui.IMemento) |
|
420 |
*/ |
|
421 |
@Override |
|
422 |
protected Object restoreItemFromMemento(IMemento element) { |
|
423 |
return element.getString("resource"); //$NON-NLS-1$ |
|
424 |
} |
|
425 |
/* |
|
426 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#storeItemToMemento(java.lang.Object, |
|
427 |
* org.eclipse.ui.IMemento) |
|
428 |
*/ |
|
429 |
@Override |
|
430 |
protected void storeItemToMemento(Object item, IMemento element) { |
|
431 |
element.putString("resource", item.toString()); //$NON-NLS-1$ |
|
432 |
} |
|
433 |
} |
|
351 |
|
|
434 | 352 |
|
435 | 353 |
/** |
436 | 354 |
* <p>getNewWizardLinkText</p> |
... | ... | |
465 | 383 |
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite) |
466 | 384 |
*/ |
467 | 385 |
/** {@inheritDoc} */ |
386 |
|
|
468 | 387 |
@Override |
469 |
protected Control createExtendedContentArea(Composite parent) {
|
|
388 |
protected Control createExtendedContentArea(Composite parent) {
|
|
470 | 389 |
String newWizardLinkText = getNewWizardLinkText(); |
471 | 390 |
if(newWizardLinkText != null){ |
472 | 391 |
Link link = new Link(parent, SWT.NONE); |
... | ... | |
496 | 415 |
if (status == IStatus.OK) { |
497 | 416 |
|
498 | 417 |
T entity = (T) wizard.getEntity(); |
499 |
// model.add(new UuidAndTitleCache<T>(entity.getUuid(), entity.getId(), getTitle(entity))); |
|
500 | 418 |
refresh(); |
501 | 419 |
setPattern(entity); |
502 | 420 |
if (getConversationHolder() != null){ |
Also available in: Unified diff
selection dialogs does not use CdmFilteredItemsSelectionDialog anymore