org.salespointframework.desktop.models
Class CountingStockListModel

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

public class CountingStockListModel
extends javax.swing.AbstractListModel
implements StockChangeListener, CatalogChangeListener, java.beans.PropertyChangeListener, HelpableListener, FilterableModel

ListModel for CountingStocks

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

Nested Class Summary
static class CountingStockListModel.CountingStockListItem
          casing class for list items
 
Nested classes/interfaces inherited from interface org.salespointframework.desktop.models.FilterableModel
FilterableModel.DefaultModelFilter, FilterableModel.ModelFilter, FilterableModel.ResultCountListener
 
Field Summary
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
          actual item list. also contains categories
protected  FilterableModel.ModelFilter modelFilter
          model filter
protected  java.util.List<FilterableModel.ResultCountListener> resultCountListeners
          result count listener list
protected  boolean showZeros
          true, if zero count items should be displayed
protected  CountingStock<?,?> stock
          CountingStock source
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
CountingStockListModel(CountingStock<StockItem,CatalogItem> stock, DataBasket db, java.util.Comparator<CatalogItem> cmp, boolean showZeros)
          constructor
CountingStockListModel(CountingStock<StockItem,CatalogItem> stock, DataBasket db, java.util.Comparator<CatalogItem> cmp, boolean showZeros, boolean categorize, Category defaultCategory)
          constructor
 
Method Summary
 void addedCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void addedStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 boolean addResultCountListener(FilterableModel.ResultCountListener rcs)
          add new ResultCountListener
 void canEditCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void canEditStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void canRemoveCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void canRemoveStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
protected  void checkAdd(java.lang.String sKey)
          Internal helper method.
protected  void checkRemove(java.lang.String sKey)
          Internal helper method.
protected  void checkUpdate(java.lang.String sKey)
          Internal helper method.
 void commitAddStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void commitedAddCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void commitEditCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void commitEditStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void commitedRemoveCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void commitRemoveStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void DatasourceChanged(boolean pumpUp)
          The Datasource changed.
 void editingCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void editingStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void filterPropertyChanged()
          apply new filter an reload items
private  void fireResultCountChanged(int count)
          trigger result count changed event
 java.lang.Object getElementAt(int index)
          get element at index
private  int getKeyIndex(java.lang.String key)
          translates key to index
 int getSize()
          get list size
protected  boolean isFirstInCategory(int index)
           
 void noEditCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void noEditStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void noRemoveCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void noRemoveStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void removedCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void removedStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void removeResultCountListener(FilterableModel.ResultCountListener rcs)
          remove ResultCountListener
 void rollbackAddStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void rollbackEditCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void rollbackEditStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void rollbackRemoveStockItems(StockChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void rolledbackAddCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void rolledbackRemoveCatalogItem(CatalogChangeEvent e)
          Update the internal model and inform any listeners according to the received event.
 void setModelFilter(FilterableModel.ModelFilter modelFilter)
          sets a new ModelFilter and applies it
 void subscribe()
          Subscribe as a listener to the model.
 void unsubscribe()
          Un-Subscribe as a listener from the model.
 void updateModel()
          Update the internal model based on the modeled CountingStock.
 
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

stock

protected CountingStock<?,?> stock
CountingStock source


db

protected DataBasket db
databasket used for visibility


cmp

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


showZeros

protected boolean showZeros
true, if zero count items should be displayed


keys

protected java.util.List<java.lang.Object> keys
actual item list. also contains categories


resultCountListeners

protected java.util.List<FilterableModel.ResultCountListener> resultCountListeners
result count listener list


modelFilter

protected FilterableModel.ModelFilter modelFilter
model filter


categorize

protected boolean categorize
true, if categories should be displayed


defaultCategory

protected Category defaultCategory
category used for items without category

Constructor Detail

CountingStockListModel

public CountingStockListModel(CountingStock<StockItem,CatalogItem> stock,
                              DataBasket db,
                              java.util.Comparator<CatalogItem> cmp,
                              boolean showZeros)
constructor

Parameters:
stock - stock
db - db
cmp - cmp. null for default
showZeros - showZeros

CountingStockListModel

public CountingStockListModel(CountingStock<StockItem,CatalogItem> stock,
                              DataBasket db,
                              java.util.Comparator<CatalogItem> cmp,
                              boolean showZeros,
                              boolean categorize,
                              Category defaultCategory)
constructor

Parameters:
stock - stock
db - db
cmp - cmp. null for default
showZeros - showZeros
categorize - categorize
defaultCategory - defaultCategory. null for default
Method Detail

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 list size

Specified by:
getSize in interface javax.swing.ListModel

subscribe

public void subscribe()
Subscribe as a listener to the model. If the modelled Catalog is a ListenableCatalog, subscribe as a listener. If the modelled CountingStock is a ListenableStock, subscribe as a listener.

Specified by:
subscribe in interface HelpableListener

unsubscribe

public void unsubscribe()
Un-Subscribe as a listener from the model. If the modelled Catalog is a ListenableCatalog, un-subscribe as a listener. If the modelled CountingStock is a ListenableStock, un-subscribe as a listener.

Specified by:
unsubscribe in interface HelpableListener

isFirstInCategory

protected boolean isFirstInCategory(int index)

updateModel

public void updateModel()
Update the internal model based on the modeled CountingStock.

Specified by:
updateModel in interface HelpableListener

addedStockItems

public void addedStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
addedStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

commitAddStockItems

public void commitAddStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
commitAddStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

rollbackAddStockItems

public void rollbackAddStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
rollbackAddStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

canRemoveStockItems

public void canRemoveStockItems(StockChangeEvent e)
                         throws VetoException
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
canRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the removal.

noRemoveStockItems

public void noRemoveStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
noRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

removedStockItems

public void removedStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
removedStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

commitRemoveStockItems

public void commitRemoveStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
commitRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

rollbackRemoveStockItems

public void rollbackRemoveStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
rollbackRemoveStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

canEditStockItems

public void canEditStockItems(StockChangeEvent e)
                       throws VetoException
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
canEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the editing.

noEditStockItems

public void noEditStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
noEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

editingStockItems

public void editingStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
editingStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

commitEditStockItems

public void commitEditStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
commitEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

rollbackEditStockItems

public void rollbackEditStockItems(StockChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
rollbackEditStockItems in interface StockChangeListener
Parameters:
e - an event object describing the event.

addedCatalogItem

public void addedCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
addedCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

commitedAddCatalogItem

public void commitedAddCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
commitedAddCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

rolledbackAddCatalogItem

public void rolledbackAddCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
rolledbackAddCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

canRemoveCatalogItem

public void canRemoveCatalogItem(CatalogChangeEvent e)
                          throws VetoException
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
canRemoveCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the removal.

noRemoveCatalogItem

public void noRemoveCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
noRemoveCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

removedCatalogItem

public void removedCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
removedCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

commitedRemoveCatalogItem

public void commitedRemoveCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
commitedRemoveCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

rolledbackRemoveCatalogItem

public void rolledbackRemoveCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
rolledbackRemoveCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

canEditCatalogItem

public void canEditCatalogItem(CatalogChangeEvent e)
                        throws VetoException
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
canEditCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the editing.

noEditCatalogItem

public void noEditCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
noEditCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

editingCatalogItem

public void editingCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

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

commitEditCatalogItem

public void commitEditCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
commitEditCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

rollbackEditCatalogItem

public void rollbackEditCatalogItem(CatalogChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
rollbackEditCatalogItem in interface CatalogChangeListener
Parameters:
e - an event object describing the event.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Update the internal model and inform any listeners according to the received event.

This method is public as an implementation detail and must not be called directly.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getKeyIndex

private int getKeyIndex(java.lang.String key)
translates key to index

Parameters:
key -
Returns:
index position or -1

checkAdd

protected void checkAdd(java.lang.String sKey)
Internal helper method. Check where, if at all, the given CatalogItem has been added with respect to the internal model.

Parameters:
sKey - the key of the added CatalogItem

checkRemove

protected void checkRemove(java.lang.String sKey)
Internal helper method. Check from where, if at all, the given CatalogItem has been removed with respect to the internal model.

Parameters:
sKey - the key of the removed CatalogItem

checkUpdate

protected void checkUpdate(java.lang.String sKey)
Internal helper method. Check for updates in the given CatalogItem.

Parameters:
sKey - the key of the updated CatalogItem

DatasourceChanged

public void DatasourceChanged(boolean pumpUp)
The Datasource changed. Invalidate internal structures and pump up event

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

fireResultCountChanged

private void fireResultCountChanged(int count)
trigger result count changed event

Parameters:
count - new count

addResultCountListener

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

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

filterPropertyChanged

public void filterPropertyChanged()
apply new filter an reload items

Specified by:
filterPropertyChanged in interface FilterableModel

removeResultCountListener

public void removeResultCountListener(FilterableModel.ResultCountListener rcs)
remove ResultCountListener

Specified by:
removeResultCountListener in interface FilterableModel

setModelFilter

public void setModelFilter(FilterableModel.ModelFilter modelFilter)
sets a new ModelFilter and applies it

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