to.etc.domui.component.tbl
Class KeySelectionModel<T,K>

java.lang.Object
  extended by to.etc.domui.component.tbl.AbstractSelectionModel<T>
      extended by to.etc.domui.component.tbl.KeySelectionModel<T,K>
Type Parameters:
T - The instance type
K - The key type
All Implemented Interfaces:
ISelectionModel<T>

public class KeySelectionModel<T,K>
extends AbstractSelectionModel<T>

Example implementation of a simple selection model, retaining only the instances key.

Author:
Frits Jalvingh Created on Feb 15, 2011

Constructor Summary
KeySelectionModel(boolean multiSelect)
           
KeySelectionModel(boolean multiSelect, boolean retainInstances)
          Constructor.
 
Method Summary
 void clearSelection()
          Clear all selections, then call the listeners to report the change.
 K getKey(T rowinstance)
          This must return the unique key K for an instance.
 java.util.List<T> getSelectedInstances()
           
 java.util.Set<K> getSelectedKeys()
           
 int getSelectionCount()
          Return the #of instances currently selected.
 boolean isMultiSelect()
          T if this model can handle multiple selections.
 boolean isSelected(T rowinstance)
          Return T if this instance is actually selected.
 void selectAll(ITableModel<T> in)
          This must add all (recoverable) items in the model and add them as selected as efficiently as possible.
 void setInstanceSelected(T rowinstance, boolean on)
          Set or clear an instance's selected state.
 
Methods inherited from class to.etc.domui.component.tbl.AbstractSelectionModel
addListener, callChanged, callSelectionAllChanged, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeySelectionModel

public KeySelectionModel(boolean multiSelect,
                         boolean retainInstances)
Constructor.

Parameters:
retainInstances - Set T in case that model should collect instancies. For lightweight use, set F in case that collecting PKs is sufficient.

KeySelectionModel

public KeySelectionModel(boolean multiSelect)
Method Detail

isMultiSelect

public boolean isMultiSelect()
Description copied from interface: ISelectionModel
T if this model can handle multiple selections.

Returns:

isSelected

public boolean isSelected(@Nonnull
                          T rowinstance)
Description copied from interface: ISelectionModel
Return T if this instance is actually selected.

Returns:

getKey

public K getKey(@Nonnull
                T rowinstance)
This must return the unique key K for an instance. By default, if the instance implements IIdentifyable<K> it will use that to retrieve the key; if that is not possible you must override this method.

Parameters:
rowinstance -
Returns:

getSelectionCount

public int getSelectionCount()
Description copied from interface: ISelectionModel
Return the #of instances currently selected.

Returns:

setInstanceSelected

public void setInstanceSelected(@Nonnull
                                T rowinstance,
                                boolean on)
                         throws java.lang.Exception
Description copied from interface: ISelectionModel
Set or clear an instance's selected state. When changed the model will call the listeners to report the change.

Throws:
java.lang.Exception

clearSelection

public void clearSelection()
                    throws java.lang.Exception
Description copied from interface: ISelectionModel
Clear all selections, then call the listeners to report the change.

Throws:
java.lang.Exception

selectAll

public void selectAll(ITableModel<T> in)
               throws java.lang.Exception
Description copied from interface: ISelectionModel
This must add all (recoverable) items in the model and add them as selected as efficiently as possible. It is NEVER called directly, but always through a ISelectionAllHandler, so that "select all" can be forbidden.

Throws:
java.lang.Exception

getSelectedInstances

public java.util.List<T> getSelectedInstances()

getSelectedKeys

public java.util.Set<K> getSelectedKeys()