C
- the type that this Cell representspublic interface Cell<C>
Multiple cell widgets or Columns can share a single Cell instance, but there may be implications for certain stateful Cells. Generally, Cells are stateless flyweights that see the world as row values/keys. If a Column contains duplicate row values/keys, the Cell will not differentiate the value in one row versus another. Similarly, if you use a single Cell instance in multiple Columns, the Cells will not differentiate the values coming from one Column versus another.
However, some interactive Cells (EditTextCell
, CheckboxCell
,
TextInputCell
, etc...) have a stateful "pending" state, which is a
map of row values/keys to the end user entered pending value. For example, if
an end user types a new value in a TextInputCell
, the
TextInputCell
maps the "pending value" and associates it with the
original row value/key. The next time the Cell Widget renders that row
value/key, the Cell renders the pending value instead. This allows
applications to refresh the Cell Widget without clearing out all of the end
user's pending changes. In subclass of AbstractEditableCell
, the
pending state remains until either the original value is updated (a
successful commit), or until
AbstractEditableCell.clearViewData(Object)
is called (a failed
commit).
If you share an interactive Cell between two cell widgets (or Columns within the same CellTable), then when the end user updates the pending value in one widget, it will be reflected in the other widget when the other widget is redrawn. You should base your decision on whether or not to share Cell instances on this behavior.
Warning: The Cell interface may change in subtle but breaking ways as we
continuously seek to improve performance. You should always subclass AbstractCell
instead
of implementing Cell
directly.
Modifier and Type | Interface and Description |
---|---|
static class |
Cell.Context
Contains information about the context of the Cell.
|
Modifier and Type | Method and Description |
---|---|
boolean |
dependsOnSelection()
Check if this cell depends on the selection state.
|
Set<String> |
getConsumedEvents()
Get the set of events that this cell consumes (see
BrowserEvents for useful
constants). |
boolean |
handlesSelection()
Check if this cell handles selection.
|
boolean |
isEditing(Cell.Context context,
Element parent,
C value)
Returns true if the cell is currently editing the data identified by the
given element and key.
|
void |
onBrowserEvent(Cell.Context context,
Element parent,
C value,
NativeEvent event,
ValueUpdater<C> valueUpdater)
Handle a browser event that took place within the cell.
|
void |
render(Cell.Context context,
C value,
SafeHtmlBuilder sb)
Render a cell as HTML into a
SafeHtmlBuilder , suitable for passing
to Element.setInnerHTML(String) on a container element. |
boolean |
resetFocus(Cell.Context context,
Element parent,
C value)
Reset focus on the Cell.
|
void |
setValue(Cell.Context context,
Element parent,
C value)
This method may be used by cell containers to set the value on a single
cell directly, rather than using
Element.setInnerHTML(String) . |
boolean dependsOnSelection()
Set<String> getConsumedEvents()
BrowserEvents
for useful
constants). The container that uses this cell should only pass these events
to
onBrowserEvent(Context, Element, Object, NativeEvent, ValueUpdater)
when the event occurs.
The returned value should not be modified, and may be an unmodifiable set. Changes to the return value may not be reflected in the cell.
BrowserEvents
boolean handlesSelection()
boolean isEditing(Cell.Context context, Element parent, C value)
context
- the Cell.Context
of the cellparent
- the parent Elementvalue
- the value associated with the cellvoid onBrowserEvent(Cell.Context context, Element parent, C value, NativeEvent event, ValueUpdater<C> valueUpdater)
context
- the Cell.Context
of the cellparent
- the parent Elementvalue
- the value associated with the cellevent
- the native browser eventvalueUpdater
- a ValueUpdater
, or null if not specifiedvoid render(Cell.Context context, C value, SafeHtmlBuilder sb)
SafeHtmlBuilder
, suitable for passing
to Element.setInnerHTML(String)
on a container element.
Note: If your cell contains natively focusable elements, such as buttons or input elements, be sure to set the tabIndex to -1 so that they do not steal focus away from the containing widget.
context
- the Cell.Context
of the cellvalue
- the cell value to be renderedsb
- the SafeHtmlBuilder
to be written toboolean resetFocus(Cell.Context context, Element parent, C value)
context
- the Cell.Context
of the cellparent
- the parent Elementvalue
- the value associated with the cellvoid setValue(Cell.Context context, Element parent, C value)
Element.setInnerHTML(String)
. See
setValue(Context, Element, Object)
for a default
implementation that uses render(Context, Object, SafeHtmlBuilder)
.context
- the Cell.Context
of the cellparent
- the parent Elementvalue
- the value associated with the cellCopyright © 2018. All rights reserved.