ListDataProvider (GWT Javadoc)

Overview | Package | Class | Use | Deprecated | Help
| GWT 2.7.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.view.client
Class ListDataProvider<T>

    java.lang.Object
      com.google.gwt.view.client.AbstractDataProvider<T>
          com.google.gwt.view.client.ListDataProvider<T>

Type Parameters:
  `T` - the data type of the list

All Implemented Interfaces:
  ProvidesKey<T>

    public class ListDataProvider<T>

extends AbstractDataProvider<T>

A concrete subclass of `AbstractDataProvider` that is backed by an in-memory list.

Modifications (inserts, removes, sets, etc.) to the list returned by `getList()` will be reflected in the model. However, mutations to the items contained within the list will NOT be reflected in the model. You must call `List.set(int, Object)` to update the item within the list and push the change to the display, or call `refresh()` to push all rows to the displays. `List.set(int, Object)` performs better because it allows the data provider to push only those rows which have changed, and usually allows the display to re-render only a subset of the rows.

### Example

>     public class ListDataProviderExample implements EntryPoint {

>       public void onModuleLoad() {
>         // Create a CellList.
>         CellList<String> cellList = new CellList<String>(new TextCell());

>         // Create a list data provider.
>         final ListDataProvider<String> dataProvider = new ListDataProvider<String>();

>         // Add the cellList to the dataProvider.
>         dataProvider.addDataDisplay(cellList);

>         // Create a form to add values to the data provider.
>         final TextBox valueBox = new TextBox();
>         valueBox.setText("Enter new value");
>         Button addButton = new Button("Add value", new ClickHandler() {
>           public void onClick(ClickEvent event) {
>             // Get the value from the text box.
>             String newValue = valueBox.getText();

>             // Get the underlying list from data dataProvider.
>             List<String> list = dataProvider.getList();

>             // Add the value to the list. The dataProvider will update the cellList.
>             list.add(newValue);
>           }
>         });

>         // Add the widgets to the root panel.
>         VerticalPanel vPanel = new VerticalPanel();
>         vPanel.add(valueBox);
>         vPanel.add(addButton);
>         vPanel.add(cellList);
>         RootPanel.get().add(vPanel);
>       }
>     }

Constructor Summary
`ListDataProvider()` Creates an empty model.
`ListDataProvider(java.util.List<T> listToWrap)` Creates a list model that wraps the given list.
`ListDataProvider(java.util.List<T> listToWrap, ProvidesKey<T> keyProvider)` Creates a list model that wraps the given list.
`ListDataProvider(ProvidesKey<T> keyProvider)` Creates an empty list model that wraps the given collection.

Method Summary
`void` | `flush()` Flush pending list changes to the displays.
`java.util.List<T>` | `getList()` Get the list that backs this model.
`protected void` | `onRangeChanged(HasData<T> display)` Called when a display changes its range of interest.
`void` | `refresh()` Refresh all of the displays listening to this adapter.
`void` | `setList(java.util.List<T> listToWrap)` Replace this model's list with the specified list.

Methods inherited from class com.google.gwt.view.client.AbstractDataProvider
`addDataDisplay, getDataDisplays, getKey, getKeyProvider, getRanges, removeDataDisplay, updateRowCount, updateRowData, updateRowData`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ListDataProvider

    public ListDataProvider()

  Creates an empty model.

### ListDataProvider

    public ListDataProvider(java.util.List<T> listToWrap)

  Creates a list model that wraps the given list.

  The wrapped list should no longer be modified as the data provider cannot detect changes to the wrapped list. Instead, call `getList()` to retrieve a wrapper that can be modified and will correctly forward changes to displays.

  Parameters:
    `listToWrap` - the List to be wrapped

### ListDataProvider

    public ListDataProvider(ProvidesKey<T> keyProvider)

  Creates an empty list model that wraps the given collection.

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

### ListDataProvider

    public ListDataProvider(java.util.List<T> listToWrap,
                            ProvidesKey<T> keyProvider)

  Creates a list model that wraps the given list.

  The wrapped list should no longer be modified as the data provider cannot detect changes to the wrapped list. Instead, call `getList()` to retrieve a wrapper that can be modified and will correctly forward changes to displays.

  Parameters:
    `listToWrap` - the List to be wrapped
    `keyProvider` - an instance of ProvidesKey, or null if the record object should act as its own key

Method Detail

### flush

    public void flush()

  Flush pending list changes to the displays. By default, displays are informed of modifications to the underlying list at the end of the current event loop, which makes it possible to perform multiple operations synchronously without repeatedly refreshing the displays. This method can be called to flush the changes immediately instead of waiting until the end of the current event loop.

### getList

    public java.util.List<T> getList()

  Get the list that backs this model. Changes to the list will be reflected in the model.

  NOTE: Mutations to the items contained within the list will NOT be reflected in the model. You must call `List.set(int, Object)` to update the item within the list and push the change to the display, or call `refresh()` to push all rows to the displays. `List.set(int, Object)` performs better because it allows the data provider to push only those rows which have changed, and usually allows the display to re-render only a subset of the rows.

  Returns:
    the list
  See Also:
    `setList(List)`

### refresh

    public void refresh()

  Refresh all of the displays listening to this adapter.

  Use `refresh()` to push mutations to the underlying data items contained within the list. The data provider cannot detect changes to data objects within the list, so you must call this method if you modify items.

  This is a shortcut for calling `List.set(int, Object)` on every item that you modify, but note that calling `List.set(int, Object)` performs better because the data provider knows which rows were modified and can push only the modified rows the displays.

### setList

    public void setList(java.util.List<T> listToWrap)

  Replace this model's list with the specified list.

  The wrapped list should no longer be modified as the data provider cannot detect changes to the wrapped list. Instead, call `getList()` to retrieve a wrapper that can be modified and will correctly forward changes to displays.

  Parameters:
    `listToWrap` - the model's new list
  See Also:
    `getList()`

### onRangeChanged

    protected void onRangeChanged(HasData<T> display)

  Description copied from class: `AbstractDataProvider`
  Called when a display changes its range of interest.

  Specified by:
    `onRangeChanged` in class `AbstractDataProvider<T>`
  Parameters:
    `display` - the display whose range has changed

Overview | Package | Class | Use | Deprecated | Help
| GWT 2.7.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD