Field-Decorators with Field-Assists
26. January 2007
Since Eclipse 3.2 JFace provides a possibility to decorate your Controls. That means you can add small icons and messages to your control to give the user a feedback of the expected input. Especially for applications that are designed for a wide range of end-users with different skills, it's an elegant way holding the users hand while guiding him through different forms. The additional capability of field-assists makes it very easy to improve the handling of your application. In this article an example is shown how to decorate a text-control and adding a simple filed assist.
Based on the field-assist example from eclipse I tried to encapsulate some functionalities regarding the field-decoration. The important classes are org.eclipse.jface.fieldassist.DecoratedField and org.eclipse.jface.fieldassist.FieldDecoration.
Creating the control
-
final DecoratedField field = new DecoratedField(parent, SWT.BORDER, new TextControlCreator());
Adding a decoration
-
final FieldDecoration decoration = new FieldDecoration(myImage, myDescription);
-
field.addFieldDecoration(decoration, SWT.TOP | SWT.LEFT, true);
-
field.showDecoration(decoration);
As you can see it's straight forward. For the background-colors of your controls you can use the following functions:
-
FieldAssistColors.computeErrorFieldBackgroundRGB(this.field.getControl());
-
FieldAssistColors.getRequiredFieldBackgroundColor(this.field.getControl());
The result will look like

I've written a small wrapper for such behavior that makes it easier to integrate this feature in your application. Just download the Java Files and integrate it in your project.



In Eclipse 3.3 this stuff seems to be deprecated. Do you know how to use it Iere?
Comment by matthias — 5. September 2007 @ 13:40
You can checkout and consult the fieldassist example at org.eclipse.ui.examples.fieldassist
It’s code should be taught at eclipse courses.
Comment by tkotisis — 17. January 2008 @ 15:21