it.amattioli.applicate.browsing
Class ListBrowserImpl<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>

Show UML class diagram
java.lang.Object
  extended by it.amattioli.applicate.browsing.ListBrowserImpl<I,T>
Type Parameters:
I - Identifier class for the browsing entities
T - class of the browsing entities
All Implemented Interfaces:
Browser<I,T>, ListBrowser<I,T>, CommandListener, Selector<T>, it.amattioli.dominate.util.PropertyChangeEmitter, EventListener
Direct Known Subclasses:
MultiBrowser, PagedListBrowserImpl

public class ListBrowserImpl<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
extends Object
implements ListBrowser<I,T>, it.amattioli.dominate.util.PropertyChangeEmitter

Standard implementation of the ListBrowser interface.

Author:
andrea

Field Summary
protected  List<T> content
           
protected  Integer selectedIndex
           
 
Constructor Summary
protected ListBrowserImpl()
          Create a new ListBrowser.
  ListBrowserImpl(Class<T> entityClass)
          Create a new repository given the class of the browsing entities.
  ListBrowserImpl(it.amattioli.dominate.Repository<I,T> repository)
          Create a new ListBrowser given the repository that contains the browsing entities.
 
Method Summary
protected  void addCommandListener(CommandListener listener)
           
protected  void addCommandListener(CommandListener listener, CommandResult... results)
           
 void addContentChangeListener(ContentChangeListener listener)
          Add a listener for events fired when the browser content changes.
 void addOrder(String property)
          Add a property that will be used to sort the browsing objects.
 void addOrder(String property, boolean reverse)
           
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a listener for PropertyChangeEvent events.
 void addSelectionListener(SelectionListener listener)
          Register a listener for the object selection.
 void commandDone(CommandEvent source)
          This method will be called every time a CommandEvent is fired by the command to which this listener has been added.
static
<J extends Serializable,Q extends it.amattioli.dominate.Entity<J>>
ListBrowserImpl<J,Q>
createFor(Class<Q> entityClass)
          Factory method that creates a new repository given the class of the browsing entities.
static
<J extends Serializable,Q extends it.amattioli.dominate.Entity<J>>
ListBrowserImpl<J,Q>
createFor(it.amattioli.dominate.Repository<J,Q> repository)
          Factory method that creates a new ListBrowser given the repository that contains the browsing entities.
 void deselect()
          Removes the current selection.
 void fillCollection(Collection<? super T> toBeFilled)
          Fill a collection with the browsing objects.
protected  void fireCommandEvent(CommandEvent source)
           
protected  void fireContentChange()
           
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
           
 it.amattioli.dominate.Filter getFilter()
          Retrieves the filter object set by ListBrowser.setFilter(Filter).
 boolean getHasNext()
          Indicate if there is an object next to the currently selected object.
 boolean getHasPrevious()
          Indicate if there is an object previous to the currently selected object.
 List<T> getList()
          Retrieves the list of the browsing objects.
 String getOrderProperty()
          Retrieves the name of the property of the browsing objects that will be used to sort the list of browsing objects.
protected  it.amattioli.dominate.Repository<I,T> getRepository()
           
 boolean getReverseOrder()
          Indicates if the order is direct or reverse.
 Integer getSelectedIndex()
          Retrieves the index of the object currently selected.
 T getSelectedObject()
          Retrieves the object currently selected.
 ObjectBrowser<I,T> getSelectedObjectBrowser()
          Retrieves a ObjectBrowser for the selected object.
 it.amattioli.dominate.Specification<T> getSpecification()
          Retrieves the specification object set by ListBrowser.setSpecification(Specification)
protected  void invalidateContent()
           
 boolean isEmptyList()
           
protected  boolean isValidContent()
           
protected  boolean isValidSelectionIndex(Integer index)
           
 ObjectBrowser<I,T> newObjectBrowser()
          Create a new ObjectBrowser for the currently selected object.
 void next()
          Move the selection to the object next to the currently selected object.
 void previous()
          Move the selection to the object previous to the currently selected object.
protected  void refreshContent()
           
protected  T refreshObject(int index)
           
 void release()
          Releases eventually acquired resources.
 void removeContentChangeListener(ContentChangeListener listener)
          Remove a listener for events fired when the browser content changes.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a listener for PropertyChangeEvent events.
 void removeSelectionListener(SelectionListener listener)
          Remove a listener from the collection of the listeners that will be notified when an object is slected in this browser.
 void select(int index)
          Select an object using its index inside the list retrieved using ListBrowser.getList().
 void select(Integer index)
           
 void select(T object)
          Select an object.
 void setFilter(it.amattioli.dominate.Filter filter)
          Set the criteria to be used to filter the browsing objects.
 void setOrder(String property)
          Set the property that will be used to sort the browsing objects.
 void setOrder(String property, boolean reverse)
          Set the property that will be used to sort the browsing objects.
protected  void setRepository(it.amattioli.dominate.Repository<I,T> repository)
           
 void setSpecification(it.amattioli.dominate.Specification<T> spec)
          Set the specification to be used to filter the browsing objects.
 String toString()
           
 void useObjectBrowserClass(Class<? extends ObjectBrowserImpl<I,T>> placeHolderClass)
          Set the class that will be used by ListBrowser.newObjectBrowser().
protected  void validateContent()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

content

protected List<T extends it.amattioli.dominate.Entity<I>> content

selectedIndex

protected Integer selectedIndex
Constructor Detail

ListBrowserImpl

protected ListBrowserImpl()
Create a new ListBrowser. Before using it a repository must be set using setRepository(Repository)


ListBrowserImpl

public ListBrowserImpl(it.amattioli.dominate.Repository<I,T> repository)
Create a new ListBrowser given the repository that contains the browsing entities.

Parameters:
repository - the repository that contains the browsing entities

ListBrowserImpl

public ListBrowserImpl(Class<T> entityClass)
Create a new repository given the class of the browsing entities.

Parameters:
entityClass - the class of the browsing entities
Method Detail

createFor

public static <J extends Serializable,Q extends it.amattioli.dominate.Entity<J>> ListBrowserImpl<J,Q> createFor(Class<Q> entityClass)
Factory method that creates a new repository given the class of the browsing entities.

Parameters:
entityClass - the class of the browsing entities

createFor

public static <J extends Serializable,Q extends it.amattioli.dominate.Entity<J>> ListBrowserImpl<J,Q> createFor(it.amattioli.dominate.Repository<J,Q> repository)
Factory method that creates a new ListBrowser given the repository that contains the browsing entities.

Parameters:
repository - the repository that contains the browsing entities

getRepository

protected it.amattioli.dominate.Repository<I,T> getRepository()

setRepository

protected void setRepository(it.amattioli.dominate.Repository<I,T> repository)

invalidateContent

protected void invalidateContent()

isValidContent

protected boolean isValidContent()

validateContent

protected void validateContent()

refreshContent

protected void refreshContent()

fillCollection

public void fillCollection(Collection<? super T> toBeFilled)
Description copied from interface: ListBrowser
Fill a collection with the browsing objects. The parameter collection will be filled with the same objects that will be returned by ListBrowser.getList().

Specified by:
fillCollection in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
toBeFilled - the collection to be filled

getList

public List<T> getList()
Description copied from interface: ListBrowser
Retrieves the list of the browsing objects. This list will be the content of the repository on which this browser is based, filtered using the criteria specified by setCriteria. The list will be sorted using the property specified by setOrder. If something causes the changing of the list of browsing objects a PropertyChange event will be fired.

Specified by:
getList in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
the list of the browsing objects

isEmptyList

public boolean isEmptyList()

setFilter

public void setFilter(it.amattioli.dominate.Filter filter)
Description copied from interface: ListBrowser
Set the criteria to be used to filter the browsing objects. The ListBrowser.getList() method will return only the objects that satisfy the specified criteria. The browser will listen on property changes of the filter bean so to refresh the browsing objects accordingly.

Specified by:
setFilter in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
filter - the criteria that will be used to filter the browsing objects

getFilter

public it.amattioli.dominate.Filter getFilter()
Description copied from interface: ListBrowser
Retrieves the filter object set by ListBrowser.setFilter(Filter).

Specified by:
getFilter in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
the filter object set by ListBrowser.setFilter(Filter)

getSpecification

public it.amattioli.dominate.Specification<T> getSpecification()
Description copied from interface: ListBrowser
Retrieves the specification object set by ListBrowser.setSpecification(Specification)

Specified by:
getSpecification in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
the specification object set by ListBrowser.setSpecification(Specification)

setSpecification

public void setSpecification(it.amattioli.dominate.Specification<T> spec)
Description copied from interface: ListBrowser
Set the specification to be used to filter the browsing objects. The ListBrowser.getList() method will return only the objects that satisfy the specification. The browser will listen on property changes of the specification bean so to refresh the browsing objects accordingly.

Specified by:
setSpecification in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
spec - the specification that will be used to filter the browsing objects

setOrder

public void setOrder(String property,
                     boolean reverse)
Description copied from interface: ListBrowser
Set the property that will be used to sort the browsing objects.

Specified by:
setOrder in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
property - the name of a property of the browsing objects that will be used to sort the list of browsing objects
reverse - if true the objects will be sort in reverse order

addOrder

public void addOrder(String property,
                     boolean reverse)

addOrder

public void addOrder(String property)
Description copied from interface: ListBrowser
Add a property that will be used to sort the browsing objects. If a previous order property was set it will remain in place and the new property will be added to the list.

Specified by:
addOrder in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>

setOrder

public void setOrder(String property)
Description copied from interface: ListBrowser
Set the property that will be used to sort the browsing objects. If this method is called more than one time with the same parameter the order will be reversed.

Specified by:
setOrder in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
property - the name of a property of the browsing objects that will be used to sort the list of browsing objects

getOrderProperty

public String getOrderProperty()
Description copied from interface: ListBrowser
Retrieves the name of the property of the browsing objects that will be used to sort the list of browsing objects.

Specified by:
getOrderProperty in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
the name of the property of the browsing objects that will be used to sort the list of browsing objects or null if no sorting property was set

getReverseOrder

public boolean getReverseOrder()
Description copied from interface: ListBrowser
Indicates if the order is direct or reverse.

Specified by:
getReverseOrder in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
true if the order is reversed

select

public void select(int index)
Description copied from interface: ListBrowser
Select an object using its index inside the list retrieved using ListBrowser.getList(). After the selection a SelectionEvent will be notified to all the objects that has been registered using #addContentChangeListener(BrowserSelectionListener).

Specified by:
select in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
index - the index inside the list retrieved using ListBrowser.getList() of the object to be selected

select

public void select(Integer index)

isValidSelectionIndex

protected boolean isValidSelectionIndex(Integer index)

select

public void select(T object)
Description copied from interface: ListBrowser
Select an object. After the selection a SelectionEvent will be notified to all the objects that has been registered using #addContentChangeListener(BrowserSelectionListener).

Specified by:
select in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
object - the object to be selected

deselect

public void deselect()
Description copied from interface: ListBrowser
Removes the current selection. After this every call to Selector.getSelectedObject() and ListBrowser.getSelectedIndex() will return null.

Specified by:
deselect in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>

refreshObject

protected T refreshObject(int index)

getSelectedObject

public T getSelectedObject()
Description copied from interface: Selector
Retrieves the object currently selected.

Specified by:
getSelectedObject in interface Selector<T extends it.amattioli.dominate.Entity<I>>
Returns:
the object currently selected or null if no object is selected

getSelectedIndex

public Integer getSelectedIndex()
Description copied from interface: ListBrowser
Retrieves the index of the object currently selected. It is the same number that must be used to select it using ListBrowser.select(int).

Specified by:
getSelectedIndex in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
the index of the object currently selected or null if no object is selected

next

public void next()
Description copied from interface: ListBrowser
Move the selection to the object next to the currently selected object. If the currently selected object is the last of the list, nothing will happen.

Specified by:
next in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>

getHasNext

public boolean getHasNext()
Description copied from interface: ListBrowser
Indicate if there is an object next to the currently selected object.

Specified by:
getHasNext in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
true if there is an object next to the currently selected object, false if the currently selected object is the last in the list

previous

public void previous()
Description copied from interface: ListBrowser
Move the selection to the object previous to the currently selected object. If the currently selected object is the first of the list, nothing will happen.

Specified by:
previous in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>

getHasPrevious

public boolean getHasPrevious()
Description copied from interface: ListBrowser
Indicate if there is an object previous to the currently selected object.

Specified by:
getHasPrevious in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
true if there is an object previous to the currently selected object, false if the currently selected object is the first in the list

commandDone

public void commandDone(CommandEvent source)
Description copied from interface: CommandListener
This method will be called every time a CommandEvent is fired by the command to which this listener has been added.

Specified by:
commandDone in interface CommandListener
Parameters:
source - the fired event

addCommandListener

protected void addCommandListener(CommandListener listener)

addCommandListener

protected void addCommandListener(CommandListener listener,
                                  CommandResult... results)

fireCommandEvent

protected void fireCommandEvent(CommandEvent source)

useObjectBrowserClass

public void useObjectBrowserClass(Class<? extends ObjectBrowserImpl<I,T>> placeHolderClass)
Description copied from interface: ListBrowser
Set the class that will be used by ListBrowser.newObjectBrowser().

Specified by:
useObjectBrowserClass in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
placeHolderClass - the class that will be used by ListBrowser.newObjectBrowser()

newObjectBrowser

public ObjectBrowser<I,T> newObjectBrowser()
Description copied from interface: ListBrowser
Create a new ObjectBrowser for the currently selected object. The object created will be an instance of the class set using ListBrowser.useObjectBrowserClass(Class). If no object browser class was specified ObjectBrowserImpl will be used.

Specified by:
newObjectBrowser in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
the new ObjectBrowser

getSelectedObjectBrowser

public ObjectBrowser<I,T> getSelectedObjectBrowser()
Description copied from interface: ListBrowser
Retrieves a ObjectBrowser for the selected object. This ObjectBrowser will be created the first time this method is called and will be linked to the currently selected object. Every time a new object is elected in the browser the ObjectBrowser will be notified so it can refresh itself to contain the currently slected object.

Specified by:
getSelectedObjectBrowser in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Returns:
a ObjectBrowser for the selected object

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: ListBrowser
Add a listener for PropertyChangeEvent events.

Specified by:
addPropertyChangeListener in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Specified by:
addPropertyChangeListener in interface it.amattioli.dominate.util.PropertyChangeEmitter
Parameters:
listener - a listener for PropertyChangeEvent events

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: ListBrowser
Remove a listener for PropertyChangeEvent events.

Specified by:
removePropertyChangeListener in interface ListBrowser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Specified by:
removePropertyChangeListener in interface it.amattioli.dominate.util.PropertyChangeEmitter
Parameters:
listener - a listener for PropertyChangeEvent events

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  Object newValue)

addSelectionListener

public void addSelectionListener(SelectionListener listener)
Description copied from interface: Selector
Register a listener for the object selection. Every time an object is selected in this browser all the registered objects will be notified.

Specified by:
addSelectionListener in interface Selector<T extends it.amattioli.dominate.Entity<I>>
Parameters:
listener - the listener to be registered

removeSelectionListener

public void removeSelectionListener(SelectionListener listener)
Description copied from interface: Selector
Remove a listener from the collection of the listeners that will be notified when an object is slected in this browser.

Specified by:
removeSelectionListener in interface Selector<T extends it.amattioli.dominate.Entity<I>>
Parameters:
listener - the listener to be removed

release

public void release()
Description copied from interface: Browser
Releases eventually acquired resources. After calling this method the browser can no longer be used.

Specified by:
release in interface Browser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>

addContentChangeListener

public void addContentChangeListener(ContentChangeListener listener)
Description copied from interface: Browser
Add a listener for events fired when the browser content changes.

Specified by:
addContentChangeListener in interface Browser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
listener - the listener to be added

removeContentChangeListener

public void removeContentChangeListener(ContentChangeListener listener)
Description copied from interface: Browser
Remove a listener for events fired when the browser content changes.

Specified by:
removeContentChangeListener in interface Browser<I extends Serializable,T extends it.amattioli.dominate.Entity<I>>
Parameters:
listener - the listener to be removed

fireContentChange

protected void fireContentChange()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.