Package com.google.gwt.user.client.ui
Class HTMLTable
- 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
-
- All Implemented Interfaces:
HasAllDragAndDropHandlers,HasClickHandlers,HasDoubleClickHandlers,HasDragEndHandlers,HasDragEnterHandlers,HasDragHandlers,HasDragLeaveHandlers,HasDragOverHandlers,HasDragStartHandlers,HasDropHandlers,HasAttachHandlers,HasHandlers,EventListener,HasVisibility,HasWidgets,HasWidgets.ForIsWidget,IsWidget,SourcesTableEvents,java.lang.Iterable<Widget>
public abstract class HTMLTable extends Panel implements SourcesTableEvents, HasAllDragAndDropHandlers, HasClickHandlers, HasDoubleClickHandlers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classHTMLTable.CellReturn value forgetCellForEvent(com.google.gwt.event.dom.client.ClickEvent).classHTMLTable.CellFormatterThis class contains methods used to format a table's cells.classHTMLTable.ColumnFormatterThis class contains methods used to format a table's columns.classHTMLTable.RowFormatterThis class contains methods used to format a table's rows.-
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
-
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets
HasWidgets.ForIsWidget
-
-
Field Summary
-
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSink
-
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
-
Constructor Summary
Constructors Constructor Description HTMLTable()Create a new empty HTML Table.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) voidaddCells(Element tbody, int row, int num)HandlerRegistrationaddClickHandler(ClickHandler handler)Adds aClickEventhandler.HandlerRegistrationaddDoubleClickHandler(DoubleClickHandler handler)Adds aDoubleClickEventhandler.HandlerRegistrationaddDragEndHandler(DragEndHandler handler)Adds aDragEndEventhandler.HandlerRegistrationaddDragEnterHandler(DragEnterHandler handler)Adds aDragEnterEventhandler.HandlerRegistrationaddDragHandler(DragHandler handler)Adds aDragEventhandler.HandlerRegistrationaddDragLeaveHandler(DragLeaveHandler handler)Adds aDragLeaveEventhandler.HandlerRegistrationaddDragOverHandler(DragOverHandler handler)Adds aDragOverEventhandler.HandlerRegistrationaddDragStartHandler(DragStartHandler handler)Adds aDragStartEventhandler.HandlerRegistrationaddDropHandler(DropHandler handler)Adds aDropEventhandler.voidaddTableListener(TableListener listener)Deprecated.add a click handler instead and usegetCellForEvent(ClickEvent)to get the cell information (remember to check for a null return value)protected voidcheckCellBounds(int row, int column)Bounds checks that the cell exists at the specified location.protected voidcheckRowBounds(int row)Checks that the row is within the correct bounds.voidclear()Removes all widgets from this table, but does not remove other HTML or text contents of cells.voidclear(boolean clearInnerHTML)Removes all widgets from this table, optionally clearing the inner HTML of each cell.booleanclearCell(int row, int column)Clears the cell at the given row and column.protected ElementcreateCell()Creates a new cell.protected ElementgetBodyElement()Gets the table's TBODY element.abstract intgetCellCount(int row)Gets the number of cells in a given row.HTMLTable.CellgetCellForEvent(ClickEvent event)Given a click event, return the Cell that was clicked, or null if the event did not hit this table.HTMLTable.CellFormattergetCellFormatter()Gets theHTMLTable.CellFormatterassociated with this table.intgetCellPadding()Gets the amount of padding that is added around all cells.intgetCellSpacing()Gets the amount of spacing that is added around all cells.HTMLTable.ColumnFormattergetColumnFormatter()Gets the column formatter.protected intgetDOMCellCount(int row)Directly ask the underlying DOM what the cell count on the given row is.protected intgetDOMCellCount(Element tableBody, int row)Directly ask the underlying DOM what the cell count on the given row is.protected intgetDOMCellCount(Element tableBody, int row)Deprecated.Call and overridegetDOMCellCount(Element, int)instead.protected intgetDOMRowCount()Directly ask the underlying DOM what the row count is.protected intgetDOMRowCount(Element tbody)protected intgetDOMRowCount(Element tbody)Deprecated.Call and overridegetDOMRowCount(Element)instead.protected ElementgetEventTargetCell(Event event)Determines the TD associated with the specified event.java.lang.StringgetHTML(int row, int column)Gets the HTML contents of the specified cell.abstract intgetRowCount()Gets the number of rows present in this table.HTMLTable.RowFormattergetRowFormatter()Gets the RowFormatter associated with this table.java.lang.StringgetText(int row, int column)Gets the text within the specified cell.WidgetgetWidget(int row, int column)Gets the widget in the specified cell.protected voidinsertCell(int row, int column)Inserts a new cell into the specified row.protected voidinsertCells(int row, int column, int count)Inserts a number of cells before the specified cell.protected intinsertRow(int beforeRow)Inserts a new row into the table.protected booleaninternalClearCell(Element td, boolean clearInnerHTML)Does actual clearing, used by clearCell and cleanCell.protected booleaninternalClearCell(Element td, boolean clearInnerHTML)Deprecated.Call and overrideinternalClearCell(com.google.gwt.dom.client.Element,boolean)instead.booleanisCellPresent(int row, int column)Determines whether the specified cell exists.java.util.Iterator<Widget>iterator()Returns an iterator containing all the widgets in this table.protected voidonEnsureDebugId(java.lang.String baseID)Affected Elements: -(row)#-(cell)# = the cell at the given row and cell index.protected abstract voidprepareCell(int row, int column)Subclasses must implement this method.protected voidprepareColumn(int column)Subclasses can implement this method.protected abstract voidprepareRow(int row)Subclasses must implement this method.booleanremove(Widget widget)Remove the specified widget from the table.protected voidremoveCell(int row, int column)Removes the specified cell from the table.protected voidremoveRow(int row)Removes the specified row from the table.voidremoveTableListener(TableListener listener)Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned by an add*Handler method insteadvoidsetBorderWidth(int width)Sets the width of the table's border.protected voidsetCellFormatter(HTMLTable.CellFormatter cellFormatter)Sets the table's CellFormatter.voidsetCellPadding(int padding)Sets the amount of padding to be added around all cells.voidsetCellSpacing(int spacing)Sets the amount of spacing to be added around all cells.protected voidsetColumnFormatter(HTMLTable.ColumnFormatter formatter)voidsetHTML(int row, int column, SafeHtml html)Sets the HTML contents of the specified cell.voidsetHTML(int row, int column, java.lang.String html)Sets the HTML contents of the specified cell.protected voidsetRowFormatter(HTMLTable.RowFormatter rowFormatter)Sets the table's RowFormatter.voidsetText(int row, int column, java.lang.String text)Sets the text within the specified cell.voidsetWidget(int row, int column, IsWidget widget)Overloaded version for IsWidget.voidsetWidget(int row, int column, Widget widget)Sets the widget within the specified cell.-
Methods inherited from class com.google.gwt.user.client.ui.Panel
add, add, adopt, doAttachChildren, doDetachChildren, orphan, remove
-
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
-
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
-
-
-
-
Method Detail
-
addClickHandler
public HandlerRegistration addClickHandler(ClickHandler handler)
Description copied from interface:HasClickHandlersAdds aClickEventhandler.- Specified by:
addClickHandlerin interfaceHasClickHandlers- Parameters:
handler- the click handler- Returns:
HandlerRegistrationused to remove this handler
-
addDoubleClickHandler
public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
Description copied from interface:HasDoubleClickHandlersAdds aDoubleClickEventhandler.- Specified by:
addDoubleClickHandlerin interfaceHasDoubleClickHandlers- Parameters:
handler- the double click handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragEndHandler
public HandlerRegistration addDragEndHandler(DragEndHandler handler)
Description copied from interface:HasDragEndHandlersAdds aDragEndEventhandler.- Specified by:
addDragEndHandlerin interfaceHasDragEndHandlers- Parameters:
handler- the drag end handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragEnterHandler
public HandlerRegistration addDragEnterHandler(DragEnterHandler handler)
Description copied from interface:HasDragEnterHandlersAdds aDragEnterEventhandler.- Specified by:
addDragEnterHandlerin interfaceHasDragEnterHandlers- Parameters:
handler- the drag end handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragHandler
public HandlerRegistration addDragHandler(DragHandler handler)
Description copied from interface:HasDragHandlersAdds aDragEventhandler.- Specified by:
addDragHandlerin interfaceHasDragHandlers- Parameters:
handler- the drag handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragLeaveHandler
public HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler)
Description copied from interface:HasDragLeaveHandlersAdds aDragLeaveEventhandler.- Specified by:
addDragLeaveHandlerin interfaceHasDragLeaveHandlers- Parameters:
handler- the drag leave handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragOverHandler
public HandlerRegistration addDragOverHandler(DragOverHandler handler)
Description copied from interface:HasDragOverHandlersAdds aDragOverEventhandler.- Specified by:
addDragOverHandlerin interfaceHasDragOverHandlers- Parameters:
handler- the drag over handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragStartHandler
public HandlerRegistration addDragStartHandler(DragStartHandler handler)
Description copied from interface:HasDragStartHandlersAdds aDragStartEventhandler.- Specified by:
addDragStartHandlerin interfaceHasDragStartHandlers- Parameters:
handler- the drag start handler- Returns:
HandlerRegistrationused to remove this handler
-
addDropHandler
public HandlerRegistration addDropHandler(DropHandler handler)
Description copied from interface:HasDropHandlersAdds aDropEventhandler.- Specified by:
addDropHandlerin interfaceHasDropHandlers- Parameters:
handler- the drop handler- Returns:
HandlerRegistrationused to remove this handler
-
addTableListener
@Deprecated public void addTableListener(TableListener listener)
Deprecated.add a click handler instead and usegetCellForEvent(ClickEvent)to get the cell information (remember to check for a null return value)Adds a listener to the current table.- Specified by:
addTableListenerin interfaceSourcesTableEvents- Parameters:
listener- listener to add
-
clear
public void clear()
Removes all widgets from this table, but does not remove other HTML or text contents of cells.- Specified by:
clearin interfaceHasWidgets- Overrides:
clearin classPanel
-
clear
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?
-
clearCell
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 rowcolumn- the widget's column- Returns:
- true if a widget was removed
- Throws:
java.lang.IndexOutOfBoundsException
-
getCellCount
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
-
getCellForEvent
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
-
getCellFormatter
public HTMLTable.CellFormatter getCellFormatter()
Gets theHTMLTable.CellFormatterassociated with this table. Use casting to get subclass-specific functionality- Returns:
- this table's cell formatter
-
getCellPadding
public int getCellPadding()
Gets the amount of padding that is added around all cells.- Returns:
- the cell padding, in pixels
-
getCellSpacing
public int getCellSpacing()
Gets the amount of spacing that is added around all cells.- Returns:
- the cell spacing, in pixels
-
getColumnFormatter
public HTMLTable.ColumnFormatter getColumnFormatter()
Gets the column formatter.- Returns:
- the column formatter
-
getHTML
public java.lang.String getHTML(int row, int column)Gets the HTML contents of the specified cell.- Parameters:
row- the cell's rowcolumn- the cell's column- Returns:
- the cell's HTML contents
- Throws:
java.lang.IndexOutOfBoundsException
-
getRowCount
public abstract int getRowCount()
Gets the number of rows present in this table.- Returns:
- the table's row count
-
getRowFormatter
public HTMLTable.RowFormatter getRowFormatter()
Gets the RowFormatter associated with this table.- Returns:
- the table's row formatter
-
getText
public java.lang.String getText(int row, int column)Gets the text within the specified cell.- Parameters:
row- the cell's rowcolumn- the cell's column- Returns:
- the cell's text contents
- Throws:
java.lang.IndexOutOfBoundsException
-
getWidget
public Widget getWidget(int row, int column)
Gets the widget in the specified cell.- Parameters:
row- the cell's rowcolumn- the cell's column- Returns:
- the widget in the specified cell, or
nullif none is present - Throws:
java.lang.IndexOutOfBoundsException
-
isCellPresent
public boolean isCellPresent(int row, int column)Determines whether the specified cell exists.- Parameters:
row- the cell's rowcolumn- the cell's column- Returns:
trueif the specified cell exists
-
iterator
public java.util.Iterator<Widget> iterator()
Returns an iterator containing all the widgets in this table.- Specified by:
iteratorin interfaceHasWidgets- Specified by:
iteratorin interfacejava.lang.Iterable<Widget>- Returns:
- the iterator
-
remove
public boolean remove(Widget widget)
Remove the specified widget from the table.- Specified by:
removein interfaceHasWidgets- Specified by:
removein classPanel- Parameters:
widget- widget to remove- Returns:
- was the widget removed from the table.
-
removeTableListener
@Deprecated public void removeTableListener(TableListener listener)
Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned by an add*Handler method insteadRemoves the specified table listener.- Specified by:
removeTableListenerin interfaceSourcesTableEvents- Parameters:
listener- listener to remove
-
setBorderWidth
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
-
setCellPadding
public void setCellPadding(int padding)
Sets the amount of padding to be added around all cells.- Parameters:
padding- the cell padding, in pixels
-
setCellSpacing
public void setCellSpacing(int spacing)
Sets the amount of spacing to be added around all cells.- Parameters:
spacing- the cell spacing, in pixels
-
setHTML
public void setHTML(int row, int column, java.lang.String html)Sets the HTML contents of the specified cell.- Parameters:
row- the cell's rowcolumn- the cell's columnhtml- the cell's HTML contents- Throws:
java.lang.IndexOutOfBoundsException
-
setHTML
public void setHTML(int row, int column, SafeHtml html)Sets the HTML contents of the specified cell.- Parameters:
row- the cell's rowcolumn- the cell's columnhtml- the cell's safe html contents- Throws:
java.lang.IndexOutOfBoundsException
-
setText
public void setText(int row, int column, java.lang.String text)Sets the text within the specified cell.- Parameters:
row- the cell's rowcolumn- cell's columntext- the cell's text contents- Throws:
java.lang.IndexOutOfBoundsException
-
setWidget
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:
widget- The widget to be added, or null to clear the cellrow- the cell's rowcolumn- the cell's column- Throws:
java.lang.IndexOutOfBoundsException
-
setWidget
public void setWidget(int row, int column, IsWidget widget)Overloaded version for IsWidget.- See Also:
setWidget(int,int,Widget)
-
checkCellBounds
protected void checkCellBounds(int row, int column)Bounds checks that the cell exists at the specified location.- Parameters:
row- cell's rowcolumn- cell's column- Throws:
java.lang.IndexOutOfBoundsException
-
checkRowBounds
protected void checkRowBounds(int row)
Checks that the row is within the correct bounds.- Parameters:
row- row index to check- Throws:
java.lang.IndexOutOfBoundsException
-
createCell
protected Element createCell()
Creates a new cell. Override this method if the cell should have initial contents.- Returns:
- the newly created TD
-
getBodyElement
protected Element getBodyElement()
Gets the table's TBODY element.- Returns:
- the TBODY element
-
getDOMCellCount
protected int getDOMCellCount(Element tableBody, int row)
Directly ask the underlying DOM what the cell count on the given row is.- Parameters:
tableBody- the elementrow- the row- Returns:
- number of columns in the row
-
getDOMCellCount
@Deprecated protected int getDOMCellCount(Element tableBody, int row)
Deprecated.Call and overridegetDOMCellCount(Element, int)instead.
-
getDOMCellCount
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
-
getDOMRowCount
protected int getDOMRowCount()
Directly ask the underlying DOM what the row count is.- Returns:
- Returns the number of rows in the table
-
getDOMRowCount
protected int getDOMRowCount(Element tbody)
-
getDOMRowCount
@Deprecated protected int getDOMRowCount(Element tbody)
Deprecated.Call and overridegetDOMRowCount(Element)instead.
-
getEventTargetCell
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
nullif none is found.
-
insertCell
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 insertedcolumn- the column before which the cell will be inserted- Throws:
java.lang.IndexOutOfBoundsException
-
insertCells
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 insertedcolumn- the column before which the new cells will be insertedcount- number of cells to be inserted- Throws:
java.lang.IndexOutOfBoundsException
-
insertRow
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
- Throws:
java.lang.IndexOutOfBoundsException
-
internalClearCell
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 clearclearInnerHTML- should the cell's inner html be cleared?- Returns:
- returns whether a widget was cleared
-
internalClearCell
@Deprecated protected boolean internalClearCell(Element td, boolean clearInnerHTML)
Deprecated.Call and overrideinternalClearCell(com.google.gwt.dom.client.Element,boolean)instead.
-
onEnsureDebugId
protected void onEnsureDebugId(java.lang.String baseID)
Affected Elements:- -(row)#-(cell)# = the cell at the given row and cell index.
- Overrides:
onEnsureDebugIdin classUIObject- Parameters:
baseID- the base ID used by the main element- See Also:
UIObject.onEnsureDebugId(String)
-
prepareCell
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 anIndexOutOfBoundsException.- Parameters:
row- the cell's rowcolumn- the cell's column
-
prepareColumn
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 asFlexTable, that do not have a concept of a global column length can ignore this method.- Parameters:
column- the cell's column- Throws:
java.lang.IndexOutOfBoundsException
-
prepareRow
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 anIndexOutOfBoundsException.- Parameters:
row- the cell's row
-
removeCell
protected void removeCell(int row, int column)Removes the specified cell from the table.- Parameters:
row- the row of the cell to removecolumn- the column of cell to remove- Throws:
java.lang.IndexOutOfBoundsException
-
removeRow
protected void removeRow(int row)
Removes the specified row from the table.- Parameters:
row- the index of the row to be removed- Throws:
java.lang.IndexOutOfBoundsException
-
setCellFormatter
protected void setCellFormatter(HTMLTable.CellFormatter cellFormatter)
Sets the table's CellFormatter.- Parameters:
cellFormatter- the table's cell formatter
-
setColumnFormatter
protected void setColumnFormatter(HTMLTable.ColumnFormatter formatter)
-
setRowFormatter
protected void setRowFormatter(HTMLTable.RowFormatter rowFormatter)
Sets the table's RowFormatter.- Parameters:
rowFormatter- the table's row formatter
-
addCells
void addCells(Element tbody, int row, int num)
-
-