JIDE 3.5.15

com.jidesoft.grid
Class ShrinkSearchableSupport

java.lang.Object
  extended by com.jidesoft.grid.ShrinkSearchableSupport
All Implemented Interfaces:
SearchableListener, PropertyChangeListener, EventListener
Direct Known Subclasses:
ComboBoxShrinkSearchableSupport, ListComboBoxShrinkSearchableSupport, ListShrinkSearchableSupport, TableComboBoxShrinkSearchableSupport, TableShrinkSearchableSupport, TreeShrinkSearchableSupport

public abstract class ShrinkSearchableSupport
extends Object
implements SearchableListener, PropertyChangeListener

Searchable is a class that can make JList, JTable and JComboBox searchable. However, when the data is abundant, it is still annoying to look for a single word in hundreds of thousands of records. Hence, ShrinkSearchableSupport is requested, which means once you type a new letter in the searchable, the JList, JTable and JComboBox will refresh its display based on the new string input.

ShrinkSearchableSupport is a base abstract class. ListShrinkSearchableSupport, TableShrinkSearchableSupport, ComboBoxShrinkSearchableSupport are implementations to make JList, JTable, JComboBox searchable to be able to shrink on searching respectively. For each implementation, there are five methods need to be implemented.

As this is an abstract class, please refer to to javadoc of ListShrinkSearchableSupport to find out how to use it with JList respectively.

Last but not the least, only one Searchable is allowed on a component. If you install another one, it will remove the first one and then install the new one.


Field Summary
protected  Searchable _searchable
           
static String CLIENT_PROPERTY_SHRINK_SEARCHABLE_SUPPORT
          The client property for ShrinkSearchableSupport instance.
 
Constructor Summary
ShrinkSearchableSupport(Searchable searchable)
           
 
Method Summary
protected abstract  void applyFilter(String searchingText)
          Update the filterable model, usually applying filter, based on the latest Searchable searching text.
protected  String convertElementToString(Object object)
          Convert the element to string.
protected abstract  int getActualIndexAt(int visualIndex)
          Get actual index from the visual index.
protected abstract  int getVisualIndexAt(int actualIndex)
          Get visual index from the actual index.
abstract  void installFilterableModel()
          Install a filterable model for the component where Searchable installed in.
protected  boolean needReinstallFilterableModel(PropertyChangeEvent event)
          Checks if the filterable model should be reinstalled if the model is changed.
 void propertyChange(PropertyChangeEvent evt)
          Property change listener registered for the component's model
 void searchableEventFired(SearchableEvent e)
          Handle the SearchableEvent fired from Searchable.
abstract  void uninstallFilterableModel()
          Uninstall the filterable model installed by installFilterableModel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_searchable

protected final Searchable _searchable

CLIENT_PROPERTY_SHRINK_SEARCHABLE_SUPPORT

public static final String CLIENT_PROPERTY_SHRINK_SEARCHABLE_SUPPORT
The client property for ShrinkSearchableSupport instance. When ShrinkSearchableSupport is installed on a component, this client property has the ShrinkSearchableSupport.

Since:
3.3.4
See Also:
Constant Field Values
Constructor Detail

ShrinkSearchableSupport

public ShrinkSearchableSupport(Searchable searchable)
Method Detail

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Property change listener registered for the component's model

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
evt - the property change event
Since:
3.2.3

needReinstallFilterableModel

protected boolean needReinstallFilterableModel(PropertyChangeEvent event)
Checks if the filterable model should be reinstalled if the model is changed.

To keep the backward compatibility, it returns false by default.

To avoid potential infinite loop, the recommended implementation for this method is

 return event.getNewValue() != _filterableListModel.
 

Parameters:
event - the property change event
Returns:
true if a new filterable model should be installed. Otherwise false.
Since:
3.2.3

searchableEventFired

public void searchableEventFired(SearchableEvent e)
Handle the SearchableEvent fired from Searchable.

Basically it will only handle SEARCHABLE_CHANGE and SEARCHABLE_END events. In these two case, it will invoke updateFilterModel to shrink the model.

Specified by:
searchableEventFired in interface SearchableListener
Parameters:
e - the event

convertElementToString

protected String convertElementToString(Object object)
Convert the element to string. This method will be invoked inside applyFilter while creating the filter instance so that the conversion in ShrinkSearchSupport could be consistent with that in Searchable it wraps.

By default, this method will invoke _searchable#convertElementToString() only. You can override it if you need customize it.

Parameters:
object - the object to be converted
Returns:
the string to be displayed.

getActualIndexAt

protected abstract int getActualIndexAt(int visualIndex)
Get actual index from the visual index. This method will be invoked before we invoke applyFilter so that we can get the current selection information hence we are able to set the selection back after the filter is applied.

Parameters:
visualIndex - the visual index
Returns:
the actual index

getVisualIndexAt

protected abstract int getVisualIndexAt(int actualIndex)
Get visual index from the actual index. This method will be invoked after we invoke applyFilter so that we can set the selection back.

Parameters:
actualIndex - the actual index
Returns:
the visual index

installFilterableModel

public abstract void installFilterableModel()
Install a filterable model for the component where Searchable installed in.


uninstallFilterableModel

public abstract void uninstallFilterableModel()
Uninstall the filterable model installed by installFilterableModel.

If you are extending this class to create your customized ShrinkSearchableSupport class, please make sure you will invoke _searchable.getComponent().removePropertyChangeListener("model", this); to remove the property change listener. Otherwise the filterable model may not be removed.


applyFilter

protected abstract void applyFilter(String searchingText)
Update the filterable model, usually applying filter, based on the latest Searchable searching text.

If you want to override this method, please be noted that you probably need make your filter#convertElementToString to invoke convertElementToString(Object). Below is one sample implementation while creating the filter.

 WildcardFilter wildcardFilter = new WildcardFilter(searchingText) {
     protected String convertElementToString(Object value) {
         String stringValue = TableShrinkSearchableSupport.this.convertElementToString(value);
         return stringValue != null ? stringValue : super.convertElementToString(value);
     }
 };
 

Parameters:
searchingText - current searching text

JIDE 3.5.15