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

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.widgetideas.table.client.overrides.HTMLTable
                  extended by com.google.gwt.widgetideas.table.client.overrides.Grid
                      extended by com.google.gwt.widgetideas.table.client.SelectionGrid
                          extended by com.google.gwt.widgetideas.table.client.SortableGrid
All Implemented Interfaces:
com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasWidgets, com.google.gwt.user.client.ui.SourcesTableEvents, SourceTableSelectionEvents
Direct Known Subclasses:
FixedWidthGrid

public class SortableGrid
extends SelectionGrid

A variation of the Grid that supports many more options such as lazy row and column creation, row movement, hovering, row selection, and better column resizing.


Nested Class Summary
static class SortableGrid.ColumnSorter
          The column sorter defines an algorithm to sort columns.
 class SortableGrid.ColumnSorterCallback
          Callback that is called when the row sorting is complete.
 
Nested classes/interfaces inherited from class com.google.gwt.widgetideas.table.client.SelectionGrid
SelectionGrid.SelectionGridCellFormatter, SelectionGrid.SelectionGridRowFormatter, SelectionGrid.SelectionPolicy
 
Nested classes/interfaces inherited from class com.google.gwt.widgetideas.table.client.overrides.HTMLTable
HTMLTable.CellFormatter, HTMLTable.ColumnFormatter, HTMLTable.RowFormatter, HTMLTable.WidgetMapper
 
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
 
Fields inherited from class com.google.gwt.widgetideas.table.client.overrides.Grid
numColumns, numRows
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
SortableGrid()
          Constructor.
SortableGrid(int rows, int columns)
          Constructs a SortableGrid with the requested size.
 
Method Summary
 void addSortableColumnsListener(SortableColumnsListener listener)
          Add a SortableColumnsListener listener.
protected  void fireColumnSorted()
          Fire column sorted event to listeners.
 SortableGrid.ColumnSorter getColumnSorter()
           
protected  SortableGrid.ColumnSorter getColumnSorter(boolean createAsNeeded)
          Get the SortableGrid.ColumnSorter.
 TableModel.ColumnSortList getColumnSortList()
           
 void moveRowDown(int row)
          Move a row up (relative to the screen) one index to a lesser index.
 void moveRowUp(int row)
          Move a row down (relative to the screen) one index to a greater index.
 void removeSortableColumnsListener(SortableColumnsListener listener)
          Remove a SortableColumnsListenerbleColumnsListener listener.
 void reverseRows()
          Completely reverse the order of all rows in the table.
 void setColumnSorter(SortableGrid.ColumnSorter sorter)
          Set the SortableGrid.ColumnSorter.
 void sortColumn(int column)
          Sort the grid according to the specified column.
 void sortColumn(int column, boolean ascending)
          Sort the grid according to the specified column.
 void swapRows(int row1, int row2)
          Swap the positions of two rows.
protected  void swapRowsRaw(int row1, int row2)
          Swap two rows without checking the cell bounds.
 
Methods inherited from class com.google.gwt.widgetideas.table.client.SelectionGrid
addTableSelectionListener, deselectRow, deselectRows, getSelectedRows, getSelectedRowsMap, getSelectionGridCellFormatter, getSelectionGridRowFormatter, getSelectionPolicy, hoverCell, insertRow, isRowSelected, onBrowserEvent, removeRow, removeTableSelectionListener, selectRow, selectRow, selectRow, setSelectionPolicy
 
Methods inherited from class com.google.gwt.widgetideas.table.client.overrides.Grid
createCell, getCellCount, getColumnCount, getRowCount, prepareCell, prepareColumn, prepareRow, resize, resizeColumns, resizeRows
 
Methods inherited from class com.google.gwt.widgetideas.table.client.overrides.HTMLTable
addTableListener, checkCellBounds, checkRowBounds, cleanCell, clear, clearAll, clearCell, getBodyElement, getCellContainer, getCellContainer, getCellFormatter, getCellPadding, getCellSpacing, getColumnFormatter, getDOMCellCount, getDOMCellCount, getDOMRowCount, getDOMRowCount, getEventTargetCell, getEventTargetRow, getHTML, getRowFormatter, getRowIndex, getText, getWidget, getWidgetMap, insertCell, insertCells, internalClearCell, isCellPresent, iterator, remove, removeCell, removeTableListener, setBodyElement, setBorderWidth, setCellFormatter, setCellPadding, setCellSpacing, setClearText, setColumnFormatter, setElement, setHTML, setRowFormatter, setText, setWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
add, adopt, adopt, disown, doAttachChildren, doDetachChildren, onLoad, onUnload, orphan
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onAttach, 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, setHeight, 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
 

Constructor Detail

SortableGrid

public SortableGrid()
Constructor.


SortableGrid

public SortableGrid(int rows,
                    int columns)
Constructs a SortableGrid with the requested size.

Parameters:
rows - the number of rows
columns - the number of columns
Throws:
java.lang.IndexOutOfBoundsException
Method Detail

addSortableColumnsListener

public void addSortableColumnsListener(SortableColumnsListener listener)
Add a SortableColumnsListener listener.

Parameters:
listener - the listener

getColumnSorter

public SortableGrid.ColumnSorter getColumnSorter()
Returns:
the column sorter used to sort columns

getColumnSortList

public TableModel.ColumnSortList getColumnSortList()
Returns:
the TableModel.ColumnSortList of previously sorted columns

moveRowDown

public void moveRowDown(int row)
Move a row up (relative to the screen) one index to a lesser index.

Parameters:
row - the row index to move
Throws:
java.lang.IndexOutOfBoundsException

moveRowUp

public void moveRowUp(int row)
Move a row down (relative to the screen) one index to a greater index.

Parameters:
row - the row index to move
Throws:
java.lang.IndexOutOfBoundsException

removeSortableColumnsListener

public void removeSortableColumnsListener(SortableColumnsListener listener)
Remove a SortableColumnsListenerbleColumnsListener listener.

Parameters:
listener - the listener to remove

reverseRows

public void reverseRows()
Completely reverse the order of all rows in the table.


setColumnSorter

public void setColumnSorter(SortableGrid.ColumnSorter sorter)
Set the SortableGrid.ColumnSorter.

Parameters:
sorter - the new SortableGrid.ColumnSorter

sortColumn

public void sortColumn(int column)
Sort the grid according to the specified column. If the column is already sorted, reverse sort it.

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

sortColumn

public void sortColumn(int column,
                       boolean ascending)
Sort the grid according to the specified column.

Parameters:
column - the column to sort
ascending - sort the column in ascending order
Throws:
java.lang.IndexOutOfBoundsException

swapRows

public void swapRows(int row1,
                     int row2)
Swap the positions of two rows.

Parameters:
row1 - the first row to swap
row2 - the second row to swap
Throws:
java.lang.IndexOutOfBoundsException

fireColumnSorted

protected void fireColumnSorted()
Fire column sorted event to listeners.


getColumnSorter

protected SortableGrid.ColumnSorter getColumnSorter(boolean createAsNeeded)
Get the SortableGrid.ColumnSorter. Optionally create a DefaultColumnSorter if the user hasn't specified one already.

Parameters:
createAsNeeded - create a default sorter if needed
Returns:
the column sorter

swapRowsRaw

protected void swapRowsRaw(int row1,
                           int row2)
Swap two rows without checking the cell bounds.

Parameters:
row1 - the first row to swap
row2 - the second row to swap