org.granite.client.tide.collections
Class AbstractPagedCollection<E>

java.lang.Object
  extended by org.granite.client.tide.collections.AbstractPagedCollection<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, TideEventObserver
Direct Known Subclasses:
PagedCollection

public abstract class AbstractPagedCollection<E>
extends Object
implements List<E>, TideEventObserver

Author:
William DRAI

Nested Class Summary
 class AbstractPagedCollection.PagedCollectionIterator
           
 class AbstractPagedCollection.PagedCollectionResponder
           
 
Field Summary
protected  int count
           
protected  boolean filterRefresh
           
protected  int first
           
protected  boolean fullRefresh
           
protected  boolean initializing
           
protected  int last
           
protected  int max
           
 
Constructor Summary
AbstractPagedCollection()
           
 
Method Summary
 boolean add(E e)
           
 void add(int index, E element)
           
 boolean addAll(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void clear()
          Clear collection content
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
protected  void find(int first, int last)
          Abstract method: trigger a results query for the current filter
protected  void findFault(TideFaultEvent event, int first, int max)
           
protected  void findResult(TideResultEvent<?> event, int first, int max)
           
protected abstract  void firePageChange(TideRpcEvent event)
          Notify listeners of remote page result
 boolean fullRefresh()
          Force refresh of collection when filter/sort have been changed
 E get(int index)
          Override of getItemAt with ItemPendingError management
protected abstract  List<E> getInternalWrappedList()
           
protected abstract  org.granite.tide.data.model.Page<E> getResult(TideResultEvent<?> event, int first, int max)
          Build a result object from the result event
protected abstract  List<E> getWrappedList()
           
 void handleEvent(TideEvent event)
           
protected  void handleFault(TideFaultEvent event)
           
protected  void handleResult(org.granite.tide.data.model.Page<E> page, TideResultEvent<?> event, int first, int max)
           
 int indexOf(Object o)
           
protected  void initialize(TideResultEvent<?> event)
           
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator<E> listIterator()
           
 ListIterator<E> listIterator(int index)
           
 boolean refresh()
          Refresh collection with new filter/sort parameters
 E remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 E set(int index, E element)
           
 void setElementClass(Class<? extends E> elementClass)
           
 void setMaxResults(int max)
          Set the page size.
 int size()
          Get total number of elements
 List<E> subList(int fromIndex, int toIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode, toArray, toArray
 

Field Detail

initializing

protected boolean initializing

first

protected int first

last

protected int last

max

protected int max

count

protected int count

fullRefresh

protected boolean fullRefresh

filterRefresh

protected boolean filterRefresh
Constructor Detail

AbstractPagedCollection

public AbstractPagedCollection()
Method Detail

size

public int size()
Get total number of elements

Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Returns:
collection total length

setMaxResults

public void setMaxResults(int max)
Set the page size. The collection will store in memory twice this page size, and each server call will return at most the page size.

Parameters:
max - maximum number of requested elements

setElementClass

public void setElementClass(Class<? extends E> elementClass)

handleEvent

public void handleEvent(TideEvent event)
Specified by:
handleEvent in interface TideEventObserver

clear

@PreDestroy
public void clear()
Clear collection content

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>

find

protected void find(int first,
                    int last)
Abstract method: trigger a results query for the current filter

Parameters:
first - : index of first required result
last - : index of last required result

fullRefresh

public boolean fullRefresh()
Force refresh of collection when filter/sort have been changed

Returns:
always false

refresh

public boolean refresh()
Refresh collection with new filter/sort parameters

Returns:
always false

getResult

protected abstract org.granite.tide.data.model.Page<E> getResult(TideResultEvent<?> event,
                                                                 int first,
                                                                 int max)
Build a result object from the result event

Parameters:
event - the result event
first - first index requested
max - max elements requested
Returns:
an object containing data from the collection resultList : the retrieved data resultCount : the total count of elements (non paged) firstResult : the index of the first retrieved element maxResults : the maximum count of retrieved elements

firePageChange

protected abstract void firePageChange(TideRpcEvent event)
Notify listeners of remote page result

Parameters:
event - the remote event (ResultEvent or FaultEvent)

initialize

protected void initialize(TideResultEvent<?> event)
Parameters:
the - result event of the first find

findResult

protected void findResult(TideResultEvent<?> event,
                          int first,
                          int max)
Parameters:
event - the result event
first - first requested index
max - max elements requested

handleResult

protected void handleResult(org.granite.tide.data.model.Page<E> page,
                            TideResultEvent<?> event,
                            int first,
                            int max)
Parameters:
result - the result object
event - the result event

findFault

protected void findFault(TideFaultEvent event,
                         int first,
                         int max)
Parameters:
event - the fault event
first - first requested index
max - max elements requested

handleFault

protected void handleFault(TideFaultEvent event)
Parameters:
event - the fault event

getInternalWrappedList

protected abstract List<E> getInternalWrappedList()

getWrappedList

protected abstract List<E> getWrappedList()

get

public E get(int index)
Override of getItemAt with ItemPendingError management

Specified by:
get in interface List<E>
Parameters:
index - index of requested item
prefetch - not used
Returns:
object at specified index

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface List<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface List<E>

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<E>

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List<E>

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface List<E>

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E>

listIterator

public ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface List<E>

add

public boolean add(E e)
Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>

add

public void add(int index,
                E element)
Specified by:
add in interface List<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>

remove

public E remove(int index)
Specified by:
remove in interface List<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface List<E>

set

public E set(int index,
             E element)
Specified by:
set in interface List<E>

subList

public List<E> subList(int fromIndex,
                       int toIndex)
Specified by:
subList in interface List<E>