com.google.gwt.widgetideas.table.client
Class ScrollTable

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Panel
              extended by com.google.gwt.user.client.ui.ComplexPanel
                  extended by com.google.gwt.widgetideas.table.client.ScrollTable
All Implemented Interfaces:
com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasWidgets, com.google.gwt.user.client.ui.IndexedPanel, ResizableWidget
Direct Known Subclasses:
PagingScrollTable

public class ScrollTable
extends com.google.gwt.user.client.ui.ComplexPanel
implements ResizableWidget

ScrollTable consists of a fixed header and footer (optional) that remain visible and a scrollable body that contains the data.

In order for the columns in the header table and data table to line up, the two table must have the same margin, padding, and border widths. You can use CSS style sheets to manipulate the colors and styles of the cell's, but you must keep the actual sizes consistent (especially with respect to the left and right side of the cells).

CSS Style Rules


Nested Class Summary
static class ScrollTable.ResizePolicy
          The resize policies of table cells.
static class ScrollTable.ScrollPolicy
          The scroll policy of the table.
static interface ScrollTable.ScrollTableImages
          An ImageBundle that provides images for ScrollTable.
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
static java.lang.String DEFAULT_STYLE_NAME
          The default style name.
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
ScrollTable(FixedWidthGrid dataTable, FixedWidthFlexTable headerTable)
          Constructor.
ScrollTable(FixedWidthGrid dataTable, FixedWidthFlexTable headerTable, ScrollTable.ScrollTableImages images)
          Constructor.
 
Method Summary
 void autoFitColumnWidth(int column)
          Stretches or shrinks the column to automatically fit its data content.
 void fillWidth()
          Adjust all column widths so they take up the maximum amount of space without needing a horizontal scroll bar.
 int getCellPadding()
           
 int getCellSpacing()
           
 int getColumnWidth(int column)
          Return the column width for a given column index.
 FixedWidthGrid getDataTable()
           
protected  com.google.gwt.user.client.Element getDataWrapper()
           
 FixedWidthFlexTable getFooterTable()
           
 FixedWidthFlexTable getHeaderTable()
           
 int getMinWidth()
           
 ScrollTable.ResizePolicy getResizePolicy()
           
 ScrollTable.ScrollPolicy getScrollPolicy()
           
 boolean isAutoFitEnabled()
           
 boolean isColumnSortable(int column)
           
 boolean isSortingEnabled()
           
protected  void onAttach()
          Resize the widget and redistribute space as needed.
 void onBrowserEvent(com.google.gwt.user.client.Event event)
           
 void onResize(int width, int height)
          This method is called when the dimensions of the parent element change.
 void redraw()
          Redraw the table.
 boolean remove(com.google.gwt.user.client.ui.Widget child)
          Unsupported.
protected  void resizeTablesVertically()
          Fixes the table heights so the header is visible and the data takes up the remaining vertical space.
protected  void resizeTablesVerticallyNow()
          Helper method that actually performs the vertical resizing.
protected  void scrollTables(boolean baseHeader)
          Sets the scroll property of the header and data wrappers when scrolling.
 void setAutoFitEnabled(boolean autoFitEnabled)
          Enable or disable automatic column fitting via mouse clicks to the header cells.
 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 setColumnSortable(int column, boolean sortable)
          Enable or disable sorting on a specific column.
 int setColumnWidth(int column, int width)
          Set the width of a column.
protected  int setColumnWidth(int column, int width, int sacrificeColumn, boolean guarenteed)
          Set the width of a column.
 void setFooterTable(FixedWidthFlexTable footerTable)
          Set the footer table that appears under the data table.
 void setHeight(java.lang.String height)
           
 void setMinWidth(int minWidth)
          Set the minimum allowable width of the data table.
 void setResizePolicy(ScrollTable.ResizePolicy resizePolicy)
          Set the resize policy of the table.
 void setScrollPolicy(ScrollTable.ScrollPolicy scrollPolicy)
          Set the scroll policy of the table.
 void setSortingEnabled(boolean sortingEnabled)
          Enable or disable column sorting via mouse clicks to the header cells.
 
Methods inherited from class com.google.gwt.user.client.ui.ComplexPanel
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, insert, insert, iterator, remove
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
add, adopt, adopt, clear, disown, doAttachChildren, doDetachChildren, onLoad, onUnload, orphan
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onDetach, removeFromParent, setElement
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.widgetideas.client.ResizableWidget
getElement, isAttached
 

Field Detail

DEFAULT_STYLE_NAME

public static final java.lang.String DEFAULT_STYLE_NAME
The default style name.

See Also:
Constant Field Values
Constructor Detail

ScrollTable

public ScrollTable(FixedWidthGrid dataTable,
                   FixedWidthFlexTable headerTable)
Constructor.

Parameters:
dataTable - the data table
headerTable - the header table

ScrollTable

public ScrollTable(FixedWidthGrid dataTable,
                   FixedWidthFlexTable headerTable,
                   ScrollTable.ScrollTableImages images)
Constructor.

Parameters:
dataTable - the data table
headerTable - the header table
images - the images to use in the table
Method Detail

autoFitColumnWidth

public void autoFitColumnWidth(int column)
Stretches or shrinks the column to automatically fit its data content.

Parameters:
column - the column to fit
Throws:
java.lang.IndexOutOfBoundsException

fillWidth

public void fillWidth()
Adjust all column widths so they take up the maximum amount of space without needing a horizontal scroll bar. The distribution will be proportional to the current width of each column. The ScrollTable must be visible on the page for this method to work.


getCellPadding

public int getCellPadding()
Returns:
the cell padding of the tables, in pixels

getCellSpacing

public int getCellSpacing()
Returns:
the cell spacing of the tables, in pixels

getColumnWidth

public int getColumnWidth(int column)
Return the column width for a given column index.

Parameters:
column - the column index
Returns:
the column width in pixels

getDataTable

public FixedWidthGrid getDataTable()
Returns:
the data table

getFooterTable

public FixedWidthFlexTable getFooterTable()
Returns:
the footer table

getHeaderTable

public FixedWidthFlexTable getHeaderTable()
Returns:
the header table

getMinWidth

public int getMinWidth()
Returns:
the minimum width of the data table

getResizePolicy

public ScrollTable.ResizePolicy getResizePolicy()
Returns:
the resize policy

getScrollPolicy

public ScrollTable.ScrollPolicy getScrollPolicy()
Returns:
the current scroll policy

isAutoFitEnabled

public boolean isAutoFitEnabled()
Returns:
true if auto fitting is enabled, false if disabled

isColumnSortable

public boolean isColumnSortable(int column)
Parameters:
column - the column index
Returns:
true if the column is sortable, false if it is not sortable

isSortingEnabled

public boolean isSortingEnabled()
Returns:
true if sorting is enabled, false if disabled

onBrowserEvent

public void onBrowserEvent(com.google.gwt.user.client.Event event)
Specified by:
onBrowserEvent in interface com.google.gwt.user.client.EventListener
Overrides:
onBrowserEvent in class com.google.gwt.user.client.ui.Widget
See Also:
Widget

onResize

public void onResize(int width,
                     int height)
This method is called when the dimensions of the parent element change. Subclasses should override this method as needed.

Specified by:
onResize in interface ResizableWidget
Parameters:
width - the new client width of the element
height - the new client height of the element

redraw

public void redraw()
Redraw the table. This is a relatively cheap operation and should be called after modifying the header or footer sections.


remove

public boolean remove(com.google.gwt.user.client.ui.Widget child)
Unsupported.

Specified by:
remove in interface com.google.gwt.user.client.ui.HasWidgets
Overrides:
remove in class com.google.gwt.user.client.ui.ComplexPanel
Parameters:
child - the widget to be removed
Returns:
false
Throws:
java.lang.UnsupportedOperationException

setAutoFitEnabled

public void setAutoFitEnabled(boolean autoFitEnabled)
Enable or disable automatic column fitting via mouse clicks to the header cells.

Parameters:
autoFitEnabled - true to enable column sorting via mouse events

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

setColumnSortable

public void setColumnSortable(int column,
                              boolean sortable)
Enable or disable sorting on a specific column. All columns are sortable by default. Use setSortingEnabled(boolean) to disable sorting on all columns.

Parameters:
column - the index of the column
sortable - true to enable sorting for this column, false to disable

setColumnWidth

public int setColumnWidth(int column,
                          int width)
Set the width of a column. If the column has already been set using the #setGuarenteedColumnWidth(int, int) method, the column will no longer have a guarenteed column width.

Parameters:
column - the index of the column
width - the width in pixels
Returns:
the new column width

setFooterTable

public void setFooterTable(FixedWidthFlexTable footerTable)
Set the footer table that appears under the data table. If set to null, the footer table will not be shown.

Parameters:
footerTable - the table to use in the footer

setHeight

public void setHeight(java.lang.String height)
Overrides:
setHeight in class com.google.gwt.user.client.ui.UIObject
See Also:
UIObject

setMinWidth

public void setMinWidth(int minWidth)
Set the minimum allowable width of the data table. If the width of this Widget is smaller than the width of the data table, a horizontal scroll bar will appear. The minWidth property only applies to the policies ScrollTable.ResizePolicy.FILL_WIDTH and ScrollTable.ResizePolicy.FILL_WIDTH_DISABLED.

Parameters:
minWidth - the minimum width, or -1 to disable

setResizePolicy

public void setResizePolicy(ScrollTable.ResizePolicy resizePolicy)
Set the resize policy of the table.

Parameters:
resizePolicy - the resize policy

setScrollPolicy

public void setScrollPolicy(ScrollTable.ScrollPolicy scrollPolicy)
Set the scroll policy of the table.

Parameters:
scrollPolicy - the new scroll policy

setSortingEnabled

public void setSortingEnabled(boolean sortingEnabled)
Enable or disable column sorting via mouse clicks to the header cells.

Parameters:
sortingEnabled - true to enable column sorting via mouse events

getDataWrapper

protected com.google.gwt.user.client.Element getDataWrapper()
Returns:
the wrapper element around the data table

onAttach

protected void onAttach()
Resize the widget and redistribute space as needed.

Overrides:
onAttach in class com.google.gwt.user.client.ui.Widget

resizeTablesVertically

protected void resizeTablesVertically()
Fixes the table heights so the header is visible and the data takes up the remaining vertical space.


resizeTablesVerticallyNow

protected void resizeTablesVerticallyNow()
Helper method that actually performs the vertical resizing.


scrollTables

protected void scrollTables(boolean baseHeader)
Sets the scroll property of the header and data wrappers when scrolling.

Parameters:
baseHeader - If true, use the header as the alignment source

setColumnWidth

protected int setColumnWidth(int column,
                             int width,
                             int sacrificeColumn,
                             boolean guarenteed)
Set the width of a column.

Parameters:
column - the index of the column
width - the width in pixels
sacrificeColumn - the column that will be shrunk to maintain the width
guarenteed - if true, the column width cannot be changed
Returns:
the new column width