|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.bebop.Completable
com.arsdigita.bebop.SimpleComponent
com.arsdigita.bebop.TextStylable
com.arsdigita.bebop.BlockStylable
com.arsdigita.bebop.Table
Displays statically or
dynamically generated data in tabular form. The data is retrieved
from a TableModel
.
This class is similar to the List
class, but it has two dimensions.
The table consists of a Table.MatrixTableModelBuilder
, a TableColumnModel
,
a TableHeader
and a TableCellRenderer
for each column.
A table that represents a static matrix can be created fairly quickly:
String[][] data = { {"Stas", "Freidin"}, {"David", "Lutterkort"} }; String[] headers = {"First Name", "Last Name"}; Table myTable = new Table(data, headers);
However, tables are most often used to represent database queries, not static
data. For these tables, the Table.MatrixTableModelBuilder
class should be used
to supply the Table
class with data.
The Table.MatrixTableModelBuilder
class will execute the database query and
return a TableModel
, which wraps the query.
The content in the cells is rendered by the TableCellRenderer
that is set for the TableColumn
to which the
cell belongs. If the TableCellRenderer
has not been
set, the TableCellRenderer
for the
Table
is used. By default, the Table
class uses an inactive
instance of the DefaultTableCellRenderer
(cell content is
displayed as Label
s). However, if an
active DefaultTableCellRenderer
is used, the cells in
the table appear as links. When the user clicks a link, the
Table
's action listeners will be fired.
The currently
selected cell is represented by two SingleSelectionModel
s -
one model for the row and one model for the column. Typically, the
selected row is identified by a string key and the selected column
is identified by an integer.
TableModel
,
TableColumnModel
Nested Class Summary | |
static class |
Table.MatrixTableModelBuilder
An internal class that creates a table model around a set of data given as a Object[][] . |
Field Summary | |
protected static String |
CELL_EVENT
The control event when the user selects one table cell. |
static TableModel |
EMPTY_MODEL
A TableModel that has no rows. |
protected static char |
SEP
|
static String |
versionId
|
Fields inherited from class com.arsdigita.bebop.BlockStylable |
ABSBOTTOM, ABSMIDDLE, BASELINE, BOTTOM, CENTER, FULL_WIDTH, INSERT, LEFT, MIDDLE, RIGHT, TEXTTOP, TOP |
Fields inherited from class com.arsdigita.bebop.SimpleComponent |
m_attr |
Fields inherited from interface com.arsdigita.bebop.util.BebopConstants |
BEBOP_BORDER, BEBOP_BOXPANEL, BEBOP_CELL, BEBOP_CHECKBOX, BEBOP_CHECKBOXGROUP, BEBOP_COLUMNPANEL, BEBOP_DATE, BEBOP_DATETIME, BEBOP_DHTMLEDITOR, BEBOP_FORMERRORS, BEBOP_FORMWIDGET, BEBOP_GRIDPANEL, BEBOP_LIST, BEBOP_MULTISELECT, BEBOP_OPTION, BEBOP_PAD, BEBOP_PADFRAME, BEBOP_PANELROW, BEBOP_PORTAL, BEBOP_PORTLET, BEBOP_RADIO, BEBOP_RADIOGROUP, BEBOP_SEG_BODY, BEBOP_SEG_HEADER, BEBOP_SEG_PANEL, BEBOP_SEGMENT, BEBOP_SELECT, BEBOP_TABLE, BEBOP_TABLEBODY, BEBOP_TABLEROW, BEBOP_TEXTAREA |
Fields inherited from interface com.arsdigita.bebop.Component |
BEBOP_XML_NS, CLASS, ID, ON_CLICK, STYLE |
Constructor Summary | |
Table()
Constructs a new, empty table. |
|
Table(Object[][] data,
Object[] headers)
Constructs a static table with the specified column headers, and pre-fills it with data. |
|
Table(TableModelBuilder b,
Object[] headers)
Constructs a table using a Table.MatrixTableModelBuilder . |
|
Table(TableModelBuilder b,
TableColumnModel c)
Constructs a table using a Table.MatrixTableModelBuilder . |
Method Summary | |
void |
addTableActionListener(TableActionListener l)
Adds a TableActionListener to the table. |
Iterator |
children()
Returns an iterator over the header and all the columns. |
void |
clearSelection(PageState s)
Clears the row and column selection models that the table holds. |
protected TableActionListener |
createTableActionListener()
Instantiates a new TableActionListener for this table. |
protected void |
fireCellSelected(PageState state,
Object rowKey,
Integer column)
Fires event listeners to indicate that a new cell has been selected in the table. |
protected void |
fireHeadSelected(PageState state,
Object rowKey,
Integer column)
Fires event listeners to indicate that a new header cell has been selected in the table. |
protected void |
generateExtraXMLAttributes(PageState state,
Element element)
Adds type-specific XML attributes to the XML element representing this link. |
void |
generateXML(PageState s,
Element p)
Generates the XML representing the table. |
String |
getBorder()
|
String |
getCellPadding()
|
String |
getCellSpacing()
|
TableColumn |
getColumn(int i)
|
TableColumnModel |
getColumnModel()
|
SingleSelectionModel |
getColumnSelectionModel()
|
protected Component |
getControler()
|
TableCellRenderer |
getDefaultCellRenderer()
|
Component |
getEmptyView()
|
TableHeader |
getHeader()
|
TableModelBuilder |
getModelBuilder()
|
SingleSelectionModel |
getRowSelectionModel()
|
boolean |
getStriped()
|
TableModel |
getTableModel(PageState s)
Returns the table model in effect for the request represented by the page state. |
String |
getWidth()
|
boolean |
isSelectedCell(PageState s,
Object rowKey,
Object column)
Determines whether the cell addressed by the specified row key and column number is selected in the request represented by the page state. |
boolean |
isSelectedColumn(PageState s,
Object column)
Determines whether a column is selected. |
boolean |
isSelectedRow(PageState s,
Object rowKey)
Determines whether a row is seleted. |
void |
lock()
Locks the table against further modifications. |
void |
register(Page p)
Registers the table with the containing page. |
void |
removeTableActionListener(TableActionListener l)
Removes a TableActionListener from the table. |
void |
respond(PageState s)
Processes the events for this table. |
void |
setBorder(String v)
|
void |
setCellPadding(String v)
|
void |
setCellSpacing(String v)
|
void |
setColumn(int i,
TableColumn v)
Maps the colulumn at a new numerical index. |
void |
setColumnModel(TableColumnModel v)
Sets a new TableColumnModel for the table. |
void |
setColumnSelectionModel(SingleSelectionModel v)
Specifies the SingleSelectionModel that will be responsible
for selecting the current column. |
void |
setDefaultCellRenderer(TableCellRenderer v)
Specifies the default cell renderer. |
void |
setEmptyView(Component v)
Sets the empty view. |
void |
setHeader(TableHeader v)
Sets a new header for this table. |
void |
setModelBuilder(TableModelBuilder v)
Sets a new Table.MatrixTableModelBuilder for the table. |
void |
setRowSelectionModel(SingleSelectionModel v)
Specifies the SingleSelectionModel that will be responsible
for selecting the current row. |
void |
setStriped(boolean striped)
|
void |
setWidth(String v)
|
Methods inherited from class com.arsdigita.bebop.BlockStylable |
setBorder, setBorder, setBorderColor, setHorizontalAlignment, setMargin, setMargin, setPadding, setPadding, setVerticalAlignment |
Methods inherited from class com.arsdigita.bebop.TextStylable |
setBackgroundColor, setColor |
Methods inherited from class com.arsdigita.bebop.SimpleComponent |
clone, exportAttributes, getAttribute, getClassAttr, getIdAttr, getKey, getMetaDataAttribute, getStyleAttr, hasAttributes, isLocked, isVisible, register, setAttribute, setClassAttr, setIdAttr, setKey, setMetaDataAttribute, setStyleAttr, setVisible |
Methods inherited from class com.arsdigita.bebop.Completable |
addCompletionListener, fireCompletionEvent |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String versionId
protected static final String CELL_EVENT
protected static final char SEP
public static final TableModel EMPTY_MODEL
TableModel
that has no rows.
Constructor Detail |
public Table()
public Table(Object[][] data, Object[] headers)
data
- a matrix of objects that will serve as static data
for the table cellsheaders
- an array of string labels for the table headerspublic Table(TableModelBuilder b, Object[] headers)
Table.MatrixTableModelBuilder
. The table
data will be generated dynamically during each request.
b
- the Table.MatrixTableModelBuilder
that is responsible for
instantiating a TableModel
during each requestheaders
- an array of string labels for the table headerspublic Table(TableModelBuilder b, TableColumnModel c)
Table.MatrixTableModelBuilder
. The table
data will be generated dynamically during each request. The
table's columns and headers will be provided by a
TableColumnModel
.
b
- the Table.MatrixTableModelBuilder
that is responsible for
instantiating a TableModel
during each requestc
- the TableColumnModel
that will maintain the
columns and headers for this tableMethod Detail |
public void addTableActionListener(TableActionListener l)
TableActionListener
to the table. The listener is
fired whenever a table cell is clicked.
l
- the TableActionListener
to be addedpublic void removeTableActionListener(TableActionListener l)
TableActionListener
from the table.
l
- the TableActionListener
to be removedprotected void fireCellSelected(PageState state, Object rowKey, Integer column)
state
- the page staterowKey
- the key that identifies the selected rowcolumn
- the integer index of the selected columnprotected void fireHeadSelected(PageState state, Object rowKey, Integer column)
state
- the page staterowKey
- the key that identifies the selected rowcolumn
- the integer index of the selected columnprotected TableActionListener createTableActionListener()
TableActionListener
for this table.
TableActionListener
that should be used
only for this table.public final TableColumnModel getColumnModel()
TableColumnModel
for this table.public void setColumnModel(TableColumnModel v)
TableColumnModel
for the table.
v
- the new TableColumnModel
public final TableModelBuilder getModelBuilder()
Table.MatrixTableModelBuilder
for this table.public void setModelBuilder(TableModelBuilder v)
Table.MatrixTableModelBuilder
for the table.
v
- the new Table.MatrixTableModelBuilder
public final TableHeader getHeader()
TableHeader
for this table. Could return null
if the header is hidden.public void setHeader(TableHeader v)
v
- the new header for this table. If null, the header will be
hidden.public TableColumn getColumn(int i)
i
- the numerical index of the column
TableColumn
whose index is i.public void setColumn(int i, TableColumn v)
i
- the numerical index of the columnv
- the column that is to be mapped at ipublic final SingleSelectionModel getRowSelectionModel()
SingleSelectionModel
that is responsible
for selecting the current row.public void setRowSelectionModel(SingleSelectionModel v)
SingleSelectionModel
that will be responsible
for selecting the current row.
v
- a SingleSelectionModel
public SingleSelectionModel getColumnSelectionModel()
SingleSelectionModel
that is responsible
for selecting the current column.public void setColumnSelectionModel(SingleSelectionModel v)
SingleSelectionModel
that will be responsible
for selecting the current column.
v
- a SingleSelectionModel
public void clearSelection(PageState s)
s
- represents the state of the current requestpublic final TableCellRenderer getDefaultCellRenderer()
TableCellRenderer
.public final void setDefaultCellRenderer(TableCellRenderer v)
TableCellRenderer
.
v
- the default TableCellRenderer
public final Component getEmptyView()
public final void setEmptyView(Component v)
new Label("The table is empty")
.
v
- a Bebop componentpublic String getWidth()
public void setWidth(String v)
v
- the HTML width of the tablepublic String getBorder()
public void setBorder(String v)
v
- the HTML border of the tablepublic String getCellSpacing()
public void setCellSpacing(String v)
v
- the HTML width of the tablepublic String getCellPadding()
public void setCellPadding(String v)
v
- the HTML cell padding of the tablepublic void respond(PageState s) throws javax.servlet.ServletException
respond
in interface Component
respond
in class SimpleComponent
s
- the page state
javax.servlet.ServletException
public void register(Page p)
register
in interface Component
register
in class SimpleComponent
p
- the page that contains this tablepublic Iterator children()
children
in interface Component
children
in class SimpleComponent
public boolean isSelectedRow(PageState s, Object rowKey)
s
- the page staterowKey
- the key that identifies the row
true
if the row is currently selected;
false
otherwise.public boolean isSelectedColumn(PageState s, Object column)
s
- the page statecolumn
- a key that identifes the column. Should be consistent
with the type used by the column selection model.
true
if the column is selected;
false
otherwise.public boolean isSelectedCell(PageState s, Object rowKey, Object column)
s
- represents the state of the page in the current requestrowKey
- the row key of the cell. The concrete type should agree
with the type used by the row selection model.column
- the column of the cell. The concrete type should agree
with the type used by the column selection model.
true
if the cell is selected;
false
otherwise.public void setStriped(boolean striped)
public boolean getStriped()
protected void generateExtraXMLAttributes(PageState state, Element element)
generateXML
produces by default.
state
- represents the current requestelement
- the XML element representing this tablepublic void generateXML(PageState s, Element p)
TableModel
from the Table.MatrixTableModelBuilder
and iterates over the model's
rows. The value in each table cell is rendered with the help of the
column's table cell renderer.
Generates an XML fragment:
<bebop:table> <bebop:thead> <bebpp:cell>...</cell> ... </bebop:thead> <bebop:tbody> <bebop:trow> <bebpp:cell>...</cell> ... </bebop:trow> ... </bebop:tbody> </bebop:table>
generateXML
in interface Component
generateXML
in class SimpleComponent
s
- the page statep
- the parent Element
protected Component getControler()
public TableModel getTableModel(PageState s)
s
- represents the state of the page in the current request
public void lock()
lock
in interface Lockable
lock
in class SimpleComponent
Lockable.lock()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |