My favorites | Sign in
Project Logo
jfg
                
Search
for
Updated Sep 17, 2008 by pescuma
GUI  
GUI explanation

GUI

The GUI module(s) is responsible for creating the widgets needed to visually represent the attributes, and to act as a bridge beetween then, updating the attribute when the widget changes and updating the widget as the attribute changes.

It fills the hole of the View and the Controller, but of course it is a very simple controller. I've yet to find a good way to put more logic inside the Controller part without making everything more complex.

The idea is that, for each type of widgets, there will be a package with the classes that handle it. For now only SWT classes were created, but in the future other mappings can be created for Swing, AWT, etc (maybe even web?).

SWT

The SWT module is seen by the world as one class: JfgFormComposite . This class extends a Composite and is able to create the widgets given the attributes. To fill the components you can call void addContentsFrom(AttributeGroup group) , which will add all attributes (that it can handle) inside itself. You can also call void add(Attribute attrib) for each attribute. There are also some addX if you want to expecify witch component should be used by the attribute.

There are a lot of configurations avaiable. They are done through the JfgFormData class. Its parameters are:

fieldTypes

Allows an easy way to set which widget to use for a field. For ex:

data.fieldTypes.put(TestClass.class.getName() + ".name", "password");

fieldsToHide

Allows an easy way to hide fields. For ex:

data.fieldsToHide.add(TestClass.class.getName() + ".name");

maxGroupAttributeLevels

Max number of levels that will be shown. A 'level' is a case when an attribute type can't be handled, but it can be accessed as a group, so its enter in the next level when looking inside the group.

If the attribute is based on reflection, this happens when an object has a field that the type is another object, so it can recursivelly enter the inside object.

Each group is displayed as a frame inside the dialog.

textTranslator

This object is responsable to translate the field/enum names to the text shown in the GUI. If you want do to i18n, this is the field that you have to look at.

showReadOnly

If read-only fields should ne shown.

Default: no

updateGuiWhenModelChanges

If the widgets should be updated when the model changes. This only works if the attribute(s) allow listeners.

Default: yes

modelUpdateStrategy

Which strategy should be used to update the model. Can be one of:

modelUpdateTimeout

Time to update the model. The meaning depends on the selection of modelUpdateStrategy

markFieldsWhithUncommitedChanges

If fields whith changes that were not yet copied to the model should be marked visually (normally changing the background color)

Advanced:

builders

Maps which SWTWidgetBuilder will be used given an attribute type.

builderTypeSelectors

Allows further customization of which "swt type" should be used for an attribute type. It allows you to do things like use a password field if the attribute has the text password inside :

builderTypeSelectors.add(new SWTBuilderTypeSelector() {
    public Object getTypeFor(Attribute attrib)
    {
            String name = getSimpleName(attrib).toLowerCase();
            
            if (name.indexOf("password") >= 0 || name.indexOf("passwd") >= 0)
                    return "password";
            
            return null;
    }
    
    private String getSimpleName(Attribute attrib)
    {
            String name = attrib.getName();
            int index = name.lastIndexOf('.');
                if (index >= 0 && index < name.length() - 1)
                        name = name.substring(index + 1);
                return name;
        }
});

PS: The getTypeFor have to return null if it don't want to handle the field.

Some selectors exists per defaut, as the above one.

attributeFilters

Allows to hide fields. For example, to hide read-only fields:

attributeFilters.add(new SWTAttributeFilter() {
    public boolean hideAttribute(Attribute attrib)
    {
            if (!attrib.canWrite())
                    return true;
            return false;
    }
});

Some filters exists per defaut, as a similar to the above one.

componentFactory

Allows to set a factory for the SWT widgets


Sign in to add a comment
Hosted by Google Code