|
GWT 2.1.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.cellview.client.AbstractHasData<T>
com.google.gwt.user.cellview.client.CellList<T>
T - the data type of list itemspublic class CellList<T>
A single column list of cells.
public class CellListExample implements EntryPoint {
/**
* The list of data to display.
*/
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
public void onModuleLoad() {
// Create a cell to render each value.
TextCell textCell = new TextCell();
// Create a CellList that uses the cell.
CellList<String> cellList = new CellList<String>(textCell);
cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
// Add a selection model to handle user selection.
final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
cellList.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
String selected = selectionModel.getSelectedObject();
if (selected != null) {
Window.alert("You selected: " + selected);
}
}
});
// 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.
cellList.setRowCount(DAYS.size(), true);
// Push the data into the widget.
cellList.setRowData(0, DAYS);
// Add it to the root panel.
RootPanel.get().add(cellList);
}
}
public class CellListValueUpdaterExample implements EntryPoint {
/**
* The list of data to display.
*/
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
public void onModuleLoad() {
// Create a cell that will interact with a value updater.
TextInputCell inputCell = new TextInputCell();
// Create a CellList that uses the cell.
CellList<String> cellList = new CellList<String>(inputCell);
// Create a value updater that will be called when the value in a cell
// changes.
ValueUpdater<String> valueUpdater = new ValueUpdater<String>() {
public void update(String newValue) {
Window.alert("You typed: " + newValue);
}
};
// Add the value updater to the cellList.
cellList.setValueUpdater(valueUpdater);
// 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.
cellList.setRowCount(DAYS.size(), true);
// Push the data into the widget.
cellList.setRowData(0, DAYS);
// Add it to the root panel.
RootPanel.get().add(cellList);
}
}
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(Contact value, Object key, 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 |
CellList.Resources
A ClientBundle that provides images for this widget. |
static interface |
CellList.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 | |
|---|---|
CellList(Cell<T> cell)
Construct a new CellList. |
|
CellList(Cell<T> cell,
CellList.Resources resources)
Construct a new CellList with the specified CellList.Resources. |
|
CellList(Cell<T> cell,
CellList.Resources resources,
ProvidesKey<T> keyProvider)
Construct a new CellList with the specified CellList.Resources
and key provider. |
|
CellList(Cell<T> cell,
ProvidesKey<T> keyProvider)
Construct a new CellList with the specified key provider. |
|
| Method Summary | |
|---|---|
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 indexOnPage)
Called when a user action triggers selection. |
protected void |
fireEventToCell(Event event,
Element parent,
T value)
Fire an event to the cell. |
protected Cell<T> |
getCell()
Return the cell used to render each item. |
protected Element |
getCellParent(Element item)
Get the parent element that wraps the cell from the list item. |
protected Element |
getChildContainer()
Return the element that holds the rendered cells. |
SafeHtml |
getEmptyListMessage()
Get the message that is displayed when there is no data. |
protected Element |
getKeyboardSelectedElement()
Get the element that has keyboard selection. |
Element |
getRowElement(int indexOnPage)
Get the Element for the specified index. |
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 |
renderRowValues(SafeHtmlBuilder sb,
java.util.List<T> values,
int start,
SelectionModel<? super T> selectionModel)
Render all row values into the specified SafeHtmlBuilder. |
protected boolean |
resetFocusOnCell()
Reset focus on the currently focused cell. |
void |
setEmptyListMessage(SafeHtml html)
Set the message to display when there is no data. |
protected void |
setKeyboardSelected(int index,
boolean selected,
boolean stealFocus)
Update an element to reflect its keyboard selected state. |
protected void |
setSelected(Element elem,
boolean selected)
Update an element to reflect its selected state. |
void |
setValueUpdater(ValueUpdater<T> valueUpdater)
Set the value updater to use when cells modify items. |
| Methods inherited from class com.google.gwt.user.client.ui.Widget |
|---|
addAttachHandler, 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, 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 |
|---|
public CellList(Cell<T> cell)
CellList.
cell - the cell used to render each item
public CellList(Cell<T> cell,
CellList.Resources resources)
CellList with the specified CellList.Resources.
cell - the cell used to render each itemresources - the resources used for this widget
public CellList(Cell<T> cell,
ProvidesKey<T> keyProvider)
CellList with the specified key provider.
cell - the cell used to render each itemkeyProvider - an instance of ProvidesKey
public CellList(Cell<T> cell,
CellList.Resources resources,
ProvidesKey<T> keyProvider)
CellList with the specified CellList.Resources
and key provider.
cell - the cell used to render each itemresources - the resources used for this widgetkeyProvider - an instance of ProvidesKey| Method Detail |
|---|
public SafeHtml getEmptyListMessage()
setEmptyListMessage(SafeHtml)public Element getRowElement(int indexOnPage)
Element for the specified index. If the element has not
been created, null is returned.
indexOnPage - the index on the page
java.lang.IndexOutOfBoundsException - if the index is outside of the current
pagepublic void setEmptyListMessage(SafeHtml html)
html - the message to display when there are no resultsgetEmptyListMessage()public void setValueUpdater(ValueUpdater<T> valueUpdater)
valueUpdater - the ValueUpdaterprotected boolean dependsOnSelection()
AbstractHasData
dependsOnSelection in class AbstractHasData<T>
protected void doSelection(Event event,
T value,
int indexOnPage)
event - the event that triggered selectionvalue - the value that was selectedindexOnPage - the index of the value on the page
protected void fireEventToCell(Event event,
Element parent,
T value)
event - the event that was firedparent - the parent of the cellvalue - the value of the cellprotected Cell<T> getCell()
protected Element getCellParent(Element item)
item - the row element that wraps the list item
protected Element getChildContainer()
AbstractHasData
getChildContainer in class AbstractHasData<T>Elementprotected Element getKeyboardSelectedElement()
AbstractHasData
getKeyboardSelectedElement in class AbstractHasData<T>protected boolean isKeyboardNavigationSuppressed()
AbstractHasData
isKeyboardNavigationSuppressed in class AbstractHasData<T>protected void onBlur()
AbstractHasData
onBlur in class AbstractHasData<T>protected void onBrowserEvent2(Event event)
AbstractHasDataAbstractHasData.onBrowserEvent(Event) completes.
onBrowserEvent2 in class AbstractHasData<T>event - the event that was firedprotected void onFocus()
AbstractHasData
onFocus in class AbstractHasData<T>
protected void renderRowValues(SafeHtmlBuilder sb,
java.util.List<T> values,
int start,
SelectionModel<? super T> selectionModel)
AbstractHasDataSafeHtmlBuilder.
renderRowValues in class AbstractHasData<T>sb - the SafeHtmlBuilder to render intovalues - the row valuesstart - the start index of the valuesselectionModel - the SelectionModelprotected boolean resetFocusOnCell()
AbstractHasData
resetFocusOnCell in class AbstractHasData<T>
protected void setKeyboardSelected(int index,
boolean selected,
boolean stealFocus)
AbstractHasData
setKeyboardSelected in class AbstractHasData<T>index - the index of the elementselected - true if selected, false if notstealFocus - true if the row should steal focus, false if not
protected void setSelected(Element elem,
boolean selected)
AbstractHasData
setSelected in class AbstractHasData<T>elem - the element to updateselected - true if selected, false if not
|
GWT 2.1.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||