T
- the data type of items in the listclass HasDataPresenter<T> extends java.lang.Object implements HasData<T>, HasKeyProvider<T>, HasKeyboardPagingPolicy
Presenter implementation of HasData
that presents data for various
cell based widgets. This class contains most of the shared logic used by
these widgets, making it easier to test the common code.
In proper MVP design, user code would interact with the presenter. However, that would complicate the widget code. Instead, each widget owns its own presenter and contains its own View. The widget forwards commands through to the presenter, which then updates the widget via the view. This keeps the user facing API simpler.
Updates are not pushed to the view immediately. Instead, the presenter
collects updates and resolves them all in a finally command. This reduces the
total number of DOM manipulations, and makes it easier to handle side effects
in user code triggered by the rendering pass. The view is responsible for
called flush()
to force the presenter to synchronize the view when
needed.
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
HasDataPresenter.ElementIterator
An iterator over DOM elements.
|
(package private) static interface |
HasDataPresenter.View<T>
The view that this presenter presents.
|
HasKeyboardPagingPolicy.KeyboardPagingPolicy
HasKeyboardSelectionPolicy.KeyboardSelectionPolicy
Modifier and Type | Field and Description |
---|---|
(package private) static int |
PAGE_INCREMENT
The number of rows to jump when PAGE_UP or PAGE_DOWN is pressed and the
HasKeyboardPagingPolicy.KeyboardPagingPolicy is
HasKeyboardPagingPolicy.KeyboardPagingPolicy.INCREASE_RANGE . |
Constructor and Description |
---|
HasDataPresenter(HasData<T> display,
HasDataPresenter.View<T> view,
int pageSize,
ProvidesKey<T> keyProvider)
Construct a new
HasDataPresenter . |
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addCellPreviewHandler(CellPreviewEvent.Handler<T> handler)
Adds a
CellPreviewEvent handler. |
HandlerRegistration |
addLoadingStateChangeHandler(LoadingStateChangeEvent.Handler handler) |
HandlerRegistration |
addRangeChangeHandler(RangeChangeEvent.Handler handler)
Add a
RangeChangeEvent.Handler . |
HandlerRegistration |
addRowCountChangeHandler(RowCountChangeEvent.Handler handler)
Add a
RowCountChangeEvent.Handler . |
(package private) java.util.List<Range> |
calculateModifiedRanges(JsArrayInteger modifiedRows,
int pageStart,
int pageEnd)
Combine the modified row indexes into as many as two
Range s,
optimizing to have the fewest unmodified rows within the ranges. |
void |
clearKeyboardSelectedRowValue()
Clear the row value associated with the keyboard selected row.
|
void |
clearSelectionModel()
Clear the
SelectionModel without updating the view. |
void |
fireEvent(GwtEvent<?> event)
Fires the given event to the handlers listening to the event's type.
|
void |
flush()
Flush pending changes to the view.
|
int |
getCurrentPageSize()
Get the current page size.
|
HasKeyboardPagingPolicy.KeyboardPagingPolicy |
getKeyboardPagingPolicy()
|
int |
getKeyboardSelectedRow()
Get the index of the keyboard selected row relative to the page start.
|
int |
getKeyboardSelectedRowInView()
Get the index of the keyboard selected row relative to the page start as it
appears in the view, regardless of whether or not there is a pending
change.
|
T |
getKeyboardSelectedRowValue()
Get the value that the user selected.
|
HasKeyboardSelectionPolicy.KeyboardSelectionPolicy |
getKeyboardSelectionPolicy()
|
ProvidesKey<T> |
getKeyProvider()
Return the key provider.
|
int |
getRowCount()
Get the overall data size.
|
SelectionModel<? super T> |
getSelectionModel()
Get the
SelectionModel used by this HasData . |
T |
getVisibleItem(int indexOnPage)
Get the row value at the specified visible index.
|
int |
getVisibleItemCount()
Get the number of visible items being displayed.
|
java.util.List<T> |
getVisibleItems()
Get an
Iterable composed of all of the visible items. |
Range |
getVisibleRange()
Return the range of data being displayed.
|
boolean |
hasPendingState()
Check whether or not there is a pending state.
|
boolean |
isEmpty()
Check whether or not the data set is empty.
|
boolean |
isRowCountExact()
Check if the total row count is exact, or an estimate.
|
void |
redraw()
Redraw the list with the current data.
|
protected void |
scheduleFinally(Scheduler.ScheduledCommand command)
Schedules the command.
|
void |
setKeyboardPagingPolicy(HasKeyboardPagingPolicy.KeyboardPagingPolicy policy)
|
void |
setKeyboardSelectedRow(int index,
boolean stealFocus,
boolean forceUpdate)
Set the row index of the keyboard selected element.
|
void |
setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy policy)
|
void |
setRowCount(int count)
Set the exact total count of all rows.
|
void |
setRowCount(int count,
boolean isExact)
Set the total count of all rows, specifying whether the count is exact or
an estimate.
|
void |
setRowData(int start,
java.util.List<? extends T> values)
Set a values associated with the rows in the visible range.
|
void |
setSelectionModel(SelectionModel<? super T> selectionModel)
Set the
SelectionModel used by this HasData . |
void |
setVisibleRange(int start,
int length)
Set the visible range or rows.
|
void |
setVisibleRange(Range range)
Set the visible range or rows.
|
void |
setVisibleRangeAndClearData(Range range,
boolean forceRangeChangeEvent)
Set the visible range and clear the current visible data.
|
static final int PAGE_INCREMENT
HasKeyboardPagingPolicy.KeyboardPagingPolicy
is
HasKeyboardPagingPolicy.KeyboardPagingPolicy.INCREASE_RANGE
.public HasDataPresenter(HasData<T> display, HasDataPresenter.View<T> view, int pageSize, ProvidesKey<T> keyProvider)
HasDataPresenter
.display
- the display that is being presentedview
- the view implementationpageSize
- the default page sizepublic HandlerRegistration addCellPreviewHandler(CellPreviewEvent.Handler<T> handler)
HasCellPreviewHandlers
CellPreviewEvent
handler.addCellPreviewHandler
in interface HasCellPreviewHandlers<T>
handler
- the handlerpublic HandlerRegistration addLoadingStateChangeHandler(LoadingStateChangeEvent.Handler handler)
public HandlerRegistration addRangeChangeHandler(RangeChangeEvent.Handler handler)
HasRows
RangeChangeEvent.Handler
.addRangeChangeHandler
in interface HasRows
handler
- the handlerHandlerRegistration
to remove the handlerpublic HandlerRegistration addRowCountChangeHandler(RowCountChangeEvent.Handler handler)
HasRows
RowCountChangeEvent.Handler
.addRowCountChangeHandler
in interface HasRows
handler
- the handlerHandlerRegistration
to remove the handlerpublic void clearKeyboardSelectedRowValue()
public void clearSelectionModel()
SelectionModel
without updating the view.public void fireEvent(GwtEvent<?> event)
HasHandlers
Any exceptions thrown by handlers will be bundled into a
UmbrellaException
and then re-thrown after all handlers have
completed. An exception thrown by a handler will not prevent other handlers
from executing.
fireEvent
in interface HasHandlers
event
- the eventjava.lang.UnsupportedOperationException
public void flush()
public int getCurrentPageSize()
public HasKeyboardPagingPolicy.KeyboardPagingPolicy getKeyboardPagingPolicy()
HasKeyboardPagingPolicy
getKeyboardPagingPolicy
in interface HasKeyboardPagingPolicy
HasKeyboardPagingPolicy.setKeyboardPagingPolicy(KeyboardPagingPolicy)
public int getKeyboardSelectedRow()
public int getKeyboardSelectedRowInView()
public T getKeyboardSelectedRowValue()
public HasKeyboardSelectionPolicy.KeyboardSelectionPolicy getKeyboardSelectionPolicy()
HasKeyboardSelectionPolicy
getKeyboardSelectionPolicy
in interface HasKeyboardSelectionPolicy
HasKeyboardSelectionPolicy.setKeyboardSelectionPolicy(KeyboardSelectionPolicy)
public ProvidesKey<T> getKeyProvider()
HasKeyProvider
getKeyProvider
in interface HasKeyProvider<T>
ProvidesKey
instancepublic int getRowCount()
getRowCount
in interface HasRows
HasRows.setRowCount(int)
public SelectionModel<? super T> getSelectionModel()
HasData
SelectionModel
used by this HasData
.getSelectionModel
in interface HasData<T>
SelectionModel
HasData.setSelectionModel(SelectionModel)
public T getVisibleItem(int indexOnPage)
HasData
getVisibleItem
in interface HasData<T>
indexOnPage
- the index on the pagepublic int getVisibleItemCount()
HasData
getVisibleItemCount
in interface HasData<T>
public java.util.List<T> getVisibleItems()
HasData
Iterable
composed of all of the visible items.getVisibleItems
in interface HasData<T>
Iterable
instancepublic Range getVisibleRange()
getVisibleRange
in interface HasRows
HasRows.setVisibleRange(Range)
,
HasRows.setVisibleRange(int, int)
public boolean hasPendingState()
public boolean isEmpty()
public boolean isRowCountExact()
HasRows
isRowCountExact
in interface HasRows
public void redraw()
public void setKeyboardPagingPolicy(HasKeyboardPagingPolicy.KeyboardPagingPolicy policy)
HasKeyboardPagingPolicy
setKeyboardPagingPolicy
in interface HasKeyboardPagingPolicy
policy
- the paging policyHasKeyboardPagingPolicy.getKeyboardPagingPolicy()
public void setKeyboardSelectedRow(int index, boolean stealFocus, boolean forceUpdate)
index
- the row indexstealFocus
- true to steal focusforceUpdate
- force the update even if the row didn't changepublic void setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy policy)
HasKeyboardSelectionPolicy
setKeyboardSelectionPolicy
in interface HasKeyboardSelectionPolicy
policy
- the selection policyHasKeyboardSelectionPolicy.getKeyboardSelectionPolicy()
public final void setRowCount(int count)
HasRows
HasRows.setRowCount(int, boolean)
.setRowCount
in interface HasRows
count
- the exact total countjava.lang.UnsupportedOperationException
HasRows.getRowCount()
public void setRowCount(int count, boolean isExact)
HasRows
setRowCount
in interface HasRows
count
- the total countisExact
- true if the count is exact, false if an estimateHasRows.getRowCount()
public void setRowData(int start, java.util.List<? extends T> values)
HasData
Set a values associated with the rows in the visible range.
This method does not replace all rows in the display; it replaces
the row values starting at the specified start index through the length of
the specified values. You must call HasRows.setRowCount(int)
to set
the total number of rows in the display. You should also use
HasRows.setRowCount(int)
to remove rows when the total number of rows
decreases.
setRowData
in interface HasData<T>
start
- the start index of the datavalues
- the values within the rangepublic void setSelectionModel(SelectionModel<? super T> selectionModel)
HasData
SelectionModel
used by this HasData
.setSelectionModel
in interface HasData<T>
selectionModel
- the SelectionModel
HasData.getSelectionModel()
public final void setVisibleRange(int start, int length)
HasRows
HasRows.setVisibleRange(Range)
.setVisibleRange
in interface HasRows
start
- the start indexlength
- the lengthjava.lang.UnsupportedOperationException
HasRows.getVisibleRange()
public void setVisibleRange(Range range)
HasRows
setVisibleRange
in interface HasRows
range
- the visible rangeHasRows.getVisibleRange()
public void setVisibleRangeAndClearData(Range range, boolean forceRangeChangeEvent)
HasData
Set the visible range and clear the current visible data.
If the second argument forceRangeChangeEvent
is true, a
RangeChangeEvent
will be fired even if the range does not change.
If false, a RangeChangeEvent
will only be fired if the range
changes.
setVisibleRangeAndClearData
in interface HasData<T>
range
- the new Range
forceRangeChangeEvent
- true to fire a RangeChangeEvent
even
if the Range
doesn't changeprotected void scheduleFinally(Scheduler.ScheduledCommand command)
Protected so that subclasses can override to use an alternative scheduler.
command
- the command to executejava.util.List<Range> calculateModifiedRanges(JsArrayInteger modifiedRows, int pageStart, int pageEnd)
Range
s,
optimizing to have the fewest unmodified rows within the ranges. Using two
ranges covers the most common use cases of selecting one row, selecting a
range, moving selection from one row to another, or moving keyboard
selection.
Visible for testing.
This method has the side effect of sorting the modified rows.
modifiedRows
- the unordered indexes of modified rows