FormBuilder

Overview of Examples

FormBuilder frameworks comes with a set of examples that demonstrate the usage of pre-built form descriptions.

Basics

new 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):

  1. look in classpath of targetClass: [packagename]/resourcePrefix/[resourceName]
  2. look in classpath analogon below shared resource location: /resourcePrefix/[packageName]/[resourceName]
  3. 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.

new 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

new 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

QuickStartStyled: adjusting column styles at runtime

new Binding

SimpleBinding: edit bean properties

BookManager: example ported from JGoodies

© Content 2003, 2004 Jeanette Winzenburg
Contact: formbuilder@swingempire.de

© Webdesign 2003, 2004 Linda Radecke
Contact: design@swingempire.de

Entry URL: http://www.swingempire.de/palace/FormBuilder
Modified: $Date: 2004/10/04 14:33:37 $