JIDE 3.5.15

com.jidesoft.filter
Class FilterFactoryManager

java.lang.Object
  extended by com.jidesoft.filter.FilterFactoryManager

public class FilterFactoryManager
extends Object

FilterFactoryManager is a class that contains the FilterFactory for each data type. It is only used in CustomFilterEditor to explore the possible filters for each data type. By default, we categorized the data type into Boolean, Date/Calendar, String and Number. There is registerDefaultFilterFactories() method which registers FilterFactories for all four categories.

If you need to extend to create more data types or customize it, you can subclass this class and override registerDefaultFilterFactories to register more filter factories. If you use it directly in CustomFilterEditor, you can use your instance directly. But if you use AutoFilterBox/AutoFilterTableHeader, you also need to call setDefaultInstance(FilterFactoryManager) to register an instance of your class as AutoFilterBox will use getDefaultInstance() to get an instance and use it.


Field Summary
static String DATA_TYPE_BOOLEAN
           
static String DATA_TYPE_DATE
           
static String DATA_TYPE_NUMBER
           
static String DATA_TYPE_STRING
           
 
Constructor Summary
FilterFactoryManager()
           
 
Method Summary
 void clear()
          Removes all registered filters.
 Filter createFilter(FilterFactory filterFactory, Object... objects)
          Creates Filter using the specified filterFactory and the necessary parameters for the filter.
 Filter createFilter(String filterFactoryName, Class type, Object... objects)
          Creates Filter using the specified filterFactoryName and the necessary parameters for the filter.
 FilterFactory findFilterFactoryByName(Class type, String filterFactoryName)
          Finds the FilterFactory from the FilterFactoryManager by the filter name.
static FilterFactoryManager getDefaultInstance()
          Gets a default instance of the FilterFactoryManager.
 List<FilterFactory> getFilterFactories(Class<?> type)
          Gets the registered FilterFactories.
 void registerDefaultFilterFactories()
          Registers default filter factories.
 void registerDefaultFilterFactories(boolean includeTwoParameters)
          Registers default filter factories.
 void registerFilterFactory(Class type, FilterFactory filterFactory)
          Registers the FilterFactory.
 void registerFilterFactory(Class type, FilterFactory filterFactory, int index)
          Registers the FilterFactory.
static void setDefaultInstance(FilterFactoryManager filterFactoryManager)
          Sets a default instance.
 boolean unregisterFilterFactory(Class type, FilterFactory filterFactory)
          Unregisters the FilterFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_TYPE_DATE

public static final String DATA_TYPE_DATE
See Also:
Constant Field Values

DATA_TYPE_STRING

public static final String DATA_TYPE_STRING
See Also:
Constant Field Values

DATA_TYPE_NUMBER

public static final String DATA_TYPE_NUMBER
See Also:
Constant Field Values

DATA_TYPE_BOOLEAN

public static final String DATA_TYPE_BOOLEAN
See Also:
Constant Field Values
Constructor Detail

FilterFactoryManager

public FilterFactoryManager()
Method Detail

registerFilterFactory

public void registerFilterFactory(Class type,
                                  FilterFactory filterFactory)
Registers the FilterFactory. Here is a sample code to register a FilterFactory.
 registerFilterFactory(Integer, new FilterFactory() {
    public Filter createFilter(Object... objects) {
        return new EqualFilter((Integer) objects[0]);
    }
    public Class[] getExpectedDataTypes() {
        return new Class[]{Integer.class};
    }
    public String getConditionString(Locale locale) {
       return "equals";
    }
 });
 
Once you register this FilterFactory, getFilterFactories(Class) will find it if the Class is Integer.class or int.class.

Parameters:
type - the type
filterFactory - the FilterFactory to be registered.

registerFilterFactory

public void registerFilterFactory(Class type,
                                  FilterFactory filterFactory,
                                  int index)
Registers the FilterFactory.

Parameters:
type - the type
filterFactory - the FilterFactory to be registered.
index - the order index of the newly registered FilterFactory. -1 means appending at the end (the last one).

unregisterFilterFactory

public boolean unregisterFilterFactory(Class type,
                                       FilterFactory filterFactory)
Unregisters the FilterFactory.

Parameters:
type - the type
filterFactory - the FilterFactory to be unregistered.
Returns:
true if unregistered successfully. Otherwise false. It usually means the FilterFactory is not registered before.

getFilterFactories

public List<FilterFactory> getFilterFactories(Class<?> type)
Gets the registered FilterFactories. This method will find all FilterFactories registered under the specified type as well as all its super classes, super interfaces including Objects. For primitives, it will search for the FilterFactories registered on the corresponding primitive wrapper type (such as if the type is int.class, we will search for Integer.class and Number.class). However if the type is the primitive wrapper type, we will not search for primitive type. So if you want the FilterFactory to be found for both int.class and Integer.class, it is better you register it using Integer.class.

Parameters:
type - the type.
Returns:
the registered FilterFactories.

clear

public void clear()
Removes all registered filters.


registerDefaultFilterFactories

public void registerDefaultFilterFactories()
Registers default filter factories.


registerDefaultFilterFactories

public void registerDefaultFilterFactories(boolean includeTwoParameters)
Registers default filter factories.

Parameters:
includeTwoParameters - true if those factories that have two parameters should be included. Otherwise false.
Since:
3.2.4

getDefaultInstance

public static FilterFactoryManager getDefaultInstance()
Gets a default instance of the FilterFactoryManager. This instance is shared by many components that need this feature. The registerDefaultFilterFactories() is already called before the default instance is returned.

Returns:
a default instance of the FilterFactoryManager

setDefaultInstance

public static void setDefaultInstance(FilterFactoryManager filterFactoryManager)
Sets a default instance. AutoFilterBox will call getDefaultInstance() to get an instance of FilterFactoryManager so it is important you call this method to set it if you subclasses FilterFactoryManager.

Parameters:
filterFactoryManager - a new instance of FilterFactoryManager.

findFilterFactoryByName

public FilterFactory findFilterFactoryByName(Class type,
                                             String filterFactoryName)
Finds the FilterFactory from the FilterFactoryManager by the filter name.

Parameters:
type - the data type.
filterFactoryName - the name of the FilterFactory.
Returns:
the FilterFactory that matches the filter name.

createFilter

public Filter createFilter(String filterFactoryName,
                           Class type,
                           Object... objects)
Creates Filter using the specified filterFactoryName and the necessary parameters for the filter.

Parameters:
filterFactoryName - the filter factory name.
type - the data type.
objects - the parameters for the filter
Returns:
a Filter. It could be null if the FilterFactory specified by the filterFactoryName doesn't exist.

createFilter

public Filter createFilter(FilterFactory filterFactory,
                           Object... objects)
Creates Filter using the specified filterFactory and the necessary parameters for the filter.

Parameters:
filterFactory - the filter factory
objects - the parameters for the filter
Returns:
a Filter. It could be null if the FilterFactory specified by the filterFactory is null.

JIDE 3.5.15