Repository navigation
TODO: Update for 0.3
The GUI module(s) is responsible for creating the widgets needed to visually represent the attributes, and to act as a bridge between 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?).
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 specify witch component should be used by the attribute.
There are a lot of configurations available. They are done through the JfgFormData class. Its parameters are:
EDIT: For 0.3 use data.config(TestClass.class.getName() + ".name").xyz
Allows an easy way to set which widget to use for a field. For ex:
data.fieldTypes.put(TestClass.class.getName() + ".name", "password");
Allows an easy way to hide fields. For ex:
data.fieldsToHide.add(TestClass.class.getName() + ".name");
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 recursively enter the inside object.
Each group is displayed as a frame inside the dialog.
This object is responsible 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.
If read-only fields should be shown.
Default: no
If the widgets should be updated when the model changes. This only works if the attribute(s) allow listeners.
Default: yes
Which strategy should be used to update the model. Can be one of:
NeverUpdateOnGuiChangeBufferUpdatesForTimeoutUpdateAfterFieldStoppedChangingUpdateAfterAllFieldsStoppedChanging
Time to update the model. The meaning depends on the selection of modelUpdateStrategy
If fields with changes that were not yet copied to the model should be marked visually (normally changing the background color)
Maps which SWTWidgetBuilder will be used given an attribute type.
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 default, as the above one.
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 default, as a similar to the above one.
Allows to set a factory for the SWT widgets