Canoo's Groovy ULCBuilder
Groovy Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
ulcbuilder-core
ulcbuilder-formlayout
ulcbuilder-miglayout
ulcbuilder-sample
.gitignore
LICENSE.txt
README.md
build.gradle
settings.gradle

README.md

ULCBuilder

ULCBuilder is a Groovy based builder for ULC (core of the Canoo RIA Suite) powered applications.

ULCBuilder and Groovy makes possible the use of a DSL-like language to defining the UI of an application, in the same vein as SwingBuilder does for Swing.

ULCBuilder is extensible via builder plugins. There are two officially supported plugins at the moment: miglayout and formlayout. These plugins allow the usage of two powerful layout managers. Builder plugins can be used by simply adding their respective jars to the application's classpath. If you rely on Maven or Ivy then you can configure the following repository to pull ULCBuilder and its dependencies

https://ci.canoo.com/nexus/content/repositories/public-releases

group: com.canoo.ulc artifact: ulcbuilder-core version: 1.0

group: com.canoo.ulc artifact: ulcbuilder-miglayout version: 1.0

group: com.canoo.ulc artifact: ulcbuilder-formlayout version: 1.0

Usage

ULCBuilder works in the same as SwingBuilder does. This means you typically create an instance of the builder and use Groovy's closures and Map notation to define which components should be created and with which properties. The following example demonstrates how a simple frame with a form-like view can be created using the builder:

package com.canoo.groovy.ulc

import com.ulcjava.applicationframework.application.SingleFrameApplication
import com.ulcjava.base.application.ULCComponent
import com.ulcjava.base.application.ULCFrame

class SampleApplication extends SingleFrameApplication {
    private final ULCBuilder builder = new ULCBuilder()

    @Override
    protected ULCComponent createStartupMainContent</th></tr>
        builder.migLayoutPane {
            label 'Label1'
            textField constraints: 'span 2, growx, wrap'
            label 'Label2'
            textField constraints: 'wrap'
            label 'Label3'
            textField()
            button 'Click!', constraints: 'right'
        }
    }

    @Override
    protected void initFrame(ULCFrame frame) {
        super.initFrame(frame)
        frame.setLocationRelativeTo(null)
    }
}

Let's review the code part by part. If you're familiar with ULC you probably know that it ships with an Application Framework that provides a set of classes that help writing applications in a more efficient way. SingleFrameApplication is one of such classes. You're only required to provide an implementation for the createStartupMainComntent() method. This is where the builder will be used to create the components that conform the application. This example relies on one of the builder plugins to be available in the classpath, we're refering to the ulcbuilder-miglayout plugin.

Granted the example is quite trivial but compare what would be the alternate code if the example were written in plain java

ULCMigLayoutPane p = new ULCMigLayoutPane();
p.add(new ULCLabel("Label1"));
p.add(new ULCTextField(), "span 2, growx, wrap");
p.add(new ULCLabel("Label2"));
p.add(new ULCTextField(), "wrap");
p.add(new ULCLabel("Label3"));
p.add(new ULCTextField());
p.add(new ULCButton("Click!"), "right");
return p;

With the builder you save a few characters (parenthesis and semi-colons), but you also gain cleaner code. It's easier to determine the hierarchy of components at first glance whereas in the Java version you'll quickly get container adds all over the place; not counting code factorizations into private methods to hide that complexity.

Builder Nodes

The builder should allow you to build any component available in ULC Core. Each node follows a naming convention that is easy to remember:

  1. Take the name of an ULC component and drop the 'ULC' prefix example: ULCButton -> Button
  2. Uncapitalize the first character example: Button -> button

And that's all! There are additional nodes that map to classes that do not follow this pattern, but the list is very short. The following section spells out all nodes available in the latest version of the builder. They are shown grouped by behavior but the grouping has no real impact on how they are used.

Node Class
SupportNodes
actionDefaultAction
actionsList
mapMap
iconULCIcon
buttonGroupULCButtonGroup
Binding
bindFullBinding
PassThruNodes
widgetaccepts any ULCComponent
containeraccepts any ULCComponent
beanany class
Windows
dialogULCDialog
frameULCFrame
windowULCWindow
ActionButtonWidgets
buttonULCButton
checkBoxULCCheckBox
checkBoxMenuItemULCCheckBoxMenuItem
menuItemULCMenuItem
radioButtonULCRadioButton
radioButtonMenuItemULCRadioButtonMenuItem
toggleButtonULCToggleButton
TextWidgets
labelULCLabel
passwordFieldULCPasswordField
textAreaULCTextArea
textFieldULCTextField
MDIWidgets
desktopPaneULCDesktopPane
internalFrameULCInternalFrame
BasicWidgets
comboBoxULCComboBox
listULCList
progressBarULCProgressBar
separatorULCSeparator
scrollBarULCScrollBar
sliderULCSlider
spinnerULCSpinner
treeULCTree
MenuWidgets
menuULCMenu
menuBarULCMenuBar
popupMenuULCPopupMenu
Containers
boxPaneULCBoxPane
scrollPaneULCScrollPane
splitPaneULCSplitPane
cardPaneULCCardPane
tabbedPaneULCTabbedPane
toolBarULCToolBar
layeredPaneULCLayeredPane
DataModels
spinnerDateModelULCSpinnerDateModel
spinnerListModelULCSpinnerListModel
spinnerNumberModelULCSpinnerNumberModel
TableComponents
tableULCTable
tableColumnULCTableColumn
tableModelULCTableModel
propertyColumnULCTableColumn
closureColumnULCTableColumn
tableTreeULCTableTree
BasicLayouts
borderLayoutPaneULCBorderLayoutPane
flowLayoutPaneULCFlowLayoutPane
gridLayoutPaneULCGridLayoutPane
gridBagLayoutPaneULCGridBagLayoutPane
BoxLayout
boxLayoutPaneULCBoxLayoutPane
fillerULCFiller
hglueULCFiller
hstrutULCFiller
rigidarea
vglueULCFiller
vstrutULCFiller
Borders
lineBorderULCLineBorder
loweredBevelBorderULCBevelBorderFactory (ULCBevelBorder.LOWERED)
raisedBevelBorderULCBevelBorderFactory (ULCBevelBorder.RAISED)
etchedBorderULCEtchedBorderFactory (ULCEtchedBorder.LOWERED)
loweredEtchedBorderULCEtchedBorderFactory (ULCEtchedBorder.LOWERED)
raisedEtchedBorderULCEtchedBorderFactory (ULCEtchedBorder.RAISED)
titledBorderULCTitledBorder
emptyBorderULCEmptyBorder
compoundBorderULCCompoundBorder
matteBorderULCMatteBorder
RenderersAndEditors
tableCellRendererDefaultTableCellRenderer
treeCellRendererDefaultTreeCellRenderer
tableTreeCellRendererDefaultTableTreeCellRenderer
cellEditorDefaultCellEditor