public abstract class

HTMLTable

extends Panel
implements HasClickHandlers HasDoubleClickHandlers SourcesTableEvents
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Panel
         ↳ com.google.gwt.user.client.ui.HTMLTable
Known Direct Subclasses

Class Overview

HTMLTable contains the common table algorithms for Grid and FlexTable.

Summary

Nested Classes
class HTMLTable.Cell Return value for getCellForEvent(ClickEvent)
class HTMLTable.CellFormatter This class contains methods used to format a table's cells. 
class HTMLTable.ColumnFormatter This class contains methods used to format a table's columns. 
class HTMLTable.RowFormatter This class contains methods used to format a table's rows. 
[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
HTMLTable()
Create a new empty HTML Table.
Public Methods
HandlerRegistration addClickHandler(ClickHandler handler)
Adds a ClickEvent handler.
HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
Adds a DoubleClickEvent handler.
void addTableListener(TableListener listener)
This method is deprecated. add a click handler instead and use getCellForEvent(ClickEvent) to get the cell information (remember to check for a null return value)
void clear()
Removes all widgets from this table, but does not remove other HTML or text contents of cells.
void clear(boolean clearInnerHTML)
Removes all widgets from this table, optionally clearing the inner HTML of each cell.
boolean clearCell(int row, int column)
Clears the cell at the given row and column.
abstract int getCellCount(int row)
Gets the number of cells in a given row.
HTMLTable.Cell getCellForEvent(ClickEvent event)
Given a click event, return the Cell that was clicked, or null if the event did not hit this table.
HTMLTable.CellFormatter getCellFormatter()
Gets the HTMLTable.CellFormatter associated with this table.
int getCellPadding()
Gets the amount of padding that is added around all cells.
int getCellSpacing()
Gets the amount of spacing that is added around all cells.
HTMLTable.ColumnFormatter getColumnFormatter()
Gets the column formatter.
String getHTML(int row, int column)
Gets the HTML contents of the specified cell.
abstract int getRowCount()
Gets the number of rows present in this table.
HTMLTable.RowFormatter getRowFormatter()
Gets the RowFormatter associated with this table.
String getText(int row, int column)
Gets the text within the specified cell.
Widget getWidget(int row, int column)
Gets the widget in the specified cell.
boolean isCellPresent(int row, int column)
Determines whether the specified cell exists.
Iterator<Widget> iterator()
Returns an iterator containing all the widgets in this table.
boolean remove(Widget widget)
Remove the specified widget from the table.
void removeTableListener(TableListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by an add*Handler method instead
void setBorderWidth(int width)
Sets the width of the table's border.
void setCellPadding(int padding)
Sets the amount of padding to be added around all cells.
void setCellSpacing(int spacing)
Sets the amount of spacing to be added around all cells.
void setHTML(int row, int column, SafeHtml html)
Sets the HTML contents of the specified cell.
void setHTML(int row, int column, String html)
Sets the HTML contents of the specified cell.
void setText(int row, int column, String text)
Sets the text within the specified cell.
void setWidget(int row, int column, Widget widget)
Sets the widget within the specified cell.
Protected Methods
void checkCellBounds(int row, int column)
Bounds checks that the cell exists at the specified location.
void checkRowBounds(int row)
Checks that the row is within the correct bounds.
Element createCell()
Creates a new cell.
Element getBodyElement()
Gets the table's TBODY element.
int getDOMCellCount(int row)
Directly ask the underlying DOM what the cell count on the given row is.
int getDOMCellCount(Element tableBody, int row)
Directly ask the underlying DOM what the cell count on the given row is.
int getDOMRowCount(Element elem)
int getDOMRowCount()
Directly ask the underlying DOM what the row count is.
Element getEventTargetCell(Event event)
Determines the TD associated with the specified event.
void insertCell(int row, int column)
Inserts a new cell into the specified row.
void insertCells(int row, int column, int count)
Inserts a number of cells before the specified cell.
int insertRow(int beforeRow)
Inserts a new row into the table.
boolean internalClearCell(Element td, boolean clearInnerHTML)
Does actual clearing, used by clearCell and cleanCell.
void onEnsureDebugId(String baseID)
Affected Elements:
  • -(row)#-(cell)# = the cell at the given row and cell index.
abstract void prepareCell(int row, int column)
Subclasses must implement this method.
void prepareColumn(int column)
Subclasses can implement this method.
abstract void prepareRow(int row)
Subclasses must implement this method.
void removeCell(int row, int column)
Removes the specified cell from the table.
void removeRow(int row)
Removes the specified row from the table.
void setCellFormatter(HTMLTable.CellFormatter cellFormatter)
Sets the table's CellFormatter.
void setColumnFormatter(HTMLTable.ColumnFormatter formatter)
void setRowFormatter(HTMLTable.RowFormatter rowFormatter)
Sets the table's RowFormatter.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.Panel
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasWidgets
From interface com.google.gwt.user.client.ui.HasWidgets.ForIsWidget
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesTableEvents
From interface java.lang.Iterable

Public Constructors

public HTMLTable ()

Create a new empty HTML Table.

Public Methods

public HandlerRegistration addClickHandler (ClickHandler handler)

Adds a ClickEvent handler.

Parameters
handler the click handler
Returns

public HandlerRegistration addDoubleClickHandler (DoubleClickHandler handler)

Adds a DoubleClickEvent handler.

Parameters
handler the double click handler
Returns

public void addTableListener (TableListener listener)

This method is deprecated.
add a click handler instead and use getCellForEvent(ClickEvent) to get the cell information (remember to check for a null return value)

Adds a listener to the current table.

Parameters
listener listener to add

public void clear ()

Removes all widgets from this table, but does not remove other HTML or text contents of cells.

public void clear (boolean clearInnerHTML)

Removes all widgets from this table, optionally clearing the inner HTML of each cell. Note that this method does not remove any cells or rows.

Parameters
clearInnerHTML should the cell's inner html be cleared?

public boolean clearCell (int row, int column)

Clears the cell at the given row and column. If it contains a Widget, it will be removed from the table. If not, its contents will simply be cleared.

Parameters
row the widget's row
column the widget's column
Returns
  • true if a widget was removed

public abstract int getCellCount (int row)

Gets the number of cells in a given row.

Parameters
row the row whose cells are to be counted
Returns
  • the number of cells present in the row

public HTMLTable.Cell getCellForEvent (ClickEvent event)

Given a click event, return the Cell that was clicked, or null if the event did not hit this table. The cell can also be null if the click event does not occur on a specific cell.

Parameters
event A click event of indeterminate origin
Returns
  • The appropriate cell, or null

public HTMLTable.CellFormatter getCellFormatter ()

Gets the HTMLTable.CellFormatter associated with this table. Use casting to get subclass-specific functionality

Returns
  • this table's cell formatter

public int getCellPadding ()

Gets the amount of padding that is added around all cells.

Returns
  • the cell padding, in pixels

public int getCellSpacing ()

Gets the amount of spacing that is added around all cells.

Returns
  • the cell spacing, in pixels

public HTMLTable.ColumnFormatter getColumnFormatter ()

Gets the column formatter.

Returns
  • the column formatter

public String getHTML (int row, int column)

Gets the HTML contents of the specified cell.

Parameters
row the cell's row
column the cell's column
Returns
  • the cell's HTML contents

public abstract int getRowCount ()

Gets the number of rows present in this table.

Returns
  • the table's row count

public HTMLTable.RowFormatter getRowFormatter ()

Gets the RowFormatter associated with this table.

Returns
  • the table's row formatter

public String getText (int row, int column)

Gets the text within the specified cell.

Parameters
row the cell's row
column the cell's column
Returns
  • the cell's text contents

public Widget getWidget (int row, int column)

Gets the widget in the specified cell.

Parameters
row the cell's row
column the cell's column
Returns
  • the widget in the specified cell, or null if none is present

public boolean isCellPresent (int row, int column)

Determines whether the specified cell exists.

Parameters
row the cell's row
column the cell's column
Returns
  • true if the specified cell exists

public Iterator<Widget> iterator ()

Returns an iterator containing all the widgets in this table.

Returns
  • the iterator

public boolean remove (Widget widget)

Remove the specified widget from the table.

Parameters
widget widget to remove
Returns
  • was the widget removed from the table.

public void removeTableListener (TableListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by an add*Handler method instead

Removes the specified table listener.

Parameters
listener listener to remove

public void setBorderWidth (int width)

Sets the width of the table's border. This border is displayed around all cells in the table.

Parameters
width the width of the border, in pixels

public void setCellPadding (int padding)

Sets the amount of padding to be added around all cells.

Parameters
padding the cell padding, in pixels

public void setCellSpacing (int spacing)

Sets the amount of spacing to be added around all cells.

Parameters
spacing the cell spacing, in pixels

public void setHTML (int row, int column, SafeHtml html)

Sets the HTML contents of the specified cell.

Parameters
row the cell's row
column the cell's column
html the cell's safe html contents

public void setHTML (int row, int column, String html)

Sets the HTML contents of the specified cell.

Parameters
row the cell's row
column the cell's column
html the cell's HTML contents

public void setText (int row, int column, String text)

Sets the text within the specified cell.

Parameters
row the cell's row
column cell's column
text the cell's text contents

public void setWidget (int row, int column, Widget widget)

Sets the widget within the specified cell.

Inherited implementations may either throw IndexOutOfBounds exception if the cell does not exist, or allocate a new cell to store the content.

FlexTable will automatically allocate the cell at the correct location and then set the widget. Grid will set the widget if and only if the cell is within the Grid's bounding box.

Parameters
row the cell's row
column the cell's column
widget The widget to be added

Protected Methods

protected void checkCellBounds (int row, int column)

Bounds checks that the cell exists at the specified location.

Parameters
row cell's row
column cell's column

protected void checkRowBounds (int row)

Checks that the row is within the correct bounds.

Parameters
row row index to check

protected Element createCell ()

Creates a new cell. Override this method if the cell should have initial contents.

Returns
  • the newly created TD

protected Element getBodyElement ()

Gets the table's TBODY element.

Returns
  • the TBODY element

protected int getDOMCellCount (int row)

Directly ask the underlying DOM what the cell count on the given row is.

Parameters
row the row
Returns
  • number of columns in the row

protected int getDOMCellCount (Element tableBody, int row)

Directly ask the underlying DOM what the cell count on the given row is.

Parameters
tableBody the element
row the row
Returns
  • number of columns in the row

protected int getDOMRowCount (Element elem)

protected int getDOMRowCount ()

Directly ask the underlying DOM what the row count is.

Returns
  • Returns the number of rows in the table

protected Element getEventTargetCell (Event event)

Determines the TD associated with the specified event.

Parameters
event the event to be queried
Returns
  • the TD associated with the event, or null if none is found.

protected void insertCell (int row, int column)

Inserts a new cell into the specified row.

Parameters
row the row into which the new cell will be inserted
column the column before which the cell will be inserted

protected void insertCells (int row, int column, int count)

Inserts a number of cells before the specified cell.

Parameters
row the row into which the new cells will be inserted
column the column before which the new cells will be inserted
count number of cells to be inserted

protected int insertRow (int beforeRow)

Inserts a new row into the table.

Parameters
beforeRow the index before which the new row will be inserted
Returns
  • the index of the newly-created row

protected boolean internalClearCell (Element td, boolean clearInnerHTML)

Does actual clearing, used by clearCell and cleanCell. All HTMLTable methods should use internalClearCell rather than clearCell, as clearCell may be overridden in subclasses to format an empty cell.

Parameters
td element to clear
clearInnerHTML should the cell's inner html be cleared?
Returns
  • returns whether a widget was cleared

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -(row)#-(cell)# = the cell at the given row and cell index.

Parameters
baseID the base ID used by the main element

protected abstract void prepareCell (int row, int column)

Subclasses must implement this method. It allows them to decide what to do just before a cell is accessed. If the cell already exists, this method must do nothing. Otherwise, a subclass must either ensure that the cell exists or throw an IndexOutOfBoundsException.

Parameters
row the cell's row
column the cell's column

protected void prepareColumn (int column)

Subclasses can implement this method. It allows them to decide what to do just before a column is accessed. For classes, such as FlexTable, that do not have a concept of a global column length can ignore this method.

Parameters
column the cell's column

protected abstract void prepareRow (int row)

Subclasses must implement this method. If the row already exists, this method must do nothing. Otherwise, a subclass must either ensure that the row exists or throw an IndexOutOfBoundsException.

Parameters
row the cell's row

protected void removeCell (int row, int column)

Removes the specified cell from the table.

Parameters
row the row of the cell to remove
column the column of cell to remove

protected void removeRow (int row)

Removes the specified row from the table.

Parameters
row the index of the row to be removed

protected void setCellFormatter (HTMLTable.CellFormatter cellFormatter)

Sets the table's CellFormatter.

Parameters
cellFormatter the table's cell formatter

protected void setColumnFormatter (HTMLTable.ColumnFormatter formatter)

protected void setRowFormatter (HTMLTable.RowFormatter rowFormatter)

Sets the table's RowFormatter.

Parameters
rowFormatter the table's row formatter