I created a new viewer that I think may be really useful. I’m writing this post to provide a high-level description. You can use it as follows:
final TokenViewer tokenViewer = new TokenViewer(root);
tokenViewer.getControl().setLayoutData(
new GridData(GridData.FILL_HORIZONTAL));
tokenViewer.setContentProvider(new BaseWorkbenchContentProvider());
tokenViewer.setLabelProvider(new WorkbenchLabelProvider());
tokenViewer.setInput(workspaceRoot);
The result is a simple text field with following services:
- Content assist.
- Object-oriented IStructuredSelection support – if the user enters proper string the selection event is thrown. If user sets selection – string will appear in the text entry.
- Easy and familiar programming model – I guess any JFace/Eclipse plugin developer wrote dozens of those label/content providers.

TokenViewer working with workspace
This simple API works for the case when text in the text field is the same as a label in the content assist pop-up. But once you want to have different text (i.e. SSN entry may show employee name in the pop-up) you will need something more specific for this task and that is why I defined special content provider (I still hope it is easier to use then regular JFace content assist API):
public interface ITokenContentProvider extends IStructuredContentProvider {
Object fromString(Object parent, String value);
String toString(Object object);
Object[] getChildren(Object object, String prefix);
}
- fromString method will return a child of the given parent node that corresponds to a specific string. It may return null.
- toString will convert given object to its string representation.
- getChildren tries to find all the elements that correspond to given string.
If the viewer is provided with IStructuredContentProvider (or ITreeContentProvider) it will wrap it with a custom adapter so you can use your existing code.
The label provider is used to decorate the content assist pop-up. I also have a slightly extended label provider interface:
public interface IDescriptionProvider extends ILabelProvider {
public String getDescription(Object element);
}
This optional extension provides the way to provide extended object descriptions that are shown along the content assist pop-up:

This is also a tokenviewer
Note – red squiggles are automatically shown when there is no object that corresponds to a text.
What I’m going to implement next is:
- Multiple selection support when token list is separated with some delimeter.
- Rich text (HTML?) support both for content assist pop-up and description pop-up.