Class TableTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.ComponentBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.InputComponentTag
-
- net.sf.jguiraffe.gui.builder.components.tags.table.TableTag
-
- All Implemented Interfaces:
Composite,ConditionalTag,ScrollSizeSupport,org.apache.commons.jelly.Tag
public class TableTag extends InputComponentTag implements Composite, ScrollSizeSupport
A tag that creates a table component.
Tables certainly belong to the most complex GUI elements. With this tag and some auxiliary tags that can be placed in the body of this tag such tables can be created and initialized. Though tables can be used for editing data they are no typical input components because they do not store their data in a form bean using a
ComponentHandler. Instead they are initialized with a model, which is simply a collection of Java beans. For each element in this collection a row will be displayed in the table. (The column's are derived from the table's column definition; see below.) So tables can be directly used for visualizing collections of data or manipulating single records.This tag is used like a normal component tag: simply place it in a builder script at the desired position according to the current layout. With the tag's attributes the model (i.e. the collection with the data objects) is specified. The exact structure of the table is specified by nested tags.
For each column to be displayed in the table a
<column></column>tag (implemented by theTableColumnTagclass) must be placed in the body of the table tag. This tag determines the column's header and the name of the property of the model objects that is to be displayed in this column. Further, aTransformercan be specified for formatting the data, and - in case of an editable column - a validator. These attributes are analogous to standard input components. More information can be found in the documentation of theColumnTag.Table tags are input component tags, which means that for each table a component handler will be created. This is a specialized handler that can be used to access specific table functionality. Per default this handler will not be added to the form's fields, but with setting the
noFieldattribute to false this behavior can be changed.The following table lists the attributes supported by the
TableTagtag handler class:Attribute Description Optional model Here the name of a bean must be provided that serves as the data model for the table. This bean must be a collection. If it implements the java.util.Listinterface, it is directly used. Otherwise it is copied into a new list because direct access to the elements by index is needed. The collection can contain arbitrary Java beans whose properties will be accessed using reflection. The bean is looked up in the current bean context.No editable This boolean property determines whether the table is read-only or can be edited. Here only the default value is set; it is possible to override this value for specific columns. If this attribute is not provided, false is assumed as the default value. Yes selectionBackground With this property the background color for selected cells can be set. If ommitted, the default color will be used. Yes selectionForeground With this property the foreground color for selected cells can be set. If ommitted, the default color will be used. Yes multiSelection This boolean property indicates whether the created table should support multi-selection, i.e. multiple rows can be selected at the same time. If the attribute is missing, false is the default value. Yes scrollWidth Here the preferred width of the scroll pane enclosing the table can be specified as a number with unit (e.g. "1.5cm"). If specified, the scroll pane will have exactly this preferred width. Otherwise, the width is determined by the preferred width of the table. yes scrollHeight Here the preferred height of the scroll pane enclosing the table can be specified as a number with unit (e.g. "10dlu"). If specified, the scroll pane will have exactly this preferred height. Otherwise, the height is determined by the preferred height of the table. yes var If this attribute is set, the table tag will store a reference to itself in the Jelly context under the name specified here. This is especially useful for testing purposes. The variable created by this meachanism can be used for instance to query the internally created form objects. Yes There are some further objects that can be associated with a table and are defined by nested tags:
TableSelectionHandlers for both renderer and editor components. These objects can be specified using nestedTableSelectionHandlerTagtags.- A
TableEditorValidationHandlerfor getting notifications about validation events related to column editors. A concrete implementation of this interface can be specified using theTableEditorValidationHandlerTagtag.
- Version:
- $Id: TableTag.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description TableTag()Creates a new instance ofTableTag.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColumn(TableColumnTag colTag)Adds a tag representing a column to this table tag.voidaddComponent(Object comp, Object constraints)Adds an element to this container.protected ComponentHandler<?>createComponentHandler(ComponentManager manager, boolean create)Creates the table component.TableColumnTaggetColumn(int index)Returns the tag for the column with the given index.intgetColumnCount()Returns the number of columns of this table.Collection<TableColumnTag>getColumns()Returns a collection with the column tags defined for this table.TableColumnWidthControllergetColumnWidthController()Returns theTableColumnWidthControllerfor the columns defined for this table.ObjectgetContainer()Returns an object representing the container.TableSelectionHandlergetEditorSelectionHandler()Returns the selection handler for editor components.TableEditorValidationHandlergetEditorValidationHandler()Returns the editor validation handler.NumberWithUnitgetPreferredScrollHeight()Returns the preferred scroll height as a number with unit.NumberWithUnitgetPreferredScrollWidth()Returns the preferred scroll width as a number with unit.TableSelectionHandlergetRendererSelectionHandler()Returns the selection handler for renderer components.FormgetRowEditForm()Returns the form with the editors defined for this table.FormgetRowRenderForm()Returns the form with the renderers defined for this table.StringgetScrollHeight()Returns the preferred scroll height as a string.StringgetScrollWidth()Returns the preferred scroll width as a string.StringgetSelectionBackground()Returns the selection background color as a string.ColorgetSelectionBackgroundColor()Returns the selection background color asColorobject.StringgetSelectionForeground()Returns the selection foreground color as a string.ColorgetSelectionForegroundColor()Returns the selection foreground color asColorobject.TableFormControllergetTableFormController()Returns an initializedTableFormControllerobject associated with this tag.Collection<?>getTableModel()Returns the model of this table.StringgetValidationErrorTitle()Returns the title of the message box that is displayed if validation fails.booleanisColumnEditable(TableColumnTag colTag)Returns a flag whether the specified column is editable.booleanisMultiSelection()Returns a flag whether multi-selection is enabled for this table.booleanisTableEditable()Returns a flag whether the table is editable.protected voidprocess()Processes this tag.protected voidprocessBeforeBody()Processes this tag before the body is executed.protected ObjectresolveModel(String modelName)Obtains the model for the table.voidsetEditable(boolean f)Set method of the editable attribute.voidsetEditorSelectionHandler(TableSelectionHandler editorSelectionHandler)Sets the selection handler for editor components.voidsetEditorValidationHandler(TableEditorValidationHandler editorValidationHandler)Sets the editor validation handler.voidsetLayout(Object layout)Sets a layout object for this container.voidsetModel(String s)Set method for the model attribute.voidsetMultiSelection(boolean multiSelection)Set method for the multiSelection attribute.voidsetRendererSelectionHandler(TableSelectionHandler rendererSelectionHandler)Sets the selection handler for renderer components.voidsetScrollHeight(String scrollHeight)Set method of thescrollHeightattribute.voidsetScrollWidth(String scrollWidth)Set method of thescrollWidthattribute.voidsetSelectionBackground(String selectionBackground)Set method for the selectionBackground attribute.voidsetSelectionForeground(String selectionForeground)Set method for the selectionForeground attribute.voidsetValidationErrorCaption(String validationErrorTitle)Sets the title of the message box that is displayed if validation fails.voidsetVar(String s)Set method of the var attribute.-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.InputComponentTag
addToGroups, checkName, createFieldHandler, getComponent, getComponentHandler, getComponentType, getDisplayName, getFieldValidator, getFormValidator, getGroups, getPropertyName, getReadTransformer, getTypeName, getWriteTransformer, handleGroups, insertField, isNoField, setComponentType, setDisplayName, setDisplayNamegrp, setDisplayNameres, setFieldValidator, setFormValidator, setGroups, setNoField, setPropertyName, setReadTransformer, setTypeName, setWriteTransformer
-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.ComponentBaseTag
getBackColor, getBackgroundColor, getConstraints, getFont, getFontRef, getForeColor, getForegroundColor, getName, getToolTipData, insertComponent, setBackColor, setConstraints, setFont, setFontRef, setForeColor, setName, setTooltip, setTooltipres, setTooltipresgrp
-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
canProcess, canProcess, convertToClass, convertToNumberWithUnit, convertToNumberWithUnit, doTag, findContainer, getBuilderData, getBuilderData, getIfName, getResourceText, getResourceText, getUnlessName, setIfName, setUnlessName
-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
Method Detail
-
getSelectionBackground
public String getSelectionBackground()
Returns the selection background color as a string.- Returns:
- the selection background color (can be null)
-
setSelectionBackground
public void setSelectionBackground(String selectionBackground)
Set method for the selectionBackground attribute.- Parameters:
selectionBackground- the value of the attribute
-
getSelectionForeground
public String getSelectionForeground()
Returns the selection foreground color as a string.- Returns:
- the selection foreground color (can be null)
-
setSelectionForeground
public void setSelectionForeground(String selectionForeground)
Set method for the selectionForeground attribute.- Parameters:
selectionForeground- the attribute's value
-
getScrollWidth
public String getScrollWidth()
Returns the preferred scroll width as a string.- Returns:
- the preferred scroll width specification (can be null)
-
setScrollWidth
public void setScrollWidth(String scrollWidth)
Set method of thescrollWidthattribute.- Parameters:
scrollWidth- the attribute's value
-
getScrollHeight
public String getScrollHeight()
Returns the preferred scroll height as a string.- Returns:
- the preferred scroll height specification (can be null)
-
setScrollHeight
public void setScrollHeight(String scrollHeight)
Set method of thescrollHeightattribute.- Parameters:
scrollHeight- the attribute's value
-
getSelectionBackgroundColor
public Color getSelectionBackgroundColor()
Returns the selection background color asColorobject. This is the value set by thesetSelectionBackground()method transformed into aColorrepresentation.- Returns:
- the selection background color
-
getSelectionForegroundColor
public Color getSelectionForegroundColor()
Returns the selection foreground color asColorobject. This is the value set by thesetSelectionForeground()method transformed into aColorrepresentation.- Returns:
- the selection foreground color
-
getPreferredScrollWidth
public NumberWithUnit getPreferredScrollWidth()
Returns the preferred scroll width as a number with unit. This is the value set using thesetScrollWidth(String)method. It has been converted to aNumberWithUnit. If no preferred scroll width has been set, this method returnsNumberWithUnit.ZERO.- Specified by:
getPreferredScrollWidthin interfaceScrollSizeSupport- Returns:
- the preferred scroll width
-
getPreferredScrollHeight
public NumberWithUnit getPreferredScrollHeight()
Returns the preferred scroll height as a number with unit. This is the value set using thesetScrollHeight(String)method. It has been converted to aNumberWithUnit. If no preferred scroll height has been set, this method returnsNumberWithUnit.ZERO.- Specified by:
getPreferredScrollHeightin interfaceScrollSizeSupport- Returns:
- the preferred scroll height
-
setModel
public void setModel(String s)
Set method for the model attribute.- Parameters:
s- the value of the attribute
-
setEditable
public void setEditable(boolean f)
Set method of the editable attribute.- Parameters:
f- the value of the attribute
-
isMultiSelection
public boolean isMultiSelection()
Returns a flag whether multi-selection is enabled for this table.- Returns:
- the multi selection flag
-
setMultiSelection
public void setMultiSelection(boolean multiSelection)
Set method for the multiSelection attribute.- Parameters:
multiSelection- the attribute's value
-
setVar
public void setVar(String s)
Set method of the var attribute.- Parameters:
s- the value of the attribute
-
isTableEditable
public boolean isTableEditable()
Returns a flag whether the table is editable. Note that this flag does not control the editable state of the full table, it only defines the default state for columns. A column can override this flag.- Returns:
- a flag whether the table is editable
-
isColumnEditable
public boolean isColumnEditable(TableColumnTag colTag)
Returns a flag whether the specified column is editable. This method should be used to find out whether the column can be edited or not. It also takes the table's default settings into account.- Parameters:
colTag- the tag representing the column to test- Returns:
- a flag whether this column can be edited
-
getEditorSelectionHandler
public TableSelectionHandler getEditorSelectionHandler()
Returns the selection handler for editor components.- Returns:
- the editor selection handler
-
setEditorSelectionHandler
public void setEditorSelectionHandler(TableSelectionHandler editorSelectionHandler)
Sets the selection handler for editor components. This method will be invoked by tags in the body to set a concrete implementation of theTableSelectionHandlerinterface.- Parameters:
editorSelectionHandler- the selection handler for editor components
-
getEditorValidationHandler
public TableEditorValidationHandler getEditorValidationHandler()
Returns the editor validation handler.- Returns:
- the editor validation handler
-
setEditorValidationHandler
public void setEditorValidationHandler(TableEditorValidationHandler editorValidationHandler)
Sets the editor validation handler. This method will be called by nested tags to set a concrete implementation of theTableEditorValidationHandlerinterface.- Parameters:
editorValidationHandler- the editor validation handler
-
getRendererSelectionHandler
public TableSelectionHandler getRendererSelectionHandler()
Returns the selection handler for renderer components. This method never returns null. If no handler was set, a dummy handler is returned.- Returns:
- the renderer selection handler
-
setRendererSelectionHandler
public void setRendererSelectionHandler(TableSelectionHandler rendererSelectionHandler)
Sets the selection handler for renderer components. This method will be invoked by tags in the body to set a concrete implementation of theTableSelectionHandlerinterface.- Parameters:
rendererSelectionHandler- the selection handler for renderer components
-
getValidationErrorTitle
public String getValidationErrorTitle()
Returns the title of the message box that is displayed if validation fails.- Returns:
- the message box title
-
setValidationErrorCaption
public void setValidationErrorCaption(String validationErrorTitle)
Sets the title of the message box that is displayed if validation fails. This property can be evaluated by the currentTableEditorValidationHandler. This object is triggered whenever validation of user input in a custom editor fails. In this case typically a message box with the validation error message(s) is displayed. With this property the caption of this message box is specified. It is typically set by a nestedTableEditorValidationHandlerTagtag handler.- Parameters:
validationErrorTitle- the caption of a validation error message box
-
getColumns
public Collection<TableColumnTag> getColumns()
Returns a collection with the column tags defined for this table. With this method all information about the existing columns can be obtained.- Returns:
- a collection with the tags representing the columns of this table
-
getColumn
public TableColumnTag getColumn(int index)
Returns the tag for the column with the given index.- Parameters:
index- the column index (0-based)- Returns:
- the column with this index
-
getColumnCount
public int getColumnCount()
Returns the number of columns of this table.- Returns:
- the number of columns of the represented table
-
getRowRenderForm
public Form getRowRenderForm()
Returns the form with the renderers defined for this table. All components defined in<colrenderer>tags for columns of this table will be collected into aFormobject. For columns that do not define their own renderers defaultFieldHandlerobjects will be added to this form. So this form object contains a complete representation of the data of a single row. Platform specific implementations can make use of this object when the table is to be displayed.- Returns:
- a form containing the components for rendering a row
-
getRowEditForm
public Form getRowEditForm()
Returns the form with the editors defined for this table. This method is analogous togetRowRenderForm(), but the returnedFormobject contains the defined editor components (plus the defaultFieldHandlerobjects to be used for columns that do not have their own editor).- Returns:
- a form containing the components for rendering a row
- See Also:
getRowRenderForm()
-
getTableModel
public Collection<?> getTableModel()
Returns the model of this table. This is a collection with arbitrary beans, which is fetched from the Jelly context.- Returns:
- the collection that acts as the table's model
-
getTableFormController
public TableFormController getTableFormController()
Returns an initializedTableFormControllerobject associated with this tag.- Returns:
- a
TableFormController - Since:
- 1.3
-
addColumn
public void addColumn(TableColumnTag colTag)
Adds a tag representing a column to this table tag. This method will be called by nested tags.- Parameters:
colTag- the column tag to be added
-
getColumnWidthController
public TableColumnWidthController getColumnWidthController() throws FormBuilderException
Returns theTableColumnWidthControllerfor the columns defined for this table. This method can be called after execution of this tag. It creates theTableColumnWidthControllerobject on demand and initializes with all columns defined for this table.- Returns:
- the
TableColumnWidthControllerfor this table - Throws:
FormBuilderException- if the controller cannot be created
-
addComponent
public void addComponent(Object comp, Object constraints)
Adds an element to this container. This tag implements theCompositeinterface so that the components created by the columns defined in its body get automatically added and do not mess up the hosting container tag. This makes it also possible to verify that onlyTableColumnTagtags are placed in the body - these tags create component handlers that do not have a component.- Specified by:
addComponentin interfaceComposite- Parameters:
comp- the component to be addedconstraints- a constraints object
-
getContainer
public Object getContainer()
Returns an object representing the container. This method from theCompositeinterface is not supported by this tag.- Specified by:
getContainerin interfaceComposite- Returns:
- the container object
-
setLayout
public void setLayout(Object layout)
Sets a layout object for this container. This method from theCompositeinterface is not supported by this tag.
-
processBeforeBody
protected void processBeforeBody() throws org.apache.commons.jelly.JellyTagException, FormBuilderExceptionProcesses this tag before the body is executed. This implementation checks for some required attributes and performs some initialization.- Overrides:
processBeforeBodyin classInputComponentTag- Throws:
org.apache.commons.jelly.JellyTagException- if a jelly related problem occursFormBuilderException- if the tag is incorrectly usedInjectionException- if the model bean cannot be resolved
-
process
protected void process() throws FormBuilderException, org.apache.commons.jelly.JellyTagExceptionProcesses this tag. This implementation performs additional validity checks regarding the definitions of the table's columns.- Overrides:
processin classInputComponentTag- Throws:
FormBuilderException- if an error occursorg.apache.commons.jelly.JellyTagException- if the tag is used incorrectly
-
resolveModel
protected Object resolveModel(String modelName)
Obtains the model for the table. This implementation tries to resolve the model bean from the current bean context.- Parameters:
modelName- the name of the model- Returns:
- the bean serving as table model
- Throws:
InjectionException- if the model bean cannot be resolved
-
createComponentHandler
protected ComponentHandler<?> createComponentHandler(ComponentManager manager, boolean create) throws FormBuilderException, org.apache.commons.jelly.JellyTagException
Creates the table component. Delegates to the component manager.- Specified by:
createComponentHandlerin classInputComponentTag- Parameters:
manager- the managercreate- the create flag- Returns:
- the new component
- Throws:
FormBuilderException- if an error occursorg.apache.commons.jelly.JellyTagException- if the tag is incorrectly used
-
-