Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

oracle.javatools.ui.builders
Class TableBuilder<T>

java.lang.Object
  extended by oracle.javatools.ui.builders.BasicBuilder<T>
      extended by oracle.javatools.ui.builders.TableBuilder<T>

public final class TableBuilder<T>
extends BasicBuilder<T>

A class to easily and concisely build a table component. Tell the builder the features you'd like the table to have, call build(), and the builder will take care of putting one together for you.

The builder uses a fluent interface, meaning a table can be quickly built like this:
(new TableBuilder()).reorder(true).build();

The table takes care of ensuring that it conforms to UI standards, and takes drudge work out of creating a reorderable table, a scrollpane, and other commonly configured ui settings.

T is the type of an object representing a row of the table.


Nested Class Summary
static class TableBuilder.DefaultAction
          Built in actions that can be used to quickly create toolbar button actions
static class TableBuilder.RowHeaderType
           
 
Nested classes/interfaces inherited from class oracle.javatools.ui.builders.BasicBuilder
BasicBuilder.Instructions
 
Field Summary
 
Fields inherited from class oracle.javatools.ui.builders.BasicBuilder
instructions
 
Constructor Summary
TableBuilder()
           
 
Method Summary
 void addColumn(java.lang.String name, java.lang.String renderViaMethodName)
          If the table model is supplied as a list or array, then define the columns in order be repeatedly calling the addColumn methods.
 void addColumn(java.lang.String name, javax.swing.table.TableCellRenderer renderer)
          If the table model is supplied as a list or array, then define the columns in order be repeatedly calling the addColumn methods.
 BuiltTable<T> build()
          Create and return the class containing the built UI for the specified table.
protected  void buildToolbar(oracle.javatools.ui.builders.BuiltBasic builtBasic)
           
protected  BasicBuilder.Instructions createInstructions()
           
 void setActionsDefault(TableBuilder.DefaultAction defaultAction, java.awt.event.ActionListener listener)
          Add one of the DefaultActions to the toolbar and listen to it.
 void setAutoSizeColumns(boolean autoSize)
          Initially size the columns of the table to match the contents.
 void setColumnSelectionAllowed(boolean selectionAllowed)
          Allow selection of table data by column
 void setHiddenColumns(int... hiddenColumns)
          Set the columns that are initally hidden.
 void setHiddenColumnsAllowed(boolean isAvailable)
          Set whether this table will display a dropdown button at the end of the column header to hide/show columns.
 void setHorizontalScrolling(boolean horizontalScrolling)
          Allow the table to scroll horizontally.
 void setModel(java.util.List<T> list)
          Supply a list, each item of the table will be one row in the table.
 void setModel(T[] array)
          Supply an array of items, each item will be one row in the table.
 void setModel(javax.swing.table.TableModel model)
          Supply the model to be used in the table.
 void setReorderable(boolean reorderable)
          Allow the contents of the table to be reordered by the user.
 void setRowHeader(TableBuilder.RowHeaderType rowHeader)
          Add a header to the start of each row
 void setRowSelectionAllowed(boolean selectionAllowed)
          Allow selection of table data by row
 void setSelectAllAllowed(boolean selectAllAllowed)
          Enables whether the table has a control that when clicked will select all of the cells in the table (Selection model permitting).
 void setSelection(int... indexes)
          Set the indexes of the rows that will be initially selected.
 void setSelectionMode(int selectionMode)
          Set the selection mode of the table, by default the mode is single selection
 void setShowGrid(boolean showGrid)
          Controls whether the table will show gridlines between cells.
 void setShowToolTips(boolean showToolTips)
          Controls whether the table will show tooltips for cells that are truncated due to reduced column width.
 void setSortable(boolean sortable)
          Allow sorting of the rows in the table with a default table row sorter
 void setSorter(javax.swing.table.TableRowSorter sorter)
          Allow sorting of the rows in the table with a default table row sorter.
 void setVisibleRows(int visibleRows)
          Set the preferred number of visible rows
 
Methods inherited from class oracle.javatools.ui.builders.BasicBuilder
setActions, setActionsSecondary, setActionsSecondary, setCheckable, setDoubleClickListener, setEmptyText, setEmptyTextLarge, setLabel, setResizable, setRollover, setSelection, setSelectionEnabledAction, setSelectionEnabledComponent, setTitlebar, setToolbarComponents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableBuilder

public TableBuilder()
Method Detail

createInstructions

protected BasicBuilder.Instructions createInstructions()
Specified by:
createInstructions in class BasicBuilder<T>

build

public BuiltTable<T> build()
Create and return the class containing the built UI for the specified table.

Returns:
a BuiltTable configured to the specification of previous calls to this builder.

buildToolbar

protected void buildToolbar(oracle.javatools.ui.builders.BuiltBasic builtBasic)
Overrides:
buildToolbar in class BasicBuilder<T>

setModel

public void setModel(javax.swing.table.TableModel model)
Supply the model to be used in the table.

Parameters:
model -

setModel

public void setModel(java.util.List<T> list)
Supply a list, each item of the table will be one row in the table. Use the 'addColumn...' methods to define the columns.

Parameters:
list - a List of items, each item is one row in the table

setModel

public void setModel(T[] array)
Supply an array of items, each item will be one row in the table. Use the 'addColumn...' methods to define the columns.

Parameters:
array - an array of items, each item is one row in the table

addColumn

public void addColumn(java.lang.String name,
                      java.lang.String renderViaMethodName)

If the table model is supplied as a list or array, then define the columns in order be repeatedly calling the addColumn methods.

The text for each column cell is retrieved by calling the method name on type T (each row in the table is a T). e.g. if the model contained 'Locale' objects in each row then set renderNameByMethod to "getDisplayCountry" to display a country name in this column:

builder.addColumn("Country", "getDisplayCountry")
This avoids the need to write a renderer in a large number of cases

Parameters:
name - The name or the column that appears in the table header
renderViaMethodName -

addColumn

public void addColumn(java.lang.String name,
                      javax.swing.table.TableCellRenderer renderer)

If the table model is supplied as a list or array, then define the columns in order be repeatedly calling the addColumn methods.

The renderer will be passed the column index and the value for the row (an instance of T) via the getTableCellRendererComponent(...) method

Parameters:
name - The name or the column that appears in the table header
renderer - a TableCellRenderer that will render a cell in this column

setSelection

public void setSelection(int... indexes)
Set the indexes of the rows that will be initially selected.

Parameters:
indexes - the indexes to select

setSelectionMode

public void setSelectionMode(int selectionMode)
Set the selection mode of the table, by default the mode is single selection

Parameters:
selectionMode - a ListSelectionModel constant

setRowSelectionAllowed

public void setRowSelectionAllowed(boolean selectionAllowed)
Allow selection of table data by row


setAutoSizeColumns

public void setAutoSizeColumns(boolean autoSize)
Initially size the columns of the table to match the contents.

Parameters:
autoSize - if true the columns will be autosized to match the contents

setSortable

public void setSortable(boolean sortable)
Allow sorting of the rows in the table with a default table row sorter

Parameters:
sortable - if true the table will be sortable

setSorter

public void setSorter(javax.swing.table.TableRowSorter sorter)
Allow sorting of the rows in the table with a default table row sorter. Setting of this automatically implies setSorted(true).

Parameters:
sorter - aTableRowSorter to sort the table

setColumnSelectionAllowed

public void setColumnSelectionAllowed(boolean selectionAllowed)
Allow selection of table data by column

Parameters:
selectionAllowed -

setHiddenColumnsAllowed

public void setHiddenColumnsAllowed(boolean isAvailable)
Set whether this table will display a dropdown button at the end of the column header to hide/show columns. The default according to current LAF guidelines is true

Parameters:
isAvailable -

setHiddenColumns

public void setHiddenColumns(int... hiddenColumns)
Set the columns that are initally hidden.

Parameters:
hiddenColumns - column indexes for initially hidden columns

setShowToolTips

public void setShowToolTips(boolean showToolTips)
Controls whether the table will show tooltips for cells that are truncated due to reduced column width. By default this is true.

Parameters:
showToolTips - if true, a tooltip will be displayed for any cell which is truncated because the column is not wide enough to display its full value.

setShowGrid

public void setShowGrid(boolean showGrid)
Controls whether the table will show gridlines between cells.

Parameters:
showGrid - if true, a grid will be shown between cells

setReorderable

public void setReorderable(boolean reorderable)
Allow the contents of the table to be reordered by the user. Supported model types include DefaultTableModel and models that implement ReorderableTableModel

Parameters:
reorderable -

setSelectAllAllowed

public void setSelectAllAllowed(boolean selectAllAllowed)

Enables whether the table has a control that when clicked will select all of the cells in the table (Selection model permitting).

A RowHeader will have to be set for this control to be visible

Under current UI guidelines this control is located at the top left of the table


setActionsDefault

public void setActionsDefault(TableBuilder.DefaultAction defaultAction,
                              java.awt.event.ActionListener listener)
Add one of the DefaultActions to the toolbar and listen to it. The listener will receive an action event with its command equal to the appropriate DefaultAction.toString()

Parameters:
defaultAction -
listener - a listener to be called when the action is performed

setHorizontalScrolling

public void setHorizontalScrolling(boolean horizontalScrolling)

Allow the table to scroll horizontally. When enabled this allows the contents of the table to be wider than the scrollpanes viewport.

This is essentially the same as calling table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)

Parameters:
horizontalScrolling -

setVisibleRows

public void setVisibleRows(int visibleRows)
Set the preferred number of visible rows

Parameters:
visibleRows - the number of visible rows

setRowHeader

public void setRowHeader(TableBuilder.RowHeaderType rowHeader)
Add a header to the start of each row

Parameters:
rowHeader -

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

Copyright © 1997, 2011, Oracle. All rights reserved.