JIDE 3.5.15

com.jidesoft.filter
Class AbstractFilter<T>

java.lang.Object
  extended by com.jidesoft.filter.AbstractFilter<T>
All Implemented Interfaces:
Filter<T>, ObjectGrouperSupport, Serializable, Cloneable
Direct Known Subclasses:
AbstractFilter, AbstractValueFilter, AllFilter, BetweenFilter, DateOrCalendarFilter, EmptyFilter, EqualFilter, IFilterableTableModel.FilterItem, InFilter, MultipleFilters, NoneFilter, NotFilter, QuickFilterField.FieldFilter, RegexFilter

public abstract class AbstractFilter<T>
extends Object
implements Filter<T>, ObjectGrouperSupport

This abstract class provides default implementations for most of the methods in the Filter interface. It takes care of the management of listeners and provides some conveniences for generating FilterEvent and dispatching them to the listeners. To create a concrete Filter as a subclass of AbstractTableModel you need only provide implementations for the following one methods:

  public boolean isValueFiltered();
  

Please note, for backward compatible reason, this class implement com.jidesoft.grid.Filter which is deprecated already. It will be changed to implement com.jidesoft.filter.Filter after a few releases.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.jidesoft.filter.Filter
ALL, CUSTOM, NULL, SEPARATOR
 
Constructor Summary
AbstractFilter()
           
AbstractFilter(String name)
           
 
Method Summary
 void addFilterListener(FilterListener l)
          Adds a listener to the list that's notified each time a change to the filter occurs.
 Object clone()
          Creates and returns a copy of the filter.
 void fireFilterChanged(FilterEvent e)
          Forwards the given notification event to all FilterListeners that registered themselves as listeners for this table model.
 void fireFilterContentChanged()
          Notifies all listeners that the filter content is changed.
 void fireFilterDisabled()
          Notifies all listeners that the filter is disabled.
 void fireFilterEnabled()
          Notifies all listeners that the filter is enabled.
 void fireFilterNameChanged()
          Notifies all listeners that the filter's name is changed.
static String getConditionString(Locale locale, String dataType, String resourceKey)
           
 FilterFactory getFilterFactory()
          Gets the FilterFactory that creates the Filter.
 String getFilterFactoryName()
          Gets the FilterFactory name that creates the Filter.
 FilterListener[] getFilterListeners()
          Returns an array of all the filter listeners registered on this filter.
 String getName()
          Gets the name of the filter.
 ObjectGrouper getObjectGrouper()
          Gets the current ObjectGrouper instance.
 String getObjectGrouperName()
          Gets the name of object grouper.
 String getPreference(Class<?> clazz, ConverterContext converterContext)
          Gets the preference while persisting this filter.
 boolean isEnabled()
          Checks if the filter is enabled.
 boolean isFilterValid()
          Checks if the filter is valid or not.
 void removeFilterListener(FilterListener l)
          Removes a listener from the list that's notified each time a change to the filter occurs.
 void setEnabled(boolean enabled)
          Sets the filter enabled or disabled.
 void setFilterFactory(FilterFactory filterFactory)
          Sets the FilterFactory.
 void setFilterFactoryName(String filterFactoryName)
          Sets the name of the FilterFactory.
 void setName(String name)
          Sets the name of the filter.
 void setObjectGrouper(ObjectGrouper objectGrouper)
          Sets the current ObjectGrouper instance.
 void setObjectGrouperName(String grouperName)
          Sets the name of object grouper.
 Object[] setPreference(String prefString, Class<?> clazz, ConverterContext converterContext)
          Sets the preference to load the preference string back to this filter.
 boolean stricterThan(Filter inputFilter)
          Checks if this filter is stricter than the input filter.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jidesoft.filter.Filter
isValueFiltered
 

Constructor Detail

AbstractFilter

public AbstractFilter()

AbstractFilter

public AbstractFilter(String name)
Method Detail

getName

public String getName()
Description copied from interface: Filter
Gets the name of the filter.

Specified by:
getName in interface Filter<T>
Returns:
the name of the filter.

setName

public void setName(String name)
Description copied from interface: Filter
Sets the name of the filter.

Specified by:
setName in interface Filter<T>
Parameters:
name - the name of the filter.

isEnabled

public boolean isEnabled()
Description copied from interface: Filter
Checks if the filter is enabled. If a filter is not enabled, isValueFiltered() will never be called.

Specified by:
isEnabled in interface Filter<T>
Returns:
true if the filter is enabled. Otherwise false.

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: Filter
Sets the filter enabled or disabled.

Specified by:
setEnabled in interface Filter<T>
Parameters:
enabled - true to enabled the filter; false to disable it.

getFilterFactory

public FilterFactory getFilterFactory()
Gets the FilterFactory that creates the Filter. If this Filter is created by FilterFactoryManager.createFilter(String, Class, Object...) or FilterFactoryManager.createFilter(FilterFactory, Object...), this method will return that FilterFactory.

Specified by:
getFilterFactory in interface Filter<T>
Returns:
the FilterFactory that creates the Filter. It could be null if the Filter is not created by FilterFactory

setFilterFactory

public void setFilterFactory(FilterFactory filterFactory)
Sets the FilterFactory. You probably don't need to call this method unless you create a Filter by code but you want the CustomFilterEditor to recognize it. In this case, you can call FilterFactoryManager.findFilterFactoryByName(Class, String).

Specified by:
setFilterFactory in interface Filter<T>
Parameters:
filterFactory - the FilterFactory.

getFilterFactoryName

public String getFilterFactoryName()
Gets the FilterFactory name that creates the Filter. If this Filter is created by FilterFactoryManager.createFilter(String, Class, Object...) or FilterFactoryManager.createFilter(FilterFactory, Object...), this method will return that FilterFactoryName.

Specified by:
getFilterFactoryName in interface Filter<T>
Returns:
the name of the FilterFactory that creates the Filter. It could be null if the Filter is not created by FilterFactory.

setFilterFactoryName

public void setFilterFactoryName(String filterFactoryName)
Sets the name of the FilterFactory. You probably don't need to call this method unless you create a Filter by code but you want the CustomFilterEditor to recognize it. In this case, you can call FilterFactoryManager.findFilterFactoryByName(Class, String). The other use case is the Filter is persisted using Java Serialization and the FilterFactory field is transient so it won't be persisted. In this case, you can call findFilterFactoryByName to find the FilterFactory based on the getFilterFactoryName().

Specified by:
setFilterFactoryName in interface Filter<T>
Parameters:
filterFactoryName - the name of the FilterFactory.

addFilterListener

public void addFilterListener(FilterListener l)
Adds a listener to the list that's notified each time a change to the filter occurs.

Specified by:
addFilterListener in interface Filter<T>
Parameters:
l - the FilterListener

removeFilterListener

public void removeFilterListener(FilterListener l)
Removes a listener from the list that's notified each time a change to the filter occurs.

Specified by:
removeFilterListener in interface Filter<T>
Parameters:
l - the FilterListener

getFilterListeners

public FilterListener[] getFilterListeners()
Returns an array of all the filter listeners registered on this filter.

Returns:
all of this filter's FilterListeners or an empty array if no filter listeners are currently registered
See Also:
addFilterListener(com.jidesoft.grid.FilterListener), removeFilterListener(com.jidesoft.grid.FilterListener)

fireFilterChanged

public void fireFilterChanged(FilterEvent e)
Forwards the given notification event to all FilterListeners that registered themselves as listeners for this table model.

Parameters:
e - the event to be forwarded
See Also:
addFilterListener(com.jidesoft.grid.FilterListener), FilterEvent, EventListenerList

fireFilterEnabled

public void fireFilterEnabled()
Notifies all listeners that the filter is enabled.

See Also:
FilterEvent, EventListenerList

fireFilterDisabled

public void fireFilterDisabled()
Notifies all listeners that the filter is disabled.

See Also:
FilterEvent, EventListenerList

fireFilterNameChanged

public void fireFilterNameChanged()
Notifies all listeners that the filter's name is changed.

See Also:
FilterEvent, EventListenerList

fireFilterContentChanged

public void fireFilterContentChanged()
Notifies all listeners that the filter content is changed.

See Also:
FilterEvent, EventListenerList

getConditionString

public static String getConditionString(Locale locale,
                                        String dataType,
                                        String resourceKey)

stricterThan

public boolean stricterThan(Filter inputFilter)
Checks if this filter is stricter than the input filter.

This is a default method that return false. The reason is that if you forgot to override this method, the filter will apply to all datum so it is safe for you although the performance will a little bit slower. To improve the performance of your filter, you can override this method to return true if the input filter is less stricter than this filter to avoid unnecessary filtering.

Specified by:
stricterThan in interface Filter<T>
Parameters:
inputFilter - the input filter
Returns:
true if this filter stricter than the input filter. Otherwise false.

getObjectGrouper

public ObjectGrouper getObjectGrouper()
Description copied from interface: ObjectGrouperSupport
Gets the current ObjectGrouper instance.

Specified by:
getObjectGrouper in interface ObjectGrouperSupport
Returns:
the grouper.

setObjectGrouper

public void setObjectGrouper(ObjectGrouper objectGrouper)
Description copied from interface: ObjectGrouperSupport
Sets the current ObjectGrouper instance.

Specified by:
setObjectGrouper in interface ObjectGrouperSupport
Parameters:
objectGrouper - the grouper

setObjectGrouperName

public void setObjectGrouperName(String grouperName)
Description copied from interface: ObjectGrouperSupport
Sets the name of object grouper.

Specified by:
setObjectGrouperName in interface ObjectGrouperSupport
Parameters:
grouperName - the grouper name

getObjectGrouperName

public String getObjectGrouperName()
Description copied from interface: ObjectGrouperSupport
Gets the name of object grouper.

Specified by:
getObjectGrouperName in interface ObjectGrouperSupport
Returns:
the grouper name.

getPreference

public String getPreference(Class<?> clazz,
                            ConverterContext converterContext)
Description copied from interface: Filter
Gets the preference while persisting this filter.

Specified by:
getPreference in interface Filter<T>
Parameters:
clazz - the class type to convert the values inside the filter to string
converterContext - the converter context to convert the values inside the filter to string
Returns:
the preference string.

setPreference

public Object[] setPreference(String prefString,
                              Class<?> clazz,
                              ConverterContext converterContext)
Description copied from interface: Filter
Sets the preference to load the preference string back to this filter.

Specified by:
setPreference in interface Filter<T>
Parameters:
prefString - the preference string
clazz - the class type to convert the values inside the filter to string
converterContext - the converter context to convert the values inside the filter to string
Returns:
the object array to be passed into the FilterFactoryManager if necessary.

clone

public Object clone()
             throws CloneNotSupportedException
Creates and returns a copy of the filter.

Specified by:
clone in interface Filter<T>
Overrides:
clone in class Object
Returns:
a cloned copy of the filter.
Throws:
CloneNotSupportedException - if the cloning of the filter is not supported.

isFilterValid

public boolean isFilterValid()
Checks if the filter is valid or not. By default, it just returns true simply. This method will help determine if the filter loaded from a string by invoking setPreference(String, Class, com.jidesoft.converter.ConverterContext) is valid or not.

Returns:
true by default.
Since:
3.4.8

JIDE 3.5.15