org.cafesip.gwtcomp.client.ui
Class SuperTable

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.HTMLTable
                  extended by com.google.gwt.user.client.ui.FlexTable
                      extended by org.cafesip.gwtcomp.client.ui.SuperTable
All Implemented Interfaces:
HasClickHandlers, HasHandlers, EventListener, HasWidgets, SourcesTableEvents, Iterable<Widget>

public class SuperTable
extends FlexTable

A table for listing tabular data with many features. Very often, applications need to display a list of data in tabular format. This widget allows you to create such tables. Here are some of the features this widget supports:

The properties of the table are highly configurable programatically or by using a style-sheet. The table properties are set using a SuperTableProperty object and the column properties are set using a ColumnProperty object. These objects are passed to the table either through the constructor or by the corresponding setter methods. (See the methods for important restrictions).

CSS Style Rules:

Screen-Shots:

In the above screen-shot, the top row contains a toolbar panel consisting of multiple toolbars. The left-most tool bar is the navigation toolbar for navigating between pages. The next toolbar is the command tool bar where applications can add their own actions such as "remove all selected rows". The righ-most toolbar is the user toolbar that applications can add their own widgets for specific actions. The second row is an application defined header. Applications can add zero or more such header rows. The third row is the column header. What rows are displayed or what toolbars are displayed is determined by the TableProperty and ColumnProperty objects.

Author:
Amit Chatterjee

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.FlexTable
FlexTable.FlexCellFormatter
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.HTMLTable
HTMLTable.Cell, HTMLTable.CellFormatter, HTMLTable.ColumnFormatter, HTMLTable.RowFormatter
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
SuperTable()
          An empty constructor for this class.
SuperTable(ColumnProperty[] columnsProperty)
          A constructor for this class.
SuperTable(ColumnProperty[] columnsProperty, SuperTableProperty properties)
          A constructor for this class with the column and table property objects supplied as parameters.
 
Method Summary
 void addRow(Widget[] row)
          Add a row to the table
 void addRow(Widget[] row, boolean selected)
          Add a row to the table and set it to selected.
 void addTableListener(SuperTableListener listener)
          Add a table listener.
 void addToUserToolbar(Widget w)
          Add an entry into the user tool bar.
 void addUserHeader(Widget widget)
          Adds a user header.
 void clear()
           
 void deleteRow(int index)
          Delete a row from the table.
 ColumnProperty[] getColumnsProperty()
          Returns the column property object.
 ListBox getCommandList()
          Returns the list box containing the application-defined list action items.
 int getCurrentPageRecordCount()
          Returns the row count in a current page.
 int getFirstRowIndex()
          Returns the index of the first row in the current page.
 Widget[][] getRows()
          Returns all the rows entries (and columns)
 int getRowSize()
          Return the number of rows.
 int[] getSelectedCell()
          Returns the user-selected cell.
 int getSelectedRowIndex()
          Returns the selected row index.
 int[] getSelectedRowIndices()
          Returns the indicies of the selected rows.
 ArrayList<Widget[]> getTableContent()
          Returns the content of the table in array list format.
 SuperTableProperty getTableProperty()
          Returns the table property.
 ToolbarPanel getToolbarPanel()
          Returns the toolbar panel object on the first row.
 Toolbar getUserBar()
          Returns the user tool bar.
 boolean isCellSelected(int row, int col)
          Is the given cell selected?
 boolean isRowInPage(int row)
          Check if a row is in the current page.
 boolean isRowSelected(int row)
          Returns if the row is selected.
 void redraw()
          In some cases, the table does not diplay the toolbar panel properly for very complex reasons.
 void removeTableListener(SuperTableListener listener)
          Remove a table listener.
 void setCell(Widget w, int row, int col)
          Replaces the widget in a given cell with a new one.
 void setCellSelected(int row, int col, boolean selected)
          Select/deselect a cell.
 void setColumnsProperty(ColumnProperty[] columnsProperty)
          Sets the column property.
 void setRow(Widget[] row, int index)
          Replaces a row with a new row.
 void setRow(Widget[] row, int index, Boolean selected)
          Replaces a row with a new row.
 void setRowSelected(int row, boolean selected)
          Select or deselect a row.
 void setTableProperty(SuperTableProperty tableProperty)
          Sets the table property.
 
Methods inherited from class com.google.gwt.user.client.ui.FlexTable
addCell, getCellCount, getFlexCellFormatter, getRowCount, insertCell, insertRow, prepareCell, prepareRow, removeAllRows, removeCell, removeCells, removeRow
 
Methods inherited from class com.google.gwt.user.client.ui.HTMLTable
addClickHandler, addTableListener, checkCellBounds, checkRowBounds, clear, clearCell, createCell, getBodyElement, getCellForEvent, getCellFormatter, getCellPadding, getCellSpacing, getColumnFormatter, getDOMCellCount, getDOMCellCount, getDOMRowCount, getDOMRowCount, getEventTargetCell, getHTML, getRowFormatter, getText, getWidget, insertCells, internalClearCell, isCellPresent, iterator, onEnsureDebugId, prepareColumn, remove, removeTableListener, setBorderWidth, setCellFormatter, setCellPadding, setCellSpacing, setColumnFormatter, 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
addDomHandler, addHandler, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setLayoutData, sinkEvents
 
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, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, 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.event.shared.HasHandlers
fireEvent
 

Constructor Detail

SuperTable

public SuperTable()
An empty constructor for this class. If you use this constructor, please use the setter methods for setting the table and column properties before adding any rows to the table.


SuperTable

public SuperTable(ColumnProperty[] columnsProperty)
A constructor for this class. The default value for the table properties is user if this constructor is used.

Parameters:
columnsProperty - column property object

SuperTable

public SuperTable(ColumnProperty[] columnsProperty,
                  SuperTableProperty properties)
A constructor for this class with the column and table property objects supplied as parameters.

Parameters:
columnsProperty - tableProperty for each column in the table.
tableProperty - table tableProperty.
Method Detail

addRow

public void addRow(Widget[] row)
Add a row to the table

Parameters:
row - widgets belonging to the row, each element in the array contains a column entry for the row.

addRow

public void addRow(Widget[] row,
                   boolean selected)
Add a row to the table and set it to selected.

Parameters:
row - widgets belonging to the row, each element in the array contains a column entry for the row.
selected - whether the row is selected (will only be set to selected if SuperTableProperty.rowSelectionEnabled() is set to true).

addTableListener

public void addTableListener(SuperTableListener listener)
Add a table listener. The listener can be used by the application to get notified of various events.

Parameters:
listener - the listener object.

addToUserToolbar

public void addToUserToolbar(Widget w)
Add an entry into the user tool bar. The user toolbar is added at the top of the table header. It is to the right of the table navigation (next, previous, first, etc.) toolbar. An application can add one or more widgets into this toolbar.

Parameters:
w - the widget to add.

addUserHeader

public void addUserHeader(Widget widget)
Adds a user header. The application may add zero or more application-specific header. The header is added in a new row immediately above the table header.

Parameters:
widget - the widget to add. Normally, a panel of some type is added.

clear

public void clear()
Specified by:
clear in interface HasWidgets
Overrides:
clear in class HTMLTable

deleteRow

public void deleteRow(int index)
Delete a row from the table.

Parameters:
index - the index starting with 0.

getColumnsProperty

public ColumnProperty[] getColumnsProperty()
Returns the column property object.

Returns:
Returns the columnsProperty.

getCommandList

public ListBox getCommandList()
Returns the list box containing the application-defined list action items. This list box is located inside the command toolbar. Applications can add their own items and listeners to the list.

Returns:
Returns the commandList.

getCurrentPageRecordCount

public int getCurrentPageRecordCount()
Returns the row count in a current page. If paging is not enabled, the record count is the number of rows. If paging is enabled, the size is determined by the rows per page table property.

Returns:
record count

getFirstRowIndex

public int getFirstRowIndex()
Returns the index of the first row in the current page. If paging is not enabled, the index is zero.

Returns:
the first row index

getRows

public Widget[][] getRows()
Returns all the rows entries (and columns)

Returns:
the rows

getRowSize

public int getRowSize()
Return the number of rows.

Returns:
the number of rows

getSelectedCell

public int[] getSelectedCell()
Returns the user-selected cell. The first element in the returned array contains the row index and the second element contains the column index.

Returns:
A null is returned if the user has not selected a row.

getSelectedRowIndex

public int getSelectedRowIndex()
Returns the selected row index. If multiple rows are selected, only the first one is returned.

Returns:
the row index starting with 0, -1 if no rows are selected.

getSelectedRowIndices

public int[] getSelectedRowIndices()
Returns the indicies of the selected rows.

Returns:
If no rows are selected, an empty array is returned.

getTableContent

public ArrayList<Widget[]> getTableContent()
Returns the content of the table in array list format.

Returns:
Returns the tableContent.

getTableProperty

public SuperTableProperty getTableProperty()
Returns the table property.

Returns:
Returns the SuperTableProperty object associated with this table.

getToolbarPanel

public ToolbarPanel getToolbarPanel()
Returns the toolbar panel object on the first row. Applications can add their own toolbars into this panel. However, applications can also use the user tool bar which is part of this panel.

Returns:
Returns the toolbarPanel.

getUserBar

public Toolbar getUserBar()
Returns the user tool bar.

Returns:
Returns the userBar.

isCellSelected

public boolean isCellSelected(int row,
                              int col)
Is the given cell selected?

Parameters:
row - row index
col - column index
Returns:
true if the cell is selected.

isRowInPage

public boolean isRowInPage(int row)
Check if a row is in the current page. If the table property has the paging set, the table content is displayed one page at a time. Therefore a given row may not be in the currently-displayed page.

Parameters:
row - the row number starting with 0.
Returns:
true if the row is in the current page.

isRowSelected

public boolean isRowSelected(int row)
Returns if the row is selected.

Parameters:
row - row number starting with 0.
Returns:
true if the row is selected, false otherwise.

removeTableListener

public void removeTableListener(SuperTableListener listener)
Remove a table listener.

Parameters:
listener - the listener object to remove.

setCell

public void setCell(Widget w,
                    int row,
                    int col)
Replaces the widget in a given cell with a new one.

Parameters:
w - the new widget object.
row - row index
col - column index

setCellSelected

public void setCellSelected(int row,
                            int col,
                            boolean selected)
Select/deselect a cell. This method is not yet implemented.

Parameters:
row -
col -
selected -

setColumnsProperty

public void setColumnsProperty(ColumnProperty[] columnsProperty)
Sets the column property. This method must be called prior to adding the first row.

Parameters:
columnsProperty - The columnsProperty to set.

setRow

public void setRow(Widget[] row,
                   int index)
Replaces a row with a new row. All row and cell attributes remain the same.

Parameters:
row - the new row
index - the row index.

setRow

public void setRow(Widget[] row,
                   int index,
                   Boolean selected)
Replaces a row with a new row.

Parameters:
row - the new row
index - the row index
selected - if set to null, the row attribute is not modified; if not null, the row is set selected or not according to the value.

setRowSelected

public void setRowSelected(int row,
                           boolean selected)
Select or deselect a row.

Parameters:
row - row index
selected - true or false.

setTableProperty

public void setTableProperty(SuperTableProperty tableProperty)
Sets the table property. This method must be called prior to adding the first row and after calling the setColumnsProperty() method for it to work properly.

Parameters:
tableProperty - The tableProperty to set.

redraw

public void redraw()
In some cases, the table does not diplay the toolbar panel properly for very complex reasons. This method is provided to manually redraw the panel. (This is a temporary solution until a completely transparent solution is found.)



Copyright © 2010 Cafesip.org. All Rights Reserved.