org.salespointframework.desktop.models
Class CatalogListModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by org.salespointframework.desktop.models.CatalogListModel
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.ListModel, CatalogChangeListener<CatalogItem>, DatasourceChangeListener, HelpableListener, FilterableModel

public class CatalogListModel
extends javax.swing.AbstractListModel
implements CatalogChangeListener<CatalogItem>, java.beans.PropertyChangeListener, HelpableListener, FilterableModel

ListModel for Catalogs

Since:
4.0
Author:
Thomas Kissinger
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.salespointframework.desktop.models.FilterableModel
FilterableModel.DefaultModelFilter, FilterableModel.ModelFilter, FilterableModel.ResultCountListener
 
Field Summary
protected  Catalog catalog
          catalog source
protected  boolean categorize
          true, if categories should be displayed
protected  java.util.Comparator<CatalogItem> cmp
          comparator for sorting
protected  DataBasket db
          databasket used for visibility
protected  Category defaultCategory
          category used for items without category
protected  java.util.List<java.lang.Object> keys
          processed source content. also contains Categorys
protected  FilterableModel.ModelFilter modelFilter
          applied model filter
protected  java.util.List<FilterableModel.ResultCountListener> resultCountListeners
           
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
CatalogListModel(Catalog c, DataBasket db, java.util.Comparator<CatalogItem> cmp)
          constructor
CatalogListModel(Catalog c, DataBasket db, java.util.Comparator<CatalogItem> cmp, boolean categorize, Category defaultCategory)
          constructor
 
Method Summary
 void addedCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever a CatalogItem was added to the Catalog.
 boolean addResultCountListener(FilterableModel.ResultCountListener rcs)
          add a ResultCountListener
 void canEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called to ask whether a CatalogItem may be edited.
 void canRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called to ask whether a CatalogItem may be removed.
protected  void checkAdd(CatalogItem ci)
           
protected  void checkRemove(CatalogItem ci)
           
protected  void checkUpdate(CatalogItem ci)
           
 void commitedAddCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever the adding of a CatalogItem was commited.
 void commitEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever editing a CatalogItem was commited.
 void commitedRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever the removal of a CatalogItem was commited.
 void DatasourceChanged(boolean pumpUp)
          datasource changed. reload all items
 void editingCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever editing a CatalogItem was started.
 void filterPropertyChanged()
          apply new filter and reload items
protected  void fireResultCountChanged(int count)
          trigger result count changed event to all registered listeners
 java.lang.Object getElementAt(int index)
          get element at index
 int getSize()
          get element count
protected  boolean isFirstInCategory(int index)
          checks if the index is the first in category
 void noEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
          z Called for each listener that already agreed with an editing that was then rejected by another listener.
 void noRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called for each listener that already agreed with a removal that was then rejected by another listener.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 void removedCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever a CatalogItem was removed from the Catalog.
 void removeResultCountListener(FilterableModel.ResultCountListener rcs)
          remove a ResultCountListener
 void rollbackEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever editing a CatalogItem was rolled back.
 void rolledbackAddCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever the adding of a CatalogItem was rolled back.
 void rolledbackRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
          Called whenever the removal of a CatalogItem was rolled back.
 void setModelFilter(FilterableModel.ModelFilter modelFilter)
          set ModelFilter and apply it
 void subscribe()
          Called when the listener should subscribe to its own event source.
 void unsubscribe()
          Called when the listener should unsubscribe from its own event source.
 void updateModel()
          updates the model and applies filters, ordering and categories
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

catalog

protected Catalog catalog
catalog source


db

protected DataBasket db
databasket used for visibility


cmp

protected java.util.Comparator<CatalogItem> cmp
comparator for sorting


keys

protected java.util.List<java.lang.Object> keys
processed source content. also contains Categorys


resultCountListeners

protected java.util.List<FilterableModel.ResultCountListener> resultCountListeners

modelFilter

protected FilterableModel.ModelFilter modelFilter
applied model filter


categorize

protected boolean categorize
true, if categories should be displayed


defaultCategory

protected Category defaultCategory
category used for items without category

Constructor Detail

CatalogListModel

public CatalogListModel(Catalog c,
                        DataBasket db,
                        java.util.Comparator<CatalogItem> cmp)
constructor

Parameters:
c - catalog
db - db
cmp - cmp. null for default comparator

CatalogListModel

public CatalogListModel(Catalog c,
                        DataBasket db,
                        java.util.Comparator<CatalogItem> cmp,
                        boolean categorize,
                        Category defaultCategory)
constructor

Parameters:
c - catalog
db - db
cmp - cmp. null for default comparator
categorize - categorize
defaultCategory - defaultCategory. null for default.
Method Detail

addedCatalogItem

public void addedCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever a CatalogItem was added to the Catalog.

Specified by:
addedCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.addedCatalogItem(CatalogChangeEvent)

canEditCatalogItem

public void canEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
                        throws VetoException
Description copied from interface: CatalogChangeListener
Called to ask whether a CatalogItem may be edited. If one of the listeners vetos the editing, all steners that had already been asked will receive a noEditCatalogItem event.

Specified by:
canEditCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the editing.
See Also:
CatalogTableModel.canEditCatalogItem(CatalogChangeEvent)

canRemoveCatalogItem

public void canRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
                          throws VetoException
Description copied from interface: CatalogChangeListener
Called to ask whether a CatalogItem may be removed. If one of the listeners vetos the removal, all listeners that had already been asked will receive a noRemoveCatalogItem event.

Specified by:
canRemoveCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the removal.
See Also:
CatalogTableModel.canRemoveCatalogItem(CatalogChangeEvent)

commitEditCatalogItem

public void commitEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever editing a CatalogItem was commited.

Specified by:
commitEditCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.commitEditCatalogItem(CatalogChangeEvent)

commitedAddCatalogItem

public void commitedAddCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever the adding of a CatalogItem was commited.

Specified by:
commitedAddCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.commitedAddCatalogItem(CatalogChangeEvent)

commitedRemoveCatalogItem

public void commitedRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever the removal of a CatalogItem was commited.

Specified by:
commitedRemoveCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.commitedRemoveCatalogItem(CatalogChangeEvent)

editingCatalogItem

public void editingCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever editing a CatalogItem was started. This event may be accompanied by a removedCatalogItem and a addedCatalogItem event, but this is implementation specific.

Specified by:
editingCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.

noEditCatalogItem

public void noEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
z Called for each listener that already agreed with an editing that was then rejected by another listener.

Specified by:
noEditCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.noEditCatalogItem(CatalogChangeEvent)

noRemoveCatalogItem

public void noRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called for each listener that already agreed with a removal that was then rejected by another listener.

Specified by:
noRemoveCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.noRemoveCatalogItem(CatalogChangeEvent)

removedCatalogItem

public void removedCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever a CatalogItem was removed from the Catalog.

Specified by:
removedCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.removedCatalogItem(CatalogChangeEvent)

rollbackEditCatalogItem

public void rollbackEditCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever editing a CatalogItem was rolled back.

Specified by:
rollbackEditCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.rollbackEditCatalogItem(CatalogChangeEvent)

rolledbackAddCatalogItem

public void rolledbackAddCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever the adding of a CatalogItem was rolled back.

Specified by:
rolledbackAddCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.rolledbackAddCatalogItem(CatalogChangeEvent)

rolledbackRemoveCatalogItem

public void rolledbackRemoveCatalogItem(CatalogChangeEvent<CatalogItem> e)
Description copied from interface: CatalogChangeListener
Called whenever the removal of a CatalogItem was rolled back.

Specified by:
rolledbackRemoveCatalogItem in interface CatalogChangeListener<CatalogItem>
Parameters:
e - an event object describing the event.
See Also:
CatalogTableModel.rolledbackRemoveCatalogItem(CatalogChangeEvent)

DatasourceChanged

public void DatasourceChanged(boolean pumpUp)
datasource changed. reload all items

Specified by:
DatasourceChanged in interface DatasourceChangeListener
Parameters:
pumpUp - true if the event should be pumped up to hosts, because this event is mostly triggered twice. first time to invalidate caches. second time for load new data

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
See Also:
CatalogTableModel.propertyChange(PropertyChangeEvent)

getElementAt

public java.lang.Object getElementAt(int index)
get element at index

Specified by:
getElementAt in interface javax.swing.ListModel

getSize

public int getSize()
get element count

Specified by:
getSize in interface javax.swing.ListModel

subscribe

public void subscribe()
Description copied from interface: HelpableListener
Called when the listener should subscribe to its own event source.

Specified by:
subscribe in interface HelpableListener
See Also:
CatalogTableModel.subscribe()

unsubscribe

public void unsubscribe()
Description copied from interface: HelpableListener
Called when the listener should unsubscribe from its own event source.

Specified by:
unsubscribe in interface HelpableListener
See Also:
CatalogTableModel.unsubscribe()

updateModel

public void updateModel()
updates the model and applies filters, ordering and categories

Specified by:
updateModel in interface HelpableListener

isFirstInCategory

protected boolean isFirstInCategory(int index)
checks if the index is the first in category

Parameters:
index -
Returns:
true, if is first

checkAdd

protected void checkAdd(CatalogItem ci)
See Also:
CatalogTableModel.checkAdd(CatalogItem)

checkRemove

protected void checkRemove(CatalogItem ci)
See Also:
CatalogTableModel.checkRemove(CatalogItem)

checkUpdate

protected void checkUpdate(CatalogItem ci)
See Also:
CatalogTableModel.checkUpdate(CatalogItem)

addResultCountListener

public boolean addResultCountListener(FilterableModel.ResultCountListener rcs)
add a ResultCountListener

Specified by:
addResultCountListener in interface FilterableModel
Returns:
true, on success

filterPropertyChanged

public void filterPropertyChanged()
apply new filter and reload items

Specified by:
filterPropertyChanged in interface FilterableModel

removeResultCountListener

public void removeResultCountListener(FilterableModel.ResultCountListener rcs)
remove a ResultCountListener

Specified by:
removeResultCountListener in interface FilterableModel

setModelFilter

public void setModelFilter(FilterableModel.ModelFilter modelFilter)
set ModelFilter and apply it

Specified by:
setModelFilter in interface FilterableModel
Parameters:
modelFilter - new model filter

fireResultCountChanged

protected void fireResultCountChanged(int count)
trigger result count changed event to all registered listeners

Parameters:
count - new count