SalesPoint v3.3 API

data.filters
Class CatalogFilter<T extends CatalogItem>

java.lang.Object
  extended by data.filters.CatalogFilter<T>
All Implemented Interfaces:
Catalog<T>, CatalogItem, DataBasketEntryDestination, DataBasketEntrySource, CatalogChangeListener<T>, ListenableCatalog<T>, Nameable, Serializable, Comparable<Object>, EventListener, HelpableListener
Direct Known Subclasses:
CurrencyFilter

public abstract class CatalogFilter<T extends CatalogItem>
extends Object
implements Catalog<T>, CatalogChangeListener<T>, ListenableCatalog<T>, HelpableListener

A filter for Catalogs.

CatalogFilters can be used to present partial views of a Catalog to parts of your application, e.g., GUI elements. However, you cannot use a CatalogFilter as a replacement for a 'real' Catalog, e.g., as an item in another Catalog.

The actual filter condition is defined by overriding method match(T).

Since:
v2.0
Author:
Steffen Zschaler
See Also:
Serialized Form

Field Summary
protected  Catalog<T> m_cOrg
          The Catalog that is being filtered.
protected  ListenerHelper m_lhListeners
          The listeners that listen for events from this Catalog.
 
Constructor Summary
CatalogFilter(Catalog<T> cOrg)
          Create a new CatalogFilter.
 
Method Summary
 void add(T ci, DataBasket db)
          Add the given item to the source Catalog.
 void addCatalogChangeListener(CatalogChangeListener ccl)
          Add a listener that wishes to receive events when the filtered Catalog changes.
 void addedCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void addNameListener(PropertyChangeListener pcl)
          Register the listener with the source Catalog.
 void addPropertyChangeListener(PropertyChangeListener pcl)
          Register the listener with the source Catalog.
 void addValueListener(PropertyChangeListener pcl)
          Register the listener with the source Catalog.
 NameContext attach(NameContext nc)
          Attach the given name context to the source Catalog.
 void canEditCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void canRemoveCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void commitedAddCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void commitEditCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void commitedRemoveCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 int compareTo(Object o)
          Compare the source Catalog to the given object.
 boolean contains(String sKey, DataBasket db)
          Check whether the indicated item is contained in the filtered Catalog.
 NameContext detachNC()
          Detach the current name context from the source Catalog.
 void editingCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
protected  void fireCanEditCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCanRemoveCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCatalogItemAddCommit(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCatalogItemAdded(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCatalogItemAddRollback(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCatalogItemRemoveCommit(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCatalogItemRemoved(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCatalogItemRemoveRollback(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireCommitEditCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireEditingCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireNoEditCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireNoRemoveCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
protected  void fireRollbackEditCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
 T get(String sKey, DataBasket db, boolean fForEdit)
          Get the indicated item from the source Catalog if it is contained in the filtered Catalog.
 Catalog getCatalog()
          Get the source Catalog's Catalog.
 Catalog getMainCatalog()
          Get the source catalog.
 String getName()
          Get the source Catalog's name.
 Value getValue()
          Get the source Catalog's value.
 Iterator<T> iterator(DataBasket db, boolean fForEdit)
          Get an iterator of all items that are contained in the filtered Catalog.
 Set<String> keySet(DataBasket db)
          Return a set that contains all keys for which a CatalogItem is contained in the filtered Catalog.
protected abstract  boolean match(T ci)
          Filter condition.
 void noEditCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void noRemoveCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 T remove(String sKey, DataBasket db)
          Remove the given item from the source Catalog if it is contained in the filtered Catalog.
 T remove(T ci, DataBasket db)
          Remove the given item from the source Catalog if it is contained in the filtered Catalog.
 void removeCatalogChangeListener(CatalogChangeListener ccl)
          Remove a listener that received events when the filtered Catalog changed.
 void removedCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void removeNameListener(PropertyChangeListener pcl)
          Un-Register the listener with the source Catalog.
 void removePropertyChangeListener(PropertyChangeListener pcl)
          Un-Register the listener with the source Catalog.
 void removeValueListener(PropertyChangeListener pcl)
          Un-Register the listener with the source Catalog.
 void rollbackEditCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void rolledbackAddCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void rolledbackRemoveCatalogItem(CatalogChangeEvent<T> e)
          Translate and propagate the event to all listeners of this Catalog.
 void setName(String sName, DataBasket db)
          Set the source Catalog's name.
 int size(DataBasket db)
          Calculate the size of the filtered Catalog.
 void subscribe()
          Subscribe as a listener to the source Catalog if that is a ListenableCatalog.
 void unsubscribe()
          Un-Subscribe as a listener from the source Catalog if that is a ListenableCatalog.
 void updateModel()
          Empty method body.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_cOrg

protected Catalog<T extends CatalogItem> m_cOrg
The Catalog that is being filtered.


m_lhListeners

protected ListenerHelper m_lhListeners
The listeners that listen for events from this Catalog.

Constructor Detail

CatalogFilter

public CatalogFilter(Catalog<T> cOrg)
Create a new CatalogFilter.

Parameters:
cOrg - the Catalog to be filtered.
Method Detail

compareTo

public int compareTo(Object o)
Compare the source Catalog to the given object.

Specified by:
compareTo in interface Comparable<Object>
Override:
Never

detachNC

public NameContext detachNC()
Detach the current name context from the source Catalog.

Specified by:
detachNC in interface Nameable
Returns:
the previously attached NameContext, if any.
Override:
Never

attach

public NameContext attach(NameContext nc)
Attach the given name context to the source Catalog.

Specified by:
attach in interface Nameable
Parameters:
nc - the new NameContext of this Nameable object.
Returns:
the previous NameContext, if any.
Override:
Never

getName

public String getName()
Get the source Catalog's name.

Specified by:
getName in interface Nameable
Override:
Never

setName

public void setName(String sName,
                    DataBasket db)
             throws NameContextException
Set the source Catalog's name.

Specified by:
setName in interface Nameable
Parameters:
sName - the new name of the object
db - the DataBasket relative to which the operation is to be performed.
Throws:
NameContextException - if the name change was not approved of by the NameContext.
See Also:
NameContext
Override:
Never

getValue

public Value getValue()
Get the source Catalog's value.

Specified by:
getValue in interface CatalogItem
Override:
Never

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener pcl)
Register the listener with the source Catalog.

Specified by:
addPropertyChangeListener in interface Nameable
Override:
Never

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener pcl)
Un-Register the listener with the source Catalog.

Specified by:
removePropertyChangeListener in interface Nameable
Override:
Never

addNameListener

public void addNameListener(PropertyChangeListener pcl)
Register the listener with the source Catalog.

Specified by:
addNameListener in interface Nameable
Override:
Never

removeNameListener

public void removeNameListener(PropertyChangeListener pcl)
Un-Register the listener with the source Catalog.

Specified by:
removeNameListener in interface Nameable
Override:
Never

addValueListener

public void addValueListener(PropertyChangeListener pcl)
Register the listener with the source Catalog.

Specified by:
addValueListener in interface CatalogItem
Override:
Never

removeValueListener

public void removeValueListener(PropertyChangeListener pcl)
Un-Register the listener with the source Catalog.

Specified by:
removeValueListener in interface CatalogItem
Override:
Never

getCatalog

public Catalog getCatalog()
Get the source Catalog's Catalog.

Specified by:
getCatalog in interface CatalogItem
Override:
Never

getMainCatalog

public Catalog getMainCatalog()
Get the source catalog. If the source catalog is a CatalogFilter again, return this Catalog's MainCatalog.

Override:
Never

add

public void add(T ci,
                DataBasket db)
Add the given item to the source Catalog.

Specified by:
add in interface Catalog<T extends CatalogItem>
Parameters:
ci - the CatalogItem to be added. This item must not be contained in another Catalog.
db - the DataBasket relative to which the operation is to be performed.
Override:
Never

remove

public T remove(T ci,
                DataBasket db)
                             throws VetoException
Remove the given item from the source Catalog if it is contained in the filtered Catalog.

Specified by:
remove in interface Catalog<T extends CatalogItem>
Parameters:
ci - the CatalogItem to be removed.
db - the DataBasket relative to which the operation is to be performed.
Returns:
the item that was actually removed.
Throws:
VetoException - if one of the listeners vetos the removal.
Override:
Never

remove

public T remove(String sKey,
                DataBasket db)
                             throws VetoException
Remove the given item from the source Catalog if it is contained in the filtered Catalog.

Specified by:
remove in interface Catalog<T extends CatalogItem>
Parameters:
sKey - the key of the CatalogItem to be removed.
db - the DataBasket relative to which the operation is to be performed.
Returns:
the item that was actually removed.
Throws:
VetoException - if one of the listeners vetos the removal.
Override:
Never

get

public T get(String sKey,
             DataBasket db,
             boolean fForEdit)
                          throws VetoException
Get the indicated item from the source Catalog if it is contained in the filtered Catalog.

Specified by:
get in interface Catalog<T extends CatalogItem>
Parameters:
sKey - the key of the CatalogItem to be retrieved.
db - the DataBasket relative to which the operation is to be performed.
fForEdit - if true, the CatalogItem will be retrieved for editing.
Returns:
the item that is associated with the given key.
Throws:
VetoException - if one of the listeners vetos the editing.
Override:
Never

contains

public boolean contains(String sKey,
                        DataBasket db)
Check whether the indicated item is contained in the filtered Catalog.

Specified by:
contains in interface Catalog<T extends CatalogItem>
Parameters:
sKey - the key for which to check containment.
db - the DataBasket that defines visibility of items. See Catalog.add(T, data.DataBasket) and Catalog.remove(T, data.DataBasket) for details on visibility.
Override:
Never

iterator

public Iterator<T> iterator(DataBasket db,
                            boolean fForEdit)
Get an iterator of all items that are contained in the filtered Catalog.

Specified by:
iterator in interface Catalog<T extends CatalogItem>
Parameters:
db - the DataBasket that defines visibility.
fForEdit - if true, the items are retrieved for editing. VetoException will be converted into UnsupportedOperationExceptions.
Override:
Never

keySet

public Set<String> keySet(DataBasket db)
Return a set that contains all keys for which a CatalogItem is contained in the filtered Catalog.

Specified by:
keySet in interface Catalog<T extends CatalogItem>
Parameters:
db - the DataBasket used to determine visibility of elements.
Override:
Never

size

public int size(DataBasket db)
Calculate the size of the filtered Catalog.

Specified by:
size in interface Catalog<T extends CatalogItem>
Parameters:
db - the DataBasket used to determine visibility.
Override:
Never

match

protected abstract boolean match(T ci)
Filter condition.

Parameters:
ci - the item to be tested
Returns:
true if the given item shall be an item of the filtered Catalog.
Override:
Always

addedCatalogItem

public void addedCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
addedCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

commitedAddCatalogItem

public void commitedAddCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
commitedAddCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

rolledbackAddCatalogItem

public void rolledbackAddCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
rolledbackAddCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

canRemoveCatalogItem

public void canRemoveCatalogItem(CatalogChangeEvent<T> e)
                          throws VetoException
Translate and propagate the event to all listeners of this Catalog.

Specified by:
canRemoveCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the removal.
Override:
Never

noRemoveCatalogItem

public void noRemoveCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
noRemoveCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

removedCatalogItem

public void removedCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
removedCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

commitedRemoveCatalogItem

public void commitedRemoveCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
commitedRemoveCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

rolledbackRemoveCatalogItem

public void rolledbackRemoveCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
rolledbackRemoveCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

canEditCatalogItem

public void canEditCatalogItem(CatalogChangeEvent<T> e)
                        throws VetoException
Translate and propagate the event to all listeners of this Catalog.

Specified by:
canEditCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Throws:
VetoException - if the listener wants to veto the editing.
Override:
Never

noEditCatalogItem

public void noEditCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
noEditCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

editingCatalogItem

public void editingCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

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

commitEditCatalogItem

public void commitEditCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
commitEditCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

rollbackEditCatalogItem

public void rollbackEditCatalogItem(CatalogChangeEvent<T> e)
Translate and propagate the event to all listeners of this Catalog.

Specified by:
rollbackEditCatalogItem in interface CatalogChangeListener<T extends CatalogItem>
Parameters:
e - an event object describing the event.
Override:
Never

addCatalogChangeListener

public void addCatalogChangeListener(CatalogChangeListener ccl)
Add a listener that wishes to receive events when the filtered Catalog changes.

Specified by:
addCatalogChangeListener in interface ListenableCatalog<T extends CatalogItem>
Parameters:
ccl - the listener to be added.
Override:
Never

removeCatalogChangeListener

public void removeCatalogChangeListener(CatalogChangeListener ccl)
Remove a listener that received events when the filtered Catalog changed.

Specified by:
removeCatalogChangeListener in interface ListenableCatalog<T extends CatalogItem>
Parameters:
ccl - the listener to be removed.
Override:
Never

fireCatalogItemAdded

protected void fireCatalogItemAdded(T ci,
                                    DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCatalogItemAddCommit

protected void fireCatalogItemAddCommit(T ci,
                                        DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCatalogItemAddRollback

protected void fireCatalogItemAddRollback(T ci,
                                          DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCatalogItemRemoved

protected void fireCatalogItemRemoved(T ci,
                                      DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCatalogItemRemoveCommit

protected void fireCatalogItemRemoveCommit(T ci,
                                           DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCatalogItemRemoveRollback

protected void fireCatalogItemRemoveRollback(T ci,
                                             DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCanRemoveCatalogItem

protected void fireCanRemoveCatalogItem(T ci,
                                        DataBasket db)
                                 throws VetoException
Fire the event to all listeners of this Catalog.

Throws:
VetoException
Override:
Never

fireNoRemoveCatalogItem

protected void fireNoRemoveCatalogItem(T ci,
                                       DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCanEditCatalogItem

protected void fireCanEditCatalogItem(T ci,
                                      DataBasket db)
                               throws VetoException
Fire the event to all listeners of this Catalog.

Throws:
VetoException
Override:
Never

fireNoEditCatalogItem

protected void fireNoEditCatalogItem(T ci,
                                     DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireEditingCatalogItem

protected void fireEditingCatalogItem(T ci,
                                      DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireCommitEditCatalogItem

protected void fireCommitEditCatalogItem(T ci,
                                         DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

fireRollbackEditCatalogItem

protected void fireRollbackEditCatalogItem(T ci,
                                           DataBasket db)
Fire the event to all listeners of this Catalog.

Override:
Never

subscribe

public void subscribe()
Subscribe as a listener to the source Catalog if that is a ListenableCatalog.

Specified by:
subscribe in interface HelpableListener
Override:
Never

unsubscribe

public void unsubscribe()
Un-Subscribe as a listener from the source Catalog if that is a ListenableCatalog.

Specified by:
unsubscribe in interface HelpableListener
Override:
Never

updateModel

public void updateModel()
Empty method body.

Specified by:
updateModel in interface HelpableListener
Override:
Never

SalesPoint v3.3 API