org.salespointframework.core.data.filters
Class CatalogFilter<T extends CatalogItem>

java.lang.Object
  extended by org.salespointframework.core.data.filters.CatalogFilter<T>
All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>, java.util.EventListener, CatalogChangeListener<T>, DatasourceChangeListener, ExternalModificationListener, Catalog<T>, CatalogItem, DataBasketEntryDestination, DataBasketEntrySource, ListenableCatalog<T>, Nameable, SpAggregate, SpItem, HelpableListener
Direct Known Subclasses:
CurrencyFilter

public abstract class CatalogFilter<T extends CatalogItem>
extends java.lang.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
Version:
2.0 19/08/1999
Author:
Steffen Zschaler

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.
 
Fields inherited from interface org.salespointframework.core.data.interfaces.CatalogItem
VALUE_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.Nameable
NAME_PROPERTY
 
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(java.beans.PropertyChangeListener pcl)
          Register the listener with the source Catalog.
 void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Register the listener with the source Catalog.
 void addValueListener(java.beans.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(java.lang.Object o)
          Compare the source Catalog to the given object.
 boolean contains(java.lang.String sKey, DataBasket db)
          Check whether the indicated item is contained in the filtered Catalog.
 void DatasourceChanged(boolean pumpUp)
          indicates a change of datasource.
 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.
 void externalModificationOccurred()
          external modification just occurred
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.
 void fireCatalogItemDataChanged(java.beans.PropertyChangeEvent pce)
           
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.
 void firePropertyChanged()
          Signals persistence layer to update objects values
protected  void fireRollbackEditCatalogItem(T ci, DataBasket db)
          Fire the event to all listeners of this Catalog.
 T get(java.lang.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.
 java.awt.image.BufferedImage getImage()
          Get the image of the CatalogItem
 Catalog getMainCatalog()
          Get the source catalog.
 java.lang.String getName()
          Get the source Catalog's name.
 Value getValue()
          Get the source Catalog's value.
 java.util.Iterator<T> iterator(DataBasket db, boolean fForEdit)
          Get an iterator of all items that are contained in the filtered Catalog.
 java.util.Set<java.lang.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(java.lang.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(java.beans.PropertyChangeListener pcl)
          Un-Register the listener with the source Catalog.
 void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Un-Register the listener with the source Catalog.
 void removeValueListener(java.beans.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.
 boolean setImage(java.net.URI filename)
          Set the image of the CatalogItem
 void setName(java.lang.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(java.lang.Object o)
Compare the source Catalog to the given object.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>

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.

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.

getName

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

Specified by:
getName in interface Nameable
Specified by:
getName in interface SpItem

setName

public void setName(java.lang.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

getValue

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

Specified by:
getValue in interface CatalogItem

addPropertyChangeListener

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

Specified by:
addPropertyChangeListener in interface Nameable

removePropertyChangeListener

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

Specified by:
removePropertyChangeListener in interface Nameable

addNameListener

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

Specified by:
addNameListener in interface Nameable

removeNameListener

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

Specified by:
removeNameListener in interface Nameable

addValueListener

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

Specified by:
addValueListener in interface CatalogItem

removeValueListener

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

Specified by:
removeValueListener in interface CatalogItem

getCatalog

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

Specified by:
getCatalog in interface CatalogItem

getMainCatalog

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


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.

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.

remove

public T remove(java.lang.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.

get

public T get(java.lang.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.

contains

public boolean contains(java.lang.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, org.salespointframework.core.data.interfaces.DataBasket) and Catalog.remove(T, org.salespointframework.core.data.interfaces.DataBasket) for details on visibility.

iterator

public java.util.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.

keySet

public java.util.Set<java.lang.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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

fireCatalogItemAdded

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


fireCatalogItemAddCommit

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


fireCatalogItemAddRollback

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


fireCatalogItemRemoved

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


fireCatalogItemRemoveCommit

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


fireCatalogItemRemoveRollback

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


fireCanRemoveCatalogItem

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

Throws:
VetoException

fireNoRemoveCatalogItem

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


fireCanEditCatalogItem

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

Throws:
VetoException

fireNoEditCatalogItem

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


fireEditingCatalogItem

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


fireCommitEditCatalogItem

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


fireRollbackEditCatalogItem

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


DatasourceChanged

public void DatasourceChanged(boolean pumpUp)
Description copied from interface: DatasourceChangeListener
indicates a change of datasource.

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

externalModificationOccurred

public void externalModificationOccurred()
Description copied from interface: ExternalModificationListener
external modification just occurred

Specified by:
externalModificationOccurred in interface ExternalModificationListener

fireCatalogItemDataChanged

public void fireCatalogItemDataChanged(java.beans.PropertyChangeEvent pce)

firePropertyChanged

public void firePropertyChanged()
Description copied from interface: CatalogItem
Signals persistence layer to update objects values

Specified by:
firePropertyChanged in interface CatalogItem

getImage

public java.awt.image.BufferedImage getImage()
Description copied from interface: CatalogItem
Get the image of the CatalogItem

Specified by:
getImage in interface CatalogItem
Returns:

setImage

public boolean setImage(java.net.URI filename)
Description copied from interface: CatalogItem
Set the image of the CatalogItem

Specified by:
setImage in interface CatalogItem
Parameters:
filename - uri, pointing to the image file
Returns:
true on success

subscribe

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

Specified by:
subscribe in interface HelpableListener

unsubscribe

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

Specified by:
unsubscribe in interface HelpableListener

updateModel

public void updateModel()
Empty method body.

Specified by:
updateModel in interface HelpableListener