In a previous tip, you have seen various Selection Dialogs in Eclipse. One thing which was not explained in it was FilteredItemsSelectionDialog, as it deserves a tip on its own. In this tip, I'll explain how to extend that class.
The Open Resource Dialog and Open Type Dialog are the ones you might be using very frequently. They are subclasses of FilteredItemsSelectionDialog. The dialog looks like this:
Lets see what does it makes to create a simple dialog like this which allows us to select some Persons. First step is to extend the FilteredItemsSelectionDialog:
When you have hundreds of thousands of items, adding it to the list up front is a huge task. So ideally, what happens is the dialog is displayed first and then the fillContentProvider is called when the user starts typing. (Or if you have specified the initial pattern, then its called as soon as the dialog is displayed to the user). For the sake of simplicity, I'm passing in all the items in the constructor and adding them to the contentProvider in the loop. This can't happen if the number of items is huge. Ideally you can specify the place where to search for thru the constructor and in the fillContentProvider, you start searching for all the items and add them. The progress will be shown below the search text box.
Apart from this FilteredPersonsSelectionDialog class, you would need few helper classes. The first one is the filter class, which should extend ItemFilter. This decides how to filter the items with the query provided in the search text box. You can decide on the wildcard strings, whether CamelCase searching is allowed etc.
The next one is related to the history. The FilteredItemsSelectionDialog can remember the selection from the previous searches. To enable that, you need to extend the SelectionHistory and set it as we have did it in the line number 10. You need to override the abstract methods in the SelectionHistory to store & restore the item from the memento. The location where the memento saved into is dictated by the getDialogSettings().
The last set of classes are the LabelProviders. You need two of them. One for displaying in the list and the other for displaying in the details area, which should ideally provide more information than the first one.
Now the last bit of info. Invoking this dialog: