M
- the model typeN
- the cell data typepublic class ListView<M,N> extends Component implements RefreshEvent.HasRefreshHandlers
A ListView
provides support for displaying a list of data. The list
view gets its data from a ListStore
. Each model in the store is
rendered as an item in the list view. Any updates to the store are
automatically pushed to the list view.
In GXT version 3, ModelKeyProvider
s and ValueProvider
s
provide the interface between your data model, the list store and the list
view. This enables a list view to work with data of any object type. The list
view uses a value provider, passed to the constructor, to get the value to
display for each model in the list view.
You can provide your own implementation of these interfaces, or you can use a
Sencha supplied generator to create them for you automatically. A generator
runs at compile time to create a Java class that is compiled to JavaScript.
The Sencha supplied generator can create classes for interfaces that extend
the PropertyAccess
interface. The generator transparently creates the
class at compile time and the GWT#create(Class)
method returns an
instance of that class at run time. The generated class is managed by GWT and
GXT and you generally do not need to worry about what the class is called,
where it is located, or other similar details.
To customize the appearance of the item in the list view, provide a cell
implementation using ListView#setCell(Cell)
.
The following code snippet illustrates the creation of a simple list view with local data for test purposes. For more practical examples that show how to customize list views to display images or use other types of cells, see the ListView, Advanced ListView and DateCell ListView examples in the online Explorer demo.
// Generate the key provider and value provider for the Data class
DataProperties dp = GWT.create(DataProperties.class);
// Create the store that the contains the data to display in the grid
ListStore<Data> s = new ListStore<Test.Data>(dp.key());
s.add(new Data("name1", "value1"));
s.add(new Data("name2", "value2"));
s.add(new Data("name3", "value3"));
s.add(new Data("name4", "value4"));
// Create the tree using the store and value provider for the name field
ListView<Data, String> t = new ListView<Data, String>(s, dp.name());
// Add the tree to a container
RootPanel.get().add(t);
To use the Sencha supplied generator to create model key providers and value
providers, extend the PropertyAccess
interface, parameterized
with the type of data you want to access (as shown below) and invoke the
GWT.create
method on its class
member (as shown in
the code snippet above). This creates an instance of the class that can be
used to initialize the list view and list store. In the following code
snippet we define a new interface called DataProperties
that
extends the PropertyAccess
interface and is parameterized with
Data
, a Plain Old Java Object (POJO).
public interface DataProperties extends PropertyAccess<Data> {
@Path("name")
ModelKeyProvider<Data> key();
ValueProvider<Data, String> name();
ValueProvider<Data, String> value();
}
public class Data {
private String name;
private String value;
public Data(String name, String value) {
super();
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
Modifier and Type | Class and Description |
---|---|
static interface |
ListView.ListViewAppearance<M>
The appearance of a list view.
|
Modifier and Type | Field and Description |
---|---|
protected XElement |
focusEl |
protected FocusImpl |
focusImpl |
protected int |
rowSelectorDepth |
protected ListStore<M> |
store |
protected ValueProvider<? super M,N> |
valueProvider |
adjustSize, allowTextSelection, cacheSizes, disableContextMenu, disabled, disabledStyle, ensureVisibilityOnSizing, height, hidden, lastSize, layer, left, mask, maskMessage, monitorWindowResize, pageX, pageY, resizeHandler, shim, tabIndex, toolTip, toolTipConfig, top, width, windowResizeDelay, windowResizeTask
Constructor and Description |
---|
ListView(ListStore<M> store,
ValueProvider<? super M,N> valueProvider)
Creates a new list view.
|
ListView(ListStore<M> store,
ValueProvider<? super M,N> valueProvider,
<any> cell)
Creates a new list view.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addRefreshHandler(RefreshEvent.RefreshHandler handler)
Adds a
RefreshEvent.RefreshHandler handler for
RefreshEvent events. |
protected void |
bufferRender(List<M> models,
SafeHtmlBuilder sb) |
protected boolean |
cellConsumesEventType(<any> cell,
String eventType) |
Element |
findElement(Element element)
Returns the matching element.
|
int |
findElementIndex(Element element)
Returns the element's index.
|
void |
focus()
Try to focus this widget.
|
protected void |
focusItem(int index) |
ListView.ListViewAppearance<M> |
getAppearance() |
<any> |
getCell()
Returns the view's cell.
|
XElement |
getElement(int index)
Returns the element at the given index.
|
List<Element> |
getElements()
Returns all of the child elements.
|
int |
getItemCount()
Returns the number of models in the view.
|
SafeHtml |
getLoadingIndicator()
Returns the view's loading indicator as html.
|
QuickTip |
getQuickTip()
Returns the view's quick tip instance.
|
ListViewSelectionModel<M> |
getSelectionModel()
Returns the view's selection model.
|
boolean |
getSelectOnOver()
Returns true if select on hover is enabled.
|
ListStore<M> |
getStore()
Returns the combo's store.
|
protected N |
getValue(M m) |
protected void |
handleEventForCell(Event event) |
int |
indexOf(Element element)
Returns the index of the element.
|
boolean |
isEnableQuickTips()
Returns true if quicktips are enabled.
|
boolean |
isTrackMouseOver()
Returns true if items are highlighted on mouse over.
|
void |
moveSelectedDown()
Moves the current selections down one level.
|
void |
moveSelectedUp()
Moves the current selections up one level.
|
protected void |
onAdd(List<M> models,
int index) |
protected void |
onAfterFirstAttach()
Called immediately after the first time the widget becomes attached to the browser's document only the first time.
|
protected void |
onBeforeLoad()
Is called before a load when a #setLoader(Loader) and {@link #setLoadingIndicator(SafeHtml) or
{@link #setLoadingIndicator(String)} are used the list will display the loading HTML.
|
void |
onBrowserEvent(Event event) |
protected void |
onFocus(Event event) |
protected void |
onHighlightRow(int index,
boolean highLight) |
protected void |
onLoadError(LoadExceptionEvent<?> event)
Is called on loader exception.
|
protected void |
onLongPress(TouchData touchData) |
protected void |
onMouseDown(Event e) |
protected void |
onMouseOut(Event ce) |
protected void |
onMouseOver(Event ce) |
protected void |
onRemove(M data,
int index) |
protected void |
onResize(int width,
int height)
Called after the widget is resized, this method is empty by default but can be implemented by any subclass that
needs to perform custom logic after a resize occurs.
|
protected void |
onSelectChange(M model,
boolean select) |
protected void |
onTap(TouchData touch) |
protected void |
onUpdate(M model,
int index) |
void |
refresh()
Refreshes the view by reloading the data from the store and re-rendering
the template.
|
void |
refreshNode(int index)
Refreshes an individual node's data from the store.
|
void |
setAllowTextSelection(boolean enable)
Enables and disables text selection for the widget.
|
void |
setCell(<any> cell)
Optionally sets the view's cell.
|
void |
setEnableQuickTips(boolean enableQuickTip)
True to enable quicktips (defaults to true, pre-render).
|
void |
setLoader(Loader<?,?> loader)
Sets the loader.
|
void |
setLoadingIndicator(SafeHtml html)
Sets the loading indicator html to be displayed during a load request.
|
void |
setSelectionModel(ListViewSelectionModel<M> sm)
Sets the selection model.
|
void |
setSelectOnOver(boolean selectOnHover)
True to select the item when mousing over a element (defaults to false).
|
void |
setStore(ListStore<M> store)
Changes the data store bound to this view and refreshes it.
|
void |
setTrackMouseOver(boolean trackMouseOver)
True to highlight items when the mouse is over (defaults to true).
|
protected void |
updateIndexes(int startIndex,
int endIndex) |
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addGestureRecognizer, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleDependentName, addStyleOnOver, adjustPosition, adjustSize, applyState, assertAfterRender, assertPreRender, blur, clearSizeCache, disable, disableContextMenu, disableEvents, enable, enableEvents, fireCancellableEvent, fireEvent, getData, getElement, getFocusEl, getFocusSupport, getGestureRecognizer, getGestureRecognizerCount, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideShadow, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, mask, mask, notifyHide, notifyShow, onAttach, onBlur, onDetach, onDisable, onEnable, onHide, onHideContextMenu, onLoad, onPosition, onRightClick, onShow, onShowContextMenu, onTouch, onUnload, onWindowResize, removeStyleDependentName, removeStyleOnOver, removeToolTip, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setMonitorWindowResize, setPagePosition, setPixelSize, setPosition, setShadow, setShadowPosition, setSize, setStateful, setStateId, setStyleDependentName, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
protected XElement focusEl
protected final FocusImpl focusImpl
protected int rowSelectorDepth
protected final ValueProvider<? super M,N> valueProvider
public ListView(ListStore<M> store, ValueProvider<? super M,N> valueProvider)
store
- the storevalueProvider
- the value providerpublic ListView(ListStore<M> store, ValueProvider<? super M,N> valueProvider, <any> cell)
store
- the storevalueProvider
- the value providercell
- the cellpublic HandlerRegistration addRefreshHandler(RefreshEvent.RefreshHandler handler)
RefreshEvent.HasRefreshHandlers
RefreshEvent.RefreshHandler
handler for
RefreshEvent
events.addRefreshHandler
in interface RefreshEvent.HasRefreshHandlers
handler
- the handlerpublic Element findElement(Element element)
element
- the element or any child elementpublic int findElementIndex(Element element)
element
- the element or any child elementpublic void focus()
Component
public ListView.ListViewAppearance<M> getAppearance()
public <any> getCell()
public XElement getElement(int index)
index
- the indexpublic List<Element> getElements()
public int getItemCount()
public SafeHtml getLoadingIndicator()
public QuickTip getQuickTip()
public ListViewSelectionModel<M> getSelectionModel()
public boolean getSelectOnOver()
public int indexOf(Element element)
element
- the elementpublic boolean isEnableQuickTips()
public boolean isTrackMouseOver()
public void moveSelectedDown()
public void moveSelectedUp()
public void onBrowserEvent(Event event)
onBrowserEvent
in class Component
public void refresh()
public void refreshNode(int index)
index
- the items data index in the storepublic void setAllowTextSelection(boolean enable)
Component
setAllowTextSelection
in class Component
enable
- true to enable, false to disablepublic void setCell(<any> cell)
cell
- the cellpublic void setEnableQuickTips(boolean enableQuickTip)
enableQuickTip
- true to enable quicktipspublic void setLoader(Loader<?,?> loader)
setLoadingIndicator(SafeHtml)
or #setLoadingIndicator(String)
.onBeforeLoad()
is called before a load and sets the loading HTML.onLoadError(com.sencha.gxt.data.shared.loader.LoadExceptionEvent)
is called on load exception.loader
- is the list loaderpublic void setLoadingIndicator(SafeHtml html)
setLoader(Loader)
has to be set for this use.
html
- the loading htmlpublic void setSelectionModel(ListViewSelectionModel<M> sm)
sm
- the selection modelpublic void setSelectOnOver(boolean selectOnHover)
selectOnHover
- true to select on mouse overpublic void setStore(ListStore<M> store)
store
- the store to bind this viewpublic void setTrackMouseOver(boolean trackMouseOver)
trackMouseOver
- true to highlight rows on mouse overprotected boolean cellConsumesEventType(<any> cell, String eventType)
protected void focusItem(int index)
protected void handleEventForCell(Event event)
protected void onAfterFirstAttach()
Component
onAfterFirstAttach
in class Component
protected void onBeforeLoad()
protected void onLoadError(LoadExceptionEvent<?> event)
setLoader(Loader)
has to be set for this to be called.
event
- is the load exception eventprotected void onHighlightRow(int index, boolean highLight)
protected void onLongPress(TouchData touchData)
protected void onMouseDown(Event e)
protected void onMouseOut(Event ce)
protected void onMouseOver(Event ce)
protected void onRemove(M data, int index)
protected void onResize(int width, int height)
Component
protected void onSelectChange(M model, boolean select)
protected void onTap(TouchData touch)
protected void onUpdate(M model, int index)
protected void updateIndexes(int startIndex, int endIndex)
Copyright © 2018. All rights reserved.