JIDE 3.5.15

com.jidesoft.combobox
Class TreeExComboBoxSearchable

java.lang.Object
  extended by com.jidesoft.swing.Searchable
      extended by com.jidesoft.swing.ComboBoxSearchable
          extended by com.jidesoft.combobox.ExComboBoxSearchable
              extended by com.jidesoft.combobox.TreeExComboBoxSearchable
All Implemented Interfaces:
PropertyChangeListener, EventListener, ListDataListener, PopupMenuListener, TreeModelListener

public class TreeExComboBoxSearchable
extends ExComboBoxSearchable
implements TreeModelListener

TreeSearchable is an concrete implementation of Searchable that enables the search function in TreeExComboBox.

It's very simple to use it. Assuming you have a TreeExComboBox, all you need to do is to call

 TreeExComboBox treeExComboBox = ....;
 TreeSearchable searchable = new TreeSearchable(treeExComboBox);
 
Now the TreeExComboBox will have the search function.

There is very little customization you need to do to TreeSearchable. The only thing you might need is when the element in the TreeExComboBox needs a special conversion to convert to string. If so, you can override convertElementToString() to provide you own algorithm to do the conversion.

 TreeExComboBox treeExComboBox = ....;
 TreeSearchable searchable = new TreeSearchable(treeExComboBox) {
      protected String convertElementToString(Object object) {
          ...
      }
 };
 

Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes, case sensitivity,


Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.swing.Searchable
Searchable.SearchField, Searchable.SearchPopup
 
Field Summary
 
Fields inherited from class com.jidesoft.swing.Searchable
_component, _componentListener, _focusListener, _keyListener, _matchCount, CLIENT_PROPERTY_SEARCHABLE, listenerList, PROPERTY_SEARCH_TEXT
 
Constructor Summary
TreeExComboBoxSearchable(TreeExComboBox tree)
           
 
Method Summary
protected  String convertElementToString(Object object)
          Converts the element in TreeExComboBox to string.
protected  Object getElementAt(int index)
          Gets the element at the specified index.
protected  int getElementCount()
          Gets the total element count in the component.
protected  int getSelectedIndex()
          Gets the selected index in the component.
protected  List<TreePath> getTreePathes()
          Gets the cached tree paths list.
 boolean isRecursive()
          Checks if the searchable is recursive.
protected  void populateTreePaths()
          Recursively go through the tree to populate the tree paths into a list and cache them.
 void propertyChange(PropertyChangeEvent evt)
           
protected  void resetTreePathes()
          Reset the cached tree paths list.
 void setRecursive(boolean recursive)
          Sets the recursive attribute.
protected  void setSelectedIndex(int index, boolean incremental)
          Sets the selected index.
 void showPopup(String searchingText)
          Shows the search popup.
 void treeNodesChanged(TreeModelEvent e)
           
 void treeNodesInserted(TreeModelEvent e)
           
 void treeNodesRemoved(TreeModelEvent e)
           
 void treeStructureChanged(TreeModelEvent e)
           
 void uninstallListeners()
          Uninstall the listeners that installed before.
 
Methods inherited from class com.jidesoft.combobox.ExComboBoxSearchable
getComboBox, popupMenuWillBecomeInvisible
 
Methods inherited from class com.jidesoft.swing.ComboBoxSearchable
contentsChanged, intervalAdded, intervalRemoved, isRefreshPopupDuringSearching, isShowPopupDuringSearching, popupMenuCanceled, popupMenuWillBecomeVisible, setRefreshPopupDuringSearching, setShowPopupDuringSearching
 
Methods inherited from class com.jidesoft.swing.Searchable
addPropertyChangeListener, addSearchableListener, adjustSelectedIndex, cancelHighlightAll, compare, compare, convertToString, createComponentListener, createFocusListener, createKeyListener, createSearchPopup, findAll, findFirst, findFromCursor, findLast, findNext, findPrevious, firePropertyChangeEvent, fireSearchableEvent, getBackground, getComponent, getCurrentIndex, getCursor, getElementAtAsString, getForeground, getMismatchForeground, getPopupLocation, getPopupLocationRelativeTo, getPopupTimeout, getResourceString, getSearchable, getSearchableListeners, getSearchableProvider, getSearchingDelay, getSearchingText, getSearchLabel, getWildcardSupport, hidePopup, highlightAll, installListeners, isActivateKey, isCaseSensitive, isCountMatch, isDeactivateKey, isFindFirstKey, isFindLastKey, isFindNextKey, isFindPreviousKey, isFromStart, isHeavyweightComponentEnabled, isHideSearchPopupOnEvent, isIncrementalSelectKey, isNavigationKey, isPopupVisible, isProcessModelChangeEvent, isRepeats, isReverseOrder, isSearchableListenerInstalled, isSelectAllKey, isWildcardEnabled, keyTypedOrPressed, removePropertyChangeListener, removeSearchableListener, reverseFindFromCursor, searchingTextEmpty, select, setBackground, setCaseSensitive, setCountMatch, setCursor, setCursor, setForeground, setFromStart, setHeavyweightComponentEnabled, setHideSearchPopupOnEvent, setMismatchForeground, setPopupLocation, setPopupLocationRelativeTo, setPopupTimeout, setProcessModelChangeEvent, setRepeats, setReverseOrder, setSearchableProvider, setSearchingDelay, setSearchLabel, setWildcardEnabled, setWildcardSupport, textChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeExComboBoxSearchable

public TreeExComboBoxSearchable(TreeExComboBox tree)
Method Detail

isRecursive

public boolean isRecursive()
Checks if the searchable is recursive.

Returns:
true if searchable is recursive.

setRecursive

public void setRecursive(boolean recursive)
Sets the recursive attribute.

If TreeSearchable is recursive, it will all tree nodes including those which are not visible to find the matching node. Obviously, if your tree has unlimited number of tree nodes or a potential huge number of tree nodes (such as a tree to represent file system), the recursive attribute should be false. To avoid this potential problem in this case, we default it to false.

Parameters:
recursive - true or false

uninstallListeners

public void uninstallListeners()
Description copied from class: Searchable
Uninstall the listeners that installed before. This method is never called because we don't have the control of the life cycle of the component. However you can call this method if you don't want the component to be searchable any more.

Overrides:
uninstallListeners in class ComboBoxSearchable

showPopup

public void showPopup(String searchingText)
Description copied from class: Searchable
Shows the search popup. By default, the search popup will be visible automatically when user types in the first key (in the case of JList, JTree, JTable) or types in designated keystroke (in the case of JTextComponent). So this method is only used when you want to show the popup manually.

Overrides:
showPopup in class Searchable
Parameters:
searchingText - the searching text

setSelectedIndex

protected void setSelectedIndex(int index,
                                boolean incremental)
Description copied from class: Searchable
Sets the selected index. The concrete implementation should call methods on the component to select the element at the specified index. The incremental flag is used to do multiple select. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.

Overrides:
setSelectedIndex in class ComboBoxSearchable
Parameters:
index - the index to be selected
incremental - a flag to enable multiple selection. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.

getSelectedIndex

protected int getSelectedIndex()
Description copied from class: Searchable
Gets the selected index in the component. The concrete implementation should call methods on the component to retrieve the current selected index. If the component supports multiple selection, it's OK just return the index of the first selection.

Here are some examples. In the case of JList, the index is the row index. In the case of JTree, the index is the row index too. In the case of JTable, depending on the selection mode, the index could be row index (in row selection mode), could be column index (in column selection mode) or could the cell index (in cell selection mode).

Overrides:
getSelectedIndex in class ComboBoxSearchable
Returns:
the selected index.

getElementAt

protected Object getElementAt(int index)
Description copied from class: Searchable
Gets the element at the specified index. The element could be any data structure that internally used in the component. The convertElementToString method will give you a chance to convert the element to string which is used to compare with the string that user types in.

Overrides:
getElementAt in class ComboBoxSearchable
Parameters:
index - the index
Returns:
the element at the specified index.

getElementCount

protected int getElementCount()
Description copied from class: Searchable
Gets the total element count in the component. Different concrete implementation could have different interpretation of the count. This is totally OK as long as it's consistent in all the methods. For example, the index parameter in other methods should be always a valid value within the total count.

Overrides:
getElementCount in class ComboBoxSearchable
Returns:
the total element count.

populateTreePaths

protected void populateTreePaths()
Recursively go through the tree to populate the tree paths into a list and cache them.

Tree paths list is only used when the recursive attribute is set to true.


resetTreePathes

protected void resetTreePathes()
Reset the cached tree paths list.

Tree paths list is only used when recursive attribute true.


getTreePathes

protected List<TreePath> getTreePathes()
Gets the cached tree paths list. If it has never been cached before, this method will create the cache.

Tree paths list is only used when recursive attribute is true.

Returns:
the tree paths list.

convertElementToString

protected String convertElementToString(Object object)
Converts the element in TreeExComboBox to string. The element by default is TreePath. The returned value will be toString() of the last path component in the TreePath.

Overrides:
convertElementToString in class ExComboBoxSearchable
Parameters:
object - the object. This is usually a TreePath.
Returns:
the string representing the TreePath in the TreeExComboBox.

treeNodesChanged

public void treeNodesChanged(TreeModelEvent e)
Specified by:
treeNodesChanged in interface TreeModelListener

treeNodesInserted

public void treeNodesInserted(TreeModelEvent e)
Specified by:
treeNodesInserted in interface TreeModelListener

treeNodesRemoved

public void treeNodesRemoved(TreeModelEvent e)
Specified by:
treeNodesRemoved in interface TreeModelListener

treeStructureChanged

public void treeStructureChanged(TreeModelEvent e)
Specified by:
treeStructureChanged in interface TreeModelListener

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener
Overrides:
propertyChange in class ComboBoxSearchable

JIDE 3.5.15