Overview of Examples
FormBuilder frameworks comes with a set of examples that demonstrate the usage of pre-built form descriptions.
Basics
QuickstartD: load and access
To load a layout from a classpath resource you need to know the layoutID of the description - that's guaranteed to be the same as the filename after saving in FormBuilder. Delegate the loading to the the shared FormLoader as returned by the FormFactory, giving the id and the client's class.
To find a resource at runtime of your application it has to be located relative to a class location. There are several places the ResourceManager will try to find it (in this sequence):
- look in classpath of targetClass: [packagename]/resourcePrefix/[resourceName]
- look in classpath analogon below shared resource location: /resourcePrefix/[packageName]/[resourceName]
- look in shared resource location: /resourcePrefix/[resourceName]
resourcePrefix is a property of ResourceManager and can be accessed/changed by client code. It defaults to "resources". For details see the API doc of ResourceManager.
A FormLoader will try to locate the resource, read it, create and add the children and customize their presentation attributes. All widgets will be named as described in the resource - thus it's possible to access them later in application code.
SimpleLoading/Form: Actions
AbstractButtons are customized by creating a default action, setting the actions's attributes and then set the action to the button. The action is registered with the shared ActionFactory. The action is of type "DelegateAction" (see actionframework at javadesktop) and has the componentID as actionCommand. Clients can hook into the default action in one of two ways:
- register a callback method (public access, parameterless) with the same name
- register an action directly
Note that this client registration can be done before or after actually loading the form. A code snippet copied from SimpleForm.java:
String[] actionIDs = { "someAction" };
public void someAction() {
log("executed someAction method");
}
protected void registerActions() {
ActionFactory.getInstance().registerHandler(Arrays.asList(actionIDs),
SIMPLE_FORM_RESOURCE, this);
ActionFactory.getInstance().registerActionAsHandler("otherAction",
SIMPLE_FORM_RESOURCE, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
log("performed otherAction " + e);
}
});
}
TBD: selection not yet supported.
SimpleForm is similar to SimpleLoading, but demonstrates how to use utility classes to further simplify the code.
LoadFromFile: access files
Quickstart: playing with design alternatives
Allows switching between design alternatives. One of the alternatives is to use "groupboxes" - a container with a titled border around it. To build a form showing this border:
- add a border to the layout
- add an element with the same id as the form itself in the Presentation Editor
- the text property of this element will be used as title
It's kind of a hack - using groupboxes is discouraged by Forms though widely used in the windows world. For an example resource, see f.i. quickstartgeneralbox.fds
Currently, nested forms are supported to a depth of one level only. To nest, add a constraint of type PlaceHolder to the parent. On loading, the constraintID of the placeholder is assumed to be the resourceID of a sub-container. If such a resource is found, the placeholder will be replaced by the automatically built subform.
Unlimited nesting will be included in a future version.
Advanced
NovaExample: custom widgets and localization
see NovaExample
QuickStartStyled: adjusting column styles at runtime
Binding
SimpleBinding: edit bean properties
BookManager: example ported from JGoodies