package eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection;
+import java.lang.reflect.Field;
+import java.security.acl.LastOwnerException;
import java.text.Collator;
import java.util.Comparator;
import java.util.HashSet;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
setListLabelProvider(labelProvider);
setDetailsLabelProvider(labelProvider);
-// setSelectionHistory(new ResourceSelectionHistory());
+ setSelectionHistory(new ResourceSelectionHistory());
}
/**
- * Override in suibclasses.
+ * Override in subclasses.
* Will run before initModel()
*/
protected void init() {
}
-
+
/**
* <p>getSelectionFromDialog</p>
*
* @return a TYPE object.
*/
protected static <TYPE extends CdmBase> TYPE getSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog<TYPE> dialog) {
- if (dialog.open() == Window.CANCEL) {
+ //dialog.setInitialPattern("");
+ int result = dialog.open();
+
+ if (result == Window.CANCEL) {
return null;
}
}
return null;
}
+
/** {@inheritDoc} */
@Override
protected ItemsFilter createFilter() {
return new ItemsFilter() {
+ /**
+ * Always returns false to enforce refiltering even if the pattern is equal
+ */
+ @Override
+ public boolean equalsFilter(ItemsFilter filter) {
+ return false;
+ }
+
@Override
public boolean isConsistentItem(Object item) {
return false;
* @param cdmObject a T object.
*/
protected void setPattern(T cdmObject) {
+ // FilteredSelection does some very tricky caching to make sure it
+ // runs with high performance.
+ // This works for most use cases, but we want to change the model while the dialog is open
+ // and all the clever caching prevents the content provider from knowing that the model has changed
+ // I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient
+ // way to solve the problem.
+ try {
+ Field lastCompletedFilter = this.getClass().getSuperclass().getSuperclass().getDeclaredField("lastCompletedFilter");
+ lastCompletedFilter.setAccessible(true);
+ lastCompletedFilter.set(this, null);
+ } catch (SecurityException e) {
+ StoreUtil.error(getClass(), e);
+ } catch (NoSuchFieldException e) {
+ StoreUtil.error(getClass(), e);
+ } catch (IllegalArgumentException e) {
+ StoreUtil.error(getClass(), e);
+ } catch (IllegalAccessException e) {
+ StoreUtil.error(getClass(), e);
+ }
+
+ // this also is not the nicest way to do it.
+ // I am still amazed, that FilteredSelectionDialog does not offer any methods to change its data
+ // once it was opened. Am I doing it wrong?
((Text) getPatternControl()).setText(getTitle(cdmObject));
}