GWT 2.3.0

com.google.gwt.user.cellview.client
Class CellTable<T>

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.cellview.client.AbstractHasData<T>
              extended by com.google.gwt.user.cellview.client.CellTable<T>
Type Parameters:
T - the data type of each row
All Implemented Interfaces:
HasAttachHandlers, HasHandlers, HasKeyboardPagingPolicy, HasKeyboardSelectionPolicy, EventListener, Focusable, IsWidget, HasCellPreviewHandlers<T>, HasData<T>, HasKeyProvider<T>, HasRows

public class CellTable<T>
extends AbstractHasData<T>

A tabular view that supports paging and columns.

Columns

The Column class defines the Cell used to render a column. Implement Column.getValue(Object) to retrieve the field value from the row object that will be rendered in the Cell.

Headers and Footers

A Header can be placed at the top (header) or bottom (footer) of the CellTable. You can specify a header as text using addColumn(Column, String), or you can create a custom Header that can change with the value of the cells, such as a column total. The Header will be rendered every time the row data changes or the table is redrawn. If you pass the same header instance (==) into adjacent columns, the header will span the columns.

Examples

Trivial example
public class CellTableExample implements EntryPoint {

  /**
   * A simple data type that represents a contact.
   */
  private static class Contact {
    private final String address;
    private final Date birthday;
    private final String name;

    public Contact(String name, Date birthday, String address) {
      this.name = name;
      this.birthday = birthday;
      this.address = address;
    }
  }

  /**
   * The list of data to display.
   */
  private static final List<Contact> CONTACTS = Arrays.asList(
      new Contact("John", new Date(80, 4, 12), "123 Fourth Avenue"),
      new Contact("Joe", new Date(85, 2, 22), "22 Lance Ln"),
      new Contact("George", new Date(46, 6, 6), "1600 Pennsylvania Avenue"));

  public void onModuleLoad() {
    // Create a CellTable.
    CellTable<Contact> table = new CellTable<Contact>();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text column to show the name.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
      @Override
      public String getValue(Contact object) {
        return object.name;
      }
    };
    table.addColumn(nameColumn, "Name");

    // Add a date column to show the birthday.
    DateCell dateCell = new DateCell();
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
      @Override
      public Date getValue(Contact object) {
        return object.birthday;
      }
    };
    table.addColumn(dateColumn, "Birthday");

    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
      @Override
      public String getValue(Contact object) {
        return object.address;
      }
    };
    table.addColumn(addressColumn, "Address");

    // Add a selection model to handle user selection.
    final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
      public void onSelectionChange(SelectionChangeEvent event) {
        Contact selected = selectionModel.getSelectedObject();
        if (selected != null) {
          Window.alert("You selected: " + selected.name);
        }
      }
    });

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    table.setRowCount(CONTACTS.size(), true);

    // Push the data into the widget.
    table.setRowData(0, CONTACTS);

    // Add it to the root panel.
    RootPanel.get().add(table);
  }
}
FieldUpdater example
public class CellTableFieldUpdaterExample implements EntryPoint {

  /**
   * A simple data type that represents a contact with a unique ID.
   */
  private static class Contact {
    private static int nextId = 0;

    private final int id;
    private final String address;
    private Date birthday;
    private String name;

    public Contact(String name, Date birthday, String address) {
      nextId++;
      this.id = nextId;
      this.name = name;
      this.birthday = birthday;
      this.address = address;
    }
  }

  /**
   * The list of data to display.
   */
  private static final List<Contact> CONTACTS = Arrays.asList(
      new Contact("John", new Date(80, 4, 12), "123 Fourth Avenue"),
      new Contact("Joe", new Date(85, 2, 22), "22 Lance Ln"),
      new Contact("George", new Date(46, 6, 6), "1600 Pennsylvania Avenue"));

  /**
   * The key provider that allows us to identify Contacts even if a field
   * changes. We identify contacts by their unique ID.
   */
  private static final ProvidesKey<Contact> KEY_PROVIDER = new ProvidesKey<CellTableFieldUpdaterExample.Contact>() {
    public Object getKey(Contact item) {
      return item.id;
    }
  };

  public void onModuleLoad() {
    // Create a CellTable with a key provider.
    final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text input column to edit the name.
    final TextInputCell nameCell = new TextInputCell();
    Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) {
      @Override
      public String getValue(Contact object) {
        return object.name;
      }
    };
    table.addColumn(nameColumn, "Name");

    // Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
      public void update(int index, Contact object, String value) {
        // Validate the data.
        if (value.length() < 3) {
          Window.alert("Names must be at least three characters long.");

          /*
           * Clear the view data. The view data contains the pending change and
           * allows the table to render with the pending value until the data is
           * committed. If the data is committed into the object, the view data
           * is automatically cleared out. If the data is not committed because
           * it is invalid, you must delete.
           */
          nameCell.clearViewData(KEY_PROVIDER.getKey(object));

          // Redraw the table.
          table.redraw();
          return;
        }

        // Inform the user of the change.
        Window.alert("You changed the name of " + object.name + " to " + value);

        // Push the changes into the Contact. At this point, you could send an
        // asynchronous request to the server to update the database.
        object.name = value;

        // Redraw the table with the new data.
        table.redraw();
      }
    });

    // Add a date column to show the birthday.
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(
        new DatePickerCell()) {
      @Override
      public Date getValue(Contact object) {
        return object.birthday;
      }
    };
    table.addColumn(dateColumn, "Birthday");

    // Add a field updater to be notified when the user enters a new birthday.
    dateColumn.setFieldUpdater(new FieldUpdater<Contact, Date>() {
      public void update(int index, Contact object, Date value) {
        Window.alert("You changed the birthday of "
            + object.name
            + " to "
            + DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).format(value));

        // Push the changes into the Contact.
        object.birthday = value;

        // Redraw the table with the new data.
        table.redraw();
      }
    });
    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
      @Override
      public String getValue(Contact object) {
        return object.address;
      }
    };
    table.addColumn(addressColumn, "Address");

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    table.setRowCount(CONTACTS.size(), true);

    // Push the data into the widget.
    table.setRowData(0, CONTACTS);

    // Add it to the root panel.
    RootPanel.get().add(table);
  }
}
Key provider example
public class KeyProviderExample implements EntryPoint {

  /**
   * A simple data type that represents a contact.
   */
  private static class Contact {
    private static int nextId = 0;

    private final int id;
    private String name;

    public Contact(String name) {
      nextId++;
      this.id = nextId;
      this.name = name;
    }
  }

  /**
   * A custom {@link Cell} used to render a {@link Contact}.
   */
  private static class ContactCell extends AbstractCell<Contact> {
    @Override
    public void render(Context context, Contact value, SafeHtmlBuilder sb) {
      if (value != null) {
        sb.appendEscaped(value.name);
      }
    }
  }

  /**
   * The list of data to display.
   */
  private static final List<Contact> CONTACTS = Arrays.asList(new Contact(
      "John"), new Contact("Joe"), new Contact("Michael"),
      new Contact("Sarah"), new Contact("George"));

  public void onModuleLoad() {
    /*
     * Define a key provider for a Contact. We use the unique ID as the key,
     * which allows to maintain selection even if the name changes.
     */
    ProvidesKey<Contact> keyProvider = new ProvidesKey<Contact>() {
      public Object getKey(Contact item) {
        // Always do a null check.
        return (item == null) ? null : item.id;
      }
    };

    // Create a CellList using the keyProvider.
    CellList<Contact> cellList = new CellList<Contact>(new ContactCell(),
        keyProvider);

    // Push data into the CellList.
    cellList.setRowCount(CONTACTS.size(), true);
    cellList.setRowData(0, CONTACTS);

    // Add a selection model using the same keyProvider.
    SelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>(
        keyProvider);
    cellList.setSelectionModel(selectionModel);

    /*
     * Select a contact. The selectionModel will select based on the ID because
     * we used a keyProvider.
     */
    Contact sarah = CONTACTS.get(3);
    selectionModel.setSelected(sarah, true);

    // Modify the name of the contact.
    sarah.name = "Sara";

    /*
     * Redraw the CellList. Sarah/Sara will still be selected because we
     * identify her by ID. If we did not use a keyProvider, Sara would not be
     * selected.
     */
    cellList.redraw();

    // Add the widgets to the root panel.
    RootPanel.get().add(cellList);
  }
}


Nested Class Summary
static interface CellTable.BasicResources
          Resources that match the GWT standard style theme.
static interface CellTable.Resources
          A ClientBundle that provides images for this widget.
static interface CellTable.Style
          Styles used by this widget.
 
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.cellview.client.HasKeyboardPagingPolicy
HasKeyboardPagingPolicy.KeyboardPagingPolicy
 
Nested classes/interfaces inherited from interface com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy
HasKeyboardSelectionPolicy.KeyboardSelectionPolicy
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
CellTable()
          Constructs a table with a default page size of 15.
CellTable(int pageSize)
          Constructs a table with the given page size.
CellTable(int pageSize, CellTable.Resources resources)
          Constructs a table with the given page size with the specified CellTable.BasicResources.
CellTable(int pageSize, CellTable.Resources resources, ProvidesKey<T> keyProvider)
          Constructs a table with the given page size, the specified CellTable.BasicResources, and the given key provider.
CellTable(int pageSize, CellTable.Resources resources, ProvidesKey<T> keyProvider, Widget loadingIndicator)
          Constructs a table with the specified page size, CellTable.BasicResources, key provider, and loading indicator.
CellTable(int pageSize, ProvidesKey<T> keyProvider)
          Constructs a table with the given page size and the given key provider.
CellTable(ProvidesKey<T> keyProvider)
          Constructs a table with a default page size of 15, and the given key provider.
 
Method Summary
 void addColumn(Column<T,?> col)
          Adds a column to the end of the table.
 void addColumn(Column<T,?> col, Header<?> header)
          Adds a column to the end of the table with an associated header.
 void addColumn(Column<T,?> col, Header<?> header, Header<?> footer)
          Adds a column to the end of the table with an associated header and footer.
 void addColumn(Column<T,?> col, SafeHtml headerHtml)
          Adds a column to the end of the table with an associated SafeHtml header.
 void addColumn(Column<T,?> col, SafeHtml headerHtml, SafeHtml footerHtml)
          Adds a column to the end of the table with an associated SafeHtml header and footer.
 void addColumn(Column<T,?> col, java.lang.String headerString)
          Adds a column to the end of the table with an associated String header.
 void addColumn(Column<T,?> col, java.lang.String headerString, java.lang.String footerString)
          Adds a column to the end of the table with an associated String header and footer.
 HandlerRegistration addColumnSortHandler(ColumnSortEvent.Handler handler)
          Add a handler to handle ColumnSortEvents.
 void addColumnStyleName(int index, java.lang.String styleName)
          Add a style name to the TableColElement at the specified index, creating it if necessary.
 void clearColumnWidth(Column<T,?> column)
          Clear the width of the specified Column.
protected  Element convertToElements(SafeHtml html)
          Convert the specified HTML into DOM elements and return the parent of the DOM elements.
protected  boolean dependsOnSelection()
          Check whether or not the cells in the view depend on the selection state.
protected  void doSelection(Event event, T value, int row, int column)
          Deprecated. use AbstractHasData.addCellPreviewHandler(com.google.gwt.view.client.CellPreviewEvent.Handler) instead
 int getBodyHeight()
          Return the height of the table body.
protected  Element getChildContainer()
          Return the element that holds the rendered cells.
 Column<T,?> getColumn(int col)
          Get the column at the specified index.
 int getColumnCount()
          Get the number of columns in the table.
 int getColumnIndex(Column<T,?> column)
          Get the index of the specified column.
 ColumnSortList getColumnSortList()
          Get the ColumnSortList that specifies which columns are sorted.
 Widget getEmptyTableWidget()
          Get the widget displayed when the table has no rows.
 int getHeaderHeight()
          Return the height of the table header.
protected  Element getKeyboardSelectedElement()
          Get the element that has keyboard selection.
 Widget getLoadingIndicator()
          Get the widget displayed when the data is loading.
 TableRowElement getRowElement(int row)
          Get the TableRowElement for the specified row.
 void insertColumn(int beforeIndex, Column<T,?> col)
          Inserts a column into the table at the specified index.
 void insertColumn(int beforeIndex, Column<T,?> col, Header<?> header)
          Inserts a column into the table at the specified index with an associated header.
 void insertColumn(int beforeIndex, Column<T,?> col, Header<?> header, Header<?> footer)
          Inserts a column into the table at the specified index with an associated header and footer.
 void insertColumn(int beforeIndex, Column<T,?> col, SafeHtml headerHtml)
          Inserts a column into the table at the specified index with an associated SafeHtml header.
 void insertColumn(int beforeIndex, Column<T,?> col, SafeHtml headerHtml, SafeHtml footerHtml)
          Inserts a column into the table at the specified index with an associated SafeHtml header and footer.
 void insertColumn(int beforeIndex, Column<T,?> col, java.lang.String headerString)
          Inserts a column into the table at the specified index with an associated String header.
 void insertColumn(int beforeIndex, Column<T,?> col, java.lang.String headerString, java.lang.String footerString)
          Inserts a column into the table at the specified index with an associated String header and footer.
protected  boolean isKeyboardNavigationSuppressed()
          Check if keyboard navigation is being suppressed, such as when the user is editing a cell.
protected  void onBlur()
          Called when the widget is blurred.
protected  void onBrowserEvent2(Event event)
          Called after AbstractHasData.onBrowserEvent(Event) completes.
protected  void onFocus()
          Called when the widget is focused.
protected  void onLoadingStateChanged(LoadingStateChangeEvent.LoadingState state)
          Called when the loading state changes.
 void redraw()
          Redraw the widget using the existing data.
 void redrawFooters()
          Redraw the table's footers.
 void redrawHeaders()
          Redraw the table's headers.
 void removeColumn(Column<T,?> col)
          Remove a column.
 void removeColumn(int index)
          Remove a column.
 void removeColumnStyleName(int index, java.lang.String styleName)
          Remove a style from the TableColElement at the specified index.
protected  void renderRowValues(SafeHtmlBuilder sb, java.util.List<T> values, int start, SelectionModel<? super T> selectionModel)
          Render all row values into the specified SafeHtmlBuilder.
protected  void replaceAllChildren(java.util.List<T> values, SafeHtml html)
          Replace all children with the specified html.
protected  boolean resetFocusOnCell()
          Reset focus on the currently focused cell.
 void setColumnWidth(Column<T,?> column, double width, Style.Unit unit)
          Set the width of a Column.
 void setColumnWidth(Column<T,?> column, java.lang.String width)
          Set the width of a Column.
 void setEmptyTableWidget(Widget widget)
          Set the widget to display when the table has no rows.
protected  void setKeyboardSelected(int index, boolean selected, boolean stealFocus)
          Update an element to reflect its keyboard selected state.
 void setLoadingIndicator(Widget widget)
          Set the widget to display when the data is loading.
 void setRowStyles(RowStyles<T> rowStyles)
          Sets the object used to determine how a row is styled; the change will take effect the next time that the table is rendered.
protected  void setSelected(Element elem, boolean selected)
          Deprecated. this method is never called by AbstractHasData, render the selected styles in renderRowValues(SafeHtmlBuilder, List, int, SelectionModel)
 void setTableLayoutFixed(boolean isFixed)
           Enable or disable fixed table layout.
 void setWidth(java.lang.String width, boolean isFixedLayout)
          Set the width of the width and specify whether or not it should use fixed table layout.
 
Methods inherited from class com.google.gwt.user.cellview.client.AbstractHasData
addCellPreviewHandler, addLoadingStateChangeHandler, addRangeChangeHandler, addRowCountChangeHandler, cellConsumesEventType, checkRowBounds, getAccessKey, getDisplayedItem, getDisplayedItems, getKeyboardPagingPolicy, getKeyboardSelectedRow, getKeyboardSelectionPolicy, getKeyProvider, getPageSize, getPageStart, getRowContainer, getRowCount, getSelectionModel, getTabIndex, getValueKey, getVisibleItem, getVisibleItemCount, getVisibleItems, getVisibleRange, isRowCountExact, isRowWithinBounds, onBrowserEvent, onUnload, onUpdateSelection, replaceChildren, setAccessKey, setFocus, setFocusable, setKeyboardPagingPolicy, setKeyboardSelectionPolicy, setPageSize, setPageStart, setRowCount, setRowCount, setRowData, setRowData, setSelectionModel, setSelectionModel, setTabIndex, setVisibleRange, setVisibleRange, setVisibleRangeAndClearData
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onDetach, onLoad, 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, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, 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

CellTable

public CellTable()
Constructs a table with a default page size of 15.


CellTable

public CellTable(int pageSize)
Constructs a table with the given page size.

Parameters:
pageSize - the page size

CellTable

public CellTable(ProvidesKey<T> keyProvider)
Constructs a table with a default page size of 15, and the given key provider.

Parameters:
keyProvider - an instance of ProvidesKey, or null if the record object should act as its own key

CellTable

public CellTable(int pageSize,
                 CellTable.Resources resources)
Constructs a table with the given page size with the specified CellTable.BasicResources.

Parameters:
pageSize - the page size
resources - the resources to use for this widget

CellTable

public CellTable(int pageSize,
                 ProvidesKey<T> keyProvider)
Constructs a table with the given page size and the given key provider.

Parameters:
pageSize - the page size
keyProvider - an instance of ProvidesKey, or null if the record object should act as its own key

CellTable

public CellTable(int pageSize,
                 CellTable.Resources resources,
                 ProvidesKey<T> keyProvider)
Constructs a table with the given page size, the specified CellTable.BasicResources, and the given key provider.

Parameters:
pageSize - the page size
resources - the resources to use for this widget
keyProvider - an instance of ProvidesKey, or null if the record object should act as its own key

CellTable

public CellTable(int pageSize,
                 CellTable.Resources resources,
                 ProvidesKey<T> keyProvider,
                 Widget loadingIndicator)
Constructs a table with the specified page size, CellTable.BasicResources, key provider, and loading indicator.

Parameters:
pageSize - the page size
resources - the resources to use for this widget
keyProvider - an instance of ProvidesKey, or null if the record object should act as its own key
loadingIndicator - the widget to use as a loading indicator, or null to disable
Method Detail

addColumn

public void addColumn(Column<T,?> col)
Adds a column to the end of the table.

Parameters:
col - the column to be added

addColumn

public void addColumn(Column<T,?> col,
                      Header<?> header)
Adds a column to the end of the table with an associated header.

Parameters:
col - the column to be added
header - the associated Header

addColumn

public void addColumn(Column<T,?> col,
                      Header<?> header,
                      Header<?> footer)
Adds a column to the end of the table with an associated header and footer.

Parameters:
col - the column to be added
header - the associated Header
footer - the associated footer (as a Header object)

addColumn

public void addColumn(Column<T,?> col,
                      java.lang.String headerString)
Adds a column to the end of the table with an associated String header.

Parameters:
col - the column to be added
headerString - the associated header text, as a String

addColumn

public void addColumn(Column<T,?> col,
                      SafeHtml headerHtml)
Adds a column to the end of the table with an associated SafeHtml header.

Parameters:
col - the column to be added
headerHtml - the associated header text, as safe HTML

addColumn

public void addColumn(Column<T,?> col,
                      java.lang.String headerString,
                      java.lang.String footerString)
Adds a column to the end of the table with an associated String header and footer.

Parameters:
col - the column to be added
headerString - the associated header text, as a String
footerString - the associated footer text, as a String

addColumn

public void addColumn(Column<T,?> col,
                      SafeHtml headerHtml,
                      SafeHtml footerHtml)
Adds a column to the end of the table with an associated SafeHtml header and footer.

Parameters:
col - the column to be added
headerHtml - the associated header text, as safe HTML
footerHtml - the associated footer text, as safe HTML

addColumnSortHandler

public HandlerRegistration addColumnSortHandler(ColumnSortEvent.Handler handler)
Add a handler to handle ColumnSortEvents.

Parameters:
handler - the ColumnSortEvent.Handler to add
Returns:
a HandlerRegistration to remove the handler

addColumnStyleName

public void addColumnStyleName(int index,
                               java.lang.String styleName)
Add a style name to the TableColElement at the specified index, creating it if necessary.

Parameters:
index - the column index
styleName - the style name to add

clearColumnWidth

public void clearColumnWidth(Column<T,?> column)
Clear the width of the specified Column.

Parameters:
column - the column

getBodyHeight

public int getBodyHeight()
Return the height of the table body.

Returns:
an int representing the body height

getColumn

public Column<T,?> getColumn(int col)
Get the column at the specified index.

Parameters:
col - the index of the column to retrieve
Returns:
the Column at the index

getColumnCount

public int getColumnCount()
Get the number of columns in the table.

Returns:
the column count

getColumnIndex

public int getColumnIndex(Column<T,?> column)
Get the index of the specified column.

Parameters:
column - the column to search for
Returns:
the index of the column, or -1 if not found

getColumnSortList

public ColumnSortList getColumnSortList()
Get the ColumnSortList that specifies which columns are sorted. Modifications to the ColumnSortList will be reflected in the table header.

Returns:
the ColumnSortList

getEmptyTableWidget

public Widget getEmptyTableWidget()
Get the widget displayed when the table has no rows.

Returns:
the empty table widget

getHeaderHeight

public int getHeaderHeight()
Return the height of the table header.

Returns:
an int representing the header height

getLoadingIndicator

public Widget getLoadingIndicator()
Get the widget displayed when the data is loading.

Returns:
the loading indicator

getRowElement

public TableRowElement getRowElement(int row)
Get the TableRowElement for the specified row. If the row element has not been created, null is returned.

Parameters:
row - the row index
Returns:
the row element, or null if it doesn't exists
Throws:
java.lang.IndexOutOfBoundsException - if the row index is outside of the current page

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col)
Inserts a column into the table at the specified index.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col,
                         Header<?> header)
Inserts a column into the table at the specified index with an associated header.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added
header - the associated Header

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col,
                         Header<?> header,
                         Header<?> footer)
Inserts a column into the table at the specified index with an associated header and footer.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added
header - the associated Header
footer - the associated footer (as a Header object)
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col,
                         java.lang.String headerString)
Inserts a column into the table at the specified index with an associated String header.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added
headerString - the associated header text, as a String

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col,
                         SafeHtml headerHtml)
Inserts a column into the table at the specified index with an associated SafeHtml header.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added
headerHtml - the associated header text, as safe HTML

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col,
                         java.lang.String headerString,
                         java.lang.String footerString)
Inserts a column into the table at the specified index with an associated String header and footer.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added
headerString - the associated header text, as a String
footerString - the associated footer text, as a String

insertColumn

public void insertColumn(int beforeIndex,
                         Column<T,?> col,
                         SafeHtml headerHtml,
                         SafeHtml footerHtml)
Inserts a column into the table at the specified index with an associated SafeHtml header and footer.

Parameters:
beforeIndex - the index to insert the column
col - the column to be added
headerHtml - the associated header text, as safe HTML
footerHtml - the associated footer text, as safe HTML

redraw

public void redraw()
Description copied from class: AbstractHasData
Redraw the widget using the existing data.

Overrides:
redraw in class AbstractHasData<T>

redrawFooters

public void redrawFooters()
Redraw the table's footers.


redrawHeaders

public void redrawHeaders()
Redraw the table's headers.


removeColumn

public void removeColumn(Column<T,?> col)
Remove a column.

Parameters:
col - the column to remove

removeColumn

public void removeColumn(int index)
Remove a column.

Parameters:
index - the column index

removeColumnStyleName

public void removeColumnStyleName(int index,
                                  java.lang.String styleName)
Remove a style from the TableColElement at the specified index.

Parameters:
index - the column index
styleName - the style name to remove

setColumnWidth

public void setColumnWidth(Column<T,?> column,
                           java.lang.String width)
Set the width of a Column. The layout behavior depends on whether or not the table is using fixed layout.

Parameters:
column - the column
width - the width of the column
See Also:
setTableLayoutFixed(boolean)

setColumnWidth

public void setColumnWidth(Column<T,?> column,
                           double width,
                           Style.Unit unit)
Set the width of a Column. The layout behavior depends on whether or not the table is using fixed layout.

Parameters:
column - the column
width - the width of the column
unit - the Style.Unit of measurement
See Also:
setTableLayoutFixed(boolean)

setEmptyTableWidget

public void setEmptyTableWidget(Widget widget)
Set the widget to display when the table has no rows.

Parameters:
widget - the empty table widget, or null to disable

setLoadingIndicator

public void setLoadingIndicator(Widget widget)
Set the widget to display when the data is loading.

Parameters:
widget - the loading indicator, or null to disable

setRowStyles

public void setRowStyles(RowStyles<T> rowStyles)
Sets the object used to determine how a row is styled; the change will take effect the next time that the table is rendered.

Parameters:
rowStyles - a RowStyles object

setTableLayoutFixed

public void setTableLayoutFixed(boolean isFixed)

Enable or disable fixed table layout.

Fixed Table Layout

When using the fixed table layout, cell contents are truncated as needed, which allows you to set the exact width of columns and the table. The default column width is 0 (invisible). In order to see all columns, you must set the width of the table (recommended 100%), or set the width of every column in the table. The following conditions are true for fixed layout tables:

Parameters:
isFixed - true to use fixed table layout, false not to
See Also:
W3C HTML Specification

setWidth

public final void setWidth(java.lang.String width,
                           boolean isFixedLayout)
Set the width of the width and specify whether or not it should use fixed table layout. See setTableLayoutFixed(boolean) for more information about fixed layout tables.

Parameters:
width - the width of the table
isFixedLayout - true to use fixed width layout, false not to
See Also:
setTableLayoutFixed(boolean), W3C HTML Specification

convertToElements

protected Element convertToElements(SafeHtml html)
Description copied from class: AbstractHasData
Convert the specified HTML into DOM elements and return the parent of the DOM elements.

Overrides:
convertToElements in class AbstractHasData<T>
Parameters:
html - the HTML to convert
Returns:
the parent element

dependsOnSelection

protected boolean dependsOnSelection()
Description copied from class: AbstractHasData
Check whether or not the cells in the view depend on the selection state.

Specified by:
dependsOnSelection in class AbstractHasData<T>
Returns:
true if cells depend on selection, false if not

doSelection

@Deprecated
protected void doSelection(Event event,
                                      T value,
                                      int row,
                                      int column)
Deprecated. use AbstractHasData.addCellPreviewHandler(com.google.gwt.view.client.CellPreviewEvent.Handler) instead

Called when a user action triggers selection.

Parameters:
event - the event that triggered selection
value - the value that was selected
row - the row index of the value on the page
column - the column index where the event occurred

getChildContainer

protected Element getChildContainer()
Description copied from class: AbstractHasData
Return the element that holds the rendered cells.

Specified by:
getChildContainer in class AbstractHasData<T>
Returns:
the container Element

getKeyboardSelectedElement

protected Element getKeyboardSelectedElement()
Description copied from class: AbstractHasData
Get the element that has keyboard selection.

Specified by:
getKeyboardSelectedElement in class AbstractHasData<T>
Returns:
the keyboard selected element

isKeyboardNavigationSuppressed

protected boolean isKeyboardNavigationSuppressed()
Description copied from class: AbstractHasData
Check if keyboard navigation is being suppressed, such as when the user is editing a cell.

Specified by:
isKeyboardNavigationSuppressed in class AbstractHasData<T>
Returns:
true if suppressed, false if not

onBlur

protected void onBlur()
Description copied from class: AbstractHasData
Called when the widget is blurred.

Overrides:
onBlur in class AbstractHasData<T>

onBrowserEvent2

protected void onBrowserEvent2(Event event)
Description copied from class: AbstractHasData
Called after AbstractHasData.onBrowserEvent(Event) completes.

Overrides:
onBrowserEvent2 in class AbstractHasData<T>
Parameters:
event - the event that was fired

onFocus

protected void onFocus()
Description copied from class: AbstractHasData
Called when the widget is focused.

Overrides:
onFocus in class AbstractHasData<T>

onLoadingStateChanged

protected void onLoadingStateChanged(LoadingStateChangeEvent.LoadingState state)
Called when the loading state changes.

Overrides:
onLoadingStateChanged in class AbstractHasData<T>
Parameters:
state - the new loading state

renderRowValues

protected void renderRowValues(SafeHtmlBuilder sb,
                               java.util.List<T> values,
                               int start,
                               SelectionModel<? super T> selectionModel)
Description copied from class: AbstractHasData
Render all row values into the specified SafeHtmlBuilder.

Specified by:
renderRowValues in class AbstractHasData<T>
Parameters:
sb - the SafeHtmlBuilder to render into
values - the row values
start - the absolute start index of the values
selectionModel - the SelectionModel

replaceAllChildren

protected void replaceAllChildren(java.util.List<T> values,
                                  SafeHtml html)
Description copied from class: AbstractHasData
Replace all children with the specified html.

Overrides:
replaceAllChildren in class AbstractHasData<T>
Parameters:
values - the values of the new children
html - the html to render in the child

resetFocusOnCell

protected boolean resetFocusOnCell()
Description copied from class: AbstractHasData
Reset focus on the currently focused cell.

Specified by:
resetFocusOnCell in class AbstractHasData<T>
Returns:
true if focus is taken, false if not

setKeyboardSelected

protected void setKeyboardSelected(int index,
                                   boolean selected,
                                   boolean stealFocus)
Description copied from class: AbstractHasData
Update an element to reflect its keyboard selected state.

Specified by:
setKeyboardSelected in class AbstractHasData<T>
Parameters:
index - the index of the element
selected - true if selected, false if not
stealFocus - true if the row should steal focus, false if not

setSelected

@Deprecated
protected void setSelected(Element elem,
                                      boolean selected)
Deprecated. this method is never called by AbstractHasData, render the selected styles in renderRowValues(SafeHtmlBuilder, List, int, SelectionModel)

Description copied from class: AbstractHasData
Update an element to reflect its selected state.

Overrides:
setSelected in class AbstractHasData<T>
Parameters:
elem - the element to update
selected - true if selected, false if not

GWT 2.3.0