M
- the model typeN
- the cell data typepublic class ListView<M,N> extends Component implements RefreshEvent.HasRefreshHandlers
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 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 s = new ListStoreTo use the Sencha supplied generator to create model key providers and value providers, extend the(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 t = new ListView(s, dp.name()); // Add the tree to a container RootPanel.get().add(t);
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 { @Path("name") ModelKeyProvider 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.
|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
DEBUG_ID_PREFIX
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,
Cell<N> cell)
Creates a new list view.
|
ListView(ListStore<M> store,
ValueProvider<? super M,N> valueProvider,
ListView.ListViewAppearance<M> appearance)
Creates a new list view.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addRefreshHandler(RefreshEvent.RefreshHandler handler)
Adds a
RefreshEvent.RefreshHandler handler for
RefreshEvent events. |
Element |
findElement(Element element)
Returns the matching element.
|
int |
findElementIndex(Element element)
Returns the element's index.
|
void |
focus()
Try to focus this widget.
|
ListView.ListViewAppearance<M> |
getAppearance() |
Cell<N> |
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 |
getLoadingHtml()
Returns the view's loading 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.
|
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.
|
void |
onBrowserEvent(Event event) |
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(Cell<N> 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 |
setLoadingHtml(SafeHtml loadingHtml)
Sets the html loading text to be displayed during a load request.
|
void |
setLoadingText(String loadingText)
Sets the text loading text 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).
|
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleOnOver, clearSizeCache, disable, disableEvents, enable, enableEvents, fireEvent, getData, getElement, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isRendered, isStateful, isVisible, isVisible, mask, mask, removeToolTip, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setPagePosition, setPixelSize, setPosition, setShadow, setShadowPosition, setSize, setStateful, setStateId, setTabIndex, setToolTip, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, removeStyleName, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, sinkBitlessEvent, toString
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, Cell<N> cell)
store
- the storevalueProvider
- the value providercell
- the cellpublic ListView(ListStore<M> store, ValueProvider<? super M,N> valueProvider, ListView.ListViewAppearance<M> appearance)
store
- the storevalueProvider
- the value providerappearance
- the appearancepublic 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 Cell<N> getCell()
public XElement getElement(int index)
index
- the indexpublic List<Element> getElements()
public int getItemCount()
public SafeHtml getLoadingHtml()
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 interface EventListener
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(Cell<N> cell)
cell
- the cellpublic void setEnableQuickTips(boolean enableQuickTip)
enableQuickTip
- true to enable quicktipspublic void setLoader(Loader<?,?> loader)
setLoadingHtml(SafeHtml)
or setLoadingText(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 setLoadingHtml(SafeHtml loadingHtml)
setLoader(Loader)
has to be set for this use.
loadingHtml
- the loading htmlpublic void setLoadingText(String loadingText)
setLoader(Loader)
has to be set for this use.
loadingText
- the loading textpublic 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 overCopyright © 2015. All rights reserved.