Errai 3.0.1-SNAPSHOT

org.jboss.errai.ui.client.widget
Class ListWidget<M,W extends HasModel<M> & com.google.gwt.user.client.ui.IsWidget>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Composite
              extended by org.jboss.errai.ui.client.widget.ListWidget<M,W>
Type Parameters:
M - the model type
W - the item widget type, needs to implement HasModel for associating the widget instance with the corresponding model instance.
All Implemented Interfaces:
com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.logical.shared.HasValueChangeHandlers<List<M>>, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.TakesValue<List<M>>, com.google.gwt.user.client.ui.HasValue<List<M>>, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, BindableListChangeHandler<M>

public abstract class ListWidget<M,W extends HasModel<M> & com.google.gwt.user.client.ui.IsWidget>
extends com.google.gwt.user.client.ui.Composite
implements com.google.gwt.user.client.ui.HasValue<List<M>>, BindableListChangeHandler<M>

A type of widget that displays and manages a child widget for each item in a list of model objects. The widget instances are managed by Errai's IOC container and are arranged in a ComplexPanel. By default, a FlowPanel is used, but an alternative can be specified using ListWidget(ComplexPanel).

Author:
Christian Sadilek

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
protected ListWidget()
           
protected ListWidget(com.google.gwt.user.client.ui.ComplexPanel panel)
           
 
Method Summary
 com.google.gwt.event.shared.HandlerRegistration addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<List<M>> handler)
           
protected abstract  Class<W> getItemWidgetType()
          Returns the class object for the item widget type to look up new instances of the widget using the client-side bean manager.
protected  com.google.gwt.user.client.ui.ComplexPanel getPanel()
          Returns the panel that contains all item widgets.
 List<M> getValue()
           
 W getWidget(int index)
          Returns the widget at the specified index.
 W getWidget(M model)
          Returns the widget currently displaying the provided model.
 void onItemAdded(List<M> oldList, M item)
          Called when a single item has been appended to the list.
 void onItemAddedAt(List<M> oldList, int index, M item)
          Called when a single item has been added to the list at the provided index.
 void onItemChanged(List<M> oldList, int index, M item)
          Called when a single item has been changed.
 void onItemRemovedAt(List<M> oldList, int index)
          Called when a single item has been removed from the list at the provided index.
 void onItemsAdded(List<M> oldList, Collection<? extends M> items)
          Called when multiple items have been appended to the list.
 void onItemsAddedAt(List<M> oldList, int index, Collection<? extends M> item)
          Called when multiple items have been added to the list starting at the provided index.
 void onItemsCleared(List<M> oldList)
          Called when all items have been removed from the list.
 void onItemsRemovedAt(List<M> oldList, List<Integer> indexes)
          Called when multiple items have been removed from the list.
protected  void onItemsRendered(List<M> items)
          Called after all item widgets have been rendered.
 void setItems(List<M> items)
          Sets the list of model objects.
 void setValue(List<M> value)
           
 void setValue(List<M> value, boolean fireEvents)
           
 
Methods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

ListWidget

protected ListWidget()

ListWidget

protected ListWidget(com.google.gwt.user.client.ui.ComplexPanel panel)
Method Detail

getItemWidgetType

protected abstract Class<W> getItemWidgetType()
Returns the class object for the item widget type to look up new instances of the widget using the client-side bean manager.

Returns:
the item widget type.

onItemsRendered

protected void onItemsRendered(List<M> items)
Called after all item widgets have been rendered. By default, this is a NOOP, but subclasses can add behaviour if needed.

Using the standard synchronous bean manager this method is invoked before setItems(List) returns. However, when using the asynchronous bean manager and declaring @LoadAsync on the item widget, this method might be called after setItems(List) returns and after the corresponding JavaScript code has been downloaded.

Parameters:
items - the rendered item list. Every change to this list will update the corresponding rendered item widgets.

getPanel

protected com.google.gwt.user.client.ui.ComplexPanel getPanel()
Returns the panel that contains all item widgets.

Returns:
the item widget panel, never null.

setItems

public void setItems(List<M> items)
Sets the list of model objects. A widget instance of type will be added to the panel for each object in the list. The list will be wrapped in an BindableListWrapper to make direct changes to the list observable.

If the standard synchronous bean manager is used it is guaranteed that all widgets have been added to the panel when this method returns. In case the asynchronous bean manager is used this method might return before the widgets have been added to the panel. See onItemsRendered(List).

Parameters:
items - The list of model objects. If null or empty all existing child widgets will be removed.

getWidget

public W getWidget(int index)
Returns the widget at the specified index.

Parameters:
index - the index to be retrieved
Returns:
the widget at the specified index
Throws:
IndexOutOfBoundsException - if the index is out of range

getWidget

public W getWidget(M model)
Returns the widget currently displaying the provided model.

Parameters:
model - the model displayed by the widget
Returns:
the widget displaying the provided model instance, null if no widget was found for the model.

addValueChangeHandler

public com.google.gwt.event.shared.HandlerRegistration addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<List<M>> handler)
Specified by:
addValueChangeHandler in interface com.google.gwt.event.logical.shared.HasValueChangeHandlers<List<M>>

getValue

public List<M> getValue()
Specified by:
getValue in interface com.google.gwt.user.client.TakesValue<List<M>>
Specified by:
getValue in interface com.google.gwt.user.client.ui.HasValue<List<M>>

setValue

public void setValue(List<M> value)
Specified by:
setValue in interface com.google.gwt.user.client.TakesValue<List<M>>
Specified by:
setValue in interface com.google.gwt.user.client.ui.HasValue<List<M>>

setValue

public void setValue(List<M> value,
                     boolean fireEvents)
Specified by:
setValue in interface com.google.gwt.user.client.ui.HasValue<List<M>>

onItemAdded

public void onItemAdded(List<M> oldList,
                        M item)
Description copied from interface: BindableListChangeHandler
Called when a single item has been appended to the list.

Specified by:
onItemAdded in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the item was appended (equal to the old value of the list). Never null.
item - the added item. May be null.

onItemAddedAt

public void onItemAddedAt(List<M> oldList,
                          int index,
                          M item)
Description copied from interface: BindableListChangeHandler
Called when a single item has been added to the list at the provided index.

Specified by:
onItemAddedAt in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the item was added (equal to the old value of the list). Never null.
index - the index at which the item has been added.
item - the added item. May be null.

onItemsAdded

public void onItemsAdded(List<M> oldList,
                         Collection<? extends M> items)
Description copied from interface: BindableListChangeHandler
Called when multiple items have been appended to the list.

Specified by:
onItemsAdded in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the items were appended (equal to the old value of the list). Never null.
items - the added items. May contain null elements.

onItemsAddedAt

public void onItemsAddedAt(List<M> oldList,
                           int index,
                           Collection<? extends M> item)
Description copied from interface: BindableListChangeHandler
Called when multiple items have been added to the list starting at the provided index.

Specified by:
onItemsAddedAt in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the items were added (equal to the old value of the list). Never null.
index - the index at which the items have been added.

onItemsCleared

public void onItemsCleared(List<M> oldList)
Description copied from interface: BindableListChangeHandler
Called when all items have been removed from the list.

Specified by:
onItemsCleared in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before all items were removed (equal to the old value of the list). Never null.

onItemRemovedAt

public void onItemRemovedAt(List<M> oldList,
                            int index)
Description copied from interface: BindableListChangeHandler
Called when a single item has been removed from the list at the provided index.

Specified by:
onItemRemovedAt in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the item was removed (equal to the old value of the list). Never null.
index - the index at which the item has been removed.

onItemsRemovedAt

public void onItemsRemovedAt(List<M> oldList,
                             List<Integer> indexes)
Description copied from interface: BindableListChangeHandler
Called when multiple items have been removed from the list.

Specified by:
onItemsRemovedAt in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the items were removed (equal to the old value of the list). Never null.

onItemChanged

public void onItemChanged(List<M> oldList,
                          int index,
                          M item)
Description copied from interface: BindableListChangeHandler
Called when a single item has been changed.

Specified by:
onItemChanged in interface BindableListChangeHandler<M>
Parameters:
oldList - a list representing the state before the item was changed (equal to the old value of the list). Never null.
index - the index of the item that has changed.
item - the new value of the item at the provided index.

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.