Class HasDataPresenter<T>
- Type Parameters:
T
- the data type of items in the list
- All Implemented Interfaces:
HasHandlers
,HasKeyboardPagingPolicy
,HasKeyboardSelectionPolicy
,HasCellPreviewHandlers<T>
,HasData<T>
,HasKeyProvider<T>
,HasRows
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.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static interface
An iterator over DOM elements.(package private) static interface
The view that this presenter presents.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
Modifier and TypeFieldDescription(package private) static final int
The number of rows to jump when PAGE_UP or PAGE_DOWN is pressed and theHasKeyboardPagingPolicy.KeyboardPagingPolicy
isHasKeyboardPagingPolicy.KeyboardPagingPolicy.INCREASE_RANGE
. -
Constructor Summary
ConstructorDescriptionHasDataPresenter
(HasData<T> display, HasDataPresenter.View<T> view, int pageSize, ProvidesKey<T> keyProvider) Construct a newHasDataPresenter
. -
Method Summary
Modifier and TypeMethodDescriptionaddCellPreviewHandler
(CellPreviewEvent.Handler<T> handler) Adds aCellPreviewEvent
handler.Add aRangeChangeEvent.Handler
.Add aRowCountChangeEvent.Handler
.calculateModifiedRanges
(JsArrayInteger modifiedRows, int pageStart, int pageEnd) Combine the modified row indexes into as many as twoRange
s, optimizing to have the fewest unmodified rows within the ranges.void
Clear the row value associated with the keyboard selected row.void
Clear theSelectionModel
without updating the view.void
Fires the given event to the handlers listening to the event's type.void
flush()
Flush pending changes to the view.int
Get the current page size.int
Get the index of the keyboard selected row relative to the page start.int
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.Get the value that the user selected.Return the key provider.int
Get the overall data size.SelectionModel
<? super T> Get theSelectionModel
used by thisHasData
.getVisibleItem
(int indexOnPage) Get the row value at the specified visible index.int
Get the number of visible items being displayed.Get anIterable
composed of all of the visible items.Return the range of data being displayed.boolean
Check whether or not there is a pending state.boolean
isEmpty()
Check whether or not the data set is empty.boolean
Check if the total row count is exact, or an estimate.void
redraw()
Redraw the list with the current data.protected void
Schedules the command.void
void
setKeyboardSelectedRow
(int index, boolean stealFocus, boolean forceUpdate) Set the row index of the keyboard selected element.void
final 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, List<? extends T> values) Set a values associated with the rows in the visible range.void
setSelectionModel
(SelectionModel<? super T> selectionModel) Set theSelectionModel
used by thisHasData
.final 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.
-
Field Details
-
PAGE_INCREMENT
static final int PAGE_INCREMENTThe number of rows to jump when PAGE_UP or PAGE_DOWN is pressed and theHasKeyboardPagingPolicy.KeyboardPagingPolicy
isHasKeyboardPagingPolicy.KeyboardPagingPolicy.INCREASE_RANGE
.- See Also:
-
-
Constructor Details
-
HasDataPresenter
public HasDataPresenter(HasData<T> display, HasDataPresenter.View<T> view, int pageSize, ProvidesKey<T> keyProvider) Construct a newHasDataPresenter
.- Parameters:
display
- the display that is being presentedview
- the view implementationpageSize
- the default page size
-
-
Method Details
-
addCellPreviewHandler
Description copied from interface:HasCellPreviewHandlers
Adds aCellPreviewEvent
handler.- Specified by:
addCellPreviewHandler
in interfaceHasCellPreviewHandlers<T>
- Parameters:
handler
- the handler- Returns:
- the registration for the event
-
addLoadingStateChangeHandler
-
addRangeChangeHandler
Description copied from interface:HasRows
Add aRangeChangeEvent.Handler
.- Specified by:
addRangeChangeHandler
in interfaceHasRows
- Parameters:
handler
- the handler- Returns:
- a
HandlerRegistration
to remove the handler
-
addRowCountChangeHandler
Description copied from interface:HasRows
Add aRowCountChangeEvent.Handler
.- Specified by:
addRowCountChangeHandler
in interfaceHasRows
- Parameters:
handler
- the handler- Returns:
- a
HandlerRegistration
to remove the handler
-
clearKeyboardSelectedRowValue
public void clearKeyboardSelectedRowValue()Clear the row value associated with the keyboard selected row. -
clearSelectionModel
public void clearSelectionModel()Clear theSelectionModel
without updating the view. -
flush
public void flush()Flush pending changes to the view. -
getCurrentPageSize
public int getCurrentPageSize()Get the current page size. This is usually the page size, but can be less if the data size cannot fill the current page.- Returns:
- the size of the current page
-
getKeyboardPagingPolicy
Description copied from interface:HasKeyboardPagingPolicy
- Specified by:
getKeyboardPagingPolicy
in interfaceHasKeyboardPagingPolicy
- Returns:
- the paging policy
- See Also:
-
getKeyboardSelectedRow
public int getKeyboardSelectedRow()Get the index of the keyboard selected row relative to the page start.- Returns:
- the row index, or -1 if disabled
-
getKeyboardSelectedRowInView
public 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.- Returns:
- the row index, or -1 if disabled
-
getKeyboardSelectedRowValue
Get the value that the user selected.- Returns:
- the value, or null if a value was not selected
-
getKeyboardSelectionPolicy
Description copied from interface:HasKeyboardSelectionPolicy
- Specified by:
getKeyboardSelectionPolicy
in interfaceHasKeyboardSelectionPolicy
- Returns:
- the selection policy
- See Also:
-
getKeyProvider
Description copied from interface:HasKeyProvider
Return the key provider.- Specified by:
getKeyProvider
in interfaceHasKeyProvider<T>
- Returns:
- the
ProvidesKey
instance
-
getRowCount
public int getRowCount()Get the overall data size.- Specified by:
getRowCount
in interfaceHasRows
- Returns:
- the data size
- See Also:
-
getSelectionModel
Description copied from interface:HasData
Get theSelectionModel
used by thisHasData
.- Specified by:
getSelectionModel
in interfaceHasData<T>
- Returns:
- the
SelectionModel
- See Also:
-
getVisibleItem
Description copied from interface:HasData
Get the row value at the specified visible index. Index 0 corresponds to the first item on the page.- Specified by:
getVisibleItem
in interfaceHasData<T>
- Parameters:
indexOnPage
- the index on the page- Returns:
- the row value
-
getVisibleItemCount
public int getVisibleItemCount()Description copied from interface:HasData
Get the number of visible items being displayed. Note that this value might be less than the page size if there is not enough data to fill the page.- Specified by:
getVisibleItemCount
in interfaceHasData<T>
- Returns:
- the number of visible items on the page
-
getVisibleItems
Description copied from interface:HasData
Get anIterable
composed of all of the visible items.- Specified by:
getVisibleItems
in interfaceHasData<T>
- Returns:
- an
Iterable
instance
-
getVisibleRange
Return the range of data being displayed.- Specified by:
getVisibleRange
in interfaceHasRows
- Returns:
- the visible range
- See Also:
-
hasPendingState
public boolean hasPendingState()Check whether or not there is a pending state. If there is a pending state, views might skip DOM updates and wait for the new data to be rendered when the pending state is resolved.- Returns:
- true if there is a pending state, false if not
-
isEmpty
public boolean isEmpty()Check whether or not the data set is empty. That is, the row count is exactly 0.- Returns:
- true if data set is empty
-
isRowCountExact
public boolean isRowCountExact()Description copied from interface:HasRows
Check if the total row count is exact, or an estimate.- Specified by:
isRowCountExact
in interfaceHasRows
- Returns:
- true if exact, false if an estimate
-
redraw
public void redraw()Redraw the list with the current data. -
setKeyboardPagingPolicy
Description copied from interface:HasKeyboardPagingPolicy
- Specified by:
setKeyboardPagingPolicy
in interfaceHasKeyboardPagingPolicy
- Parameters:
policy
- the paging policy- See Also:
-
setKeyboardSelectedRow
public void setKeyboardSelectedRow(int index, boolean stealFocus, boolean forceUpdate) Set the row index of the keyboard selected element.- Parameters:
index
- the row indexstealFocus
- true to steal focusforceUpdate
- force the update even if the row didn't change
-
setKeyboardSelectionPolicy
Description copied from interface:HasKeyboardSelectionPolicy
- Specified by:
setKeyboardSelectionPolicy
in interfaceHasKeyboardSelectionPolicy
- Parameters:
policy
- the selection policy- See Also:
-
setRowCount
public final void setRowCount(int count) Description copied from interface:HasRows
Set the exact total count of all rows. This method defers toHasRows.setRowCount(int, boolean)
.- Specified by:
setRowCount
in interfaceHasRows
- Parameters:
count
- the exact total count- Throws:
UnsupportedOperationException
- See Also:
-
setRowCount
public void setRowCount(int count, boolean isExact) Description copied from interface:HasRows
Set the total count of all rows, specifying whether the count is exact or an estimate.- Specified by:
setRowCount
in interfaceHasRows
- Parameters:
count
- the total countisExact
- true if the count is exact, false if an estimate- See Also:
-
setRowData
Description copied from interface: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 useHasRows.setRowCount(int)
to remove rows when the total number of rows decreases.- Specified by:
setRowData
in interfaceHasData<T>
- Parameters:
start
- the start index of the datavalues
- the values within the range
-
setSelectionModel
Description copied from interface:HasData
Set theSelectionModel
used by thisHasData
.- Specified by:
setSelectionModel
in interfaceHasData<T>
- Parameters:
selectionModel
- theSelectionModel
- See Also:
-
setVisibleRange
public final void setVisibleRange(int start, int length) Description copied from interface:HasRows
Set the visible range or rows. This method defers toHasRows.setVisibleRange(Range)
.- Specified by:
setVisibleRange
in interfaceHasRows
- Parameters:
start
- the start indexlength
- the length- Throws:
UnsupportedOperationException
- See Also:
-
setVisibleRange
Description copied from interface:HasRows
Set the visible range or rows.- Specified by:
setVisibleRange
in interfaceHasRows
- Parameters:
range
- the visible range- See Also:
-
setVisibleRangeAndClearData
Description copied from interface:HasData
Set the visible range and clear the current visible data.
If the second argument
forceRangeChangeEvent
is true, aRangeChangeEvent
will be fired even if the range does not change. If false, aRangeChangeEvent
will only be fired if the range changes.- Specified by:
setVisibleRangeAndClearData
in interfaceHasData<T>
- Parameters:
range
- the newRange
forceRangeChangeEvent
- true to fire aRangeChangeEvent
even if theRange
doesn't change
-
scheduleFinally
Schedules the command.Protected so that subclasses can override to use an alternative scheduler.
- Parameters:
command
- the command to execute
-
calculateModifiedRanges
Combine the modified row indexes into as many as twoRange
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.
- Parameters:
modifiedRows
- the unordered indexes of modified rows- Returns:
- up to two ranges that encompass the modified rows
-