JIDE 3.5.15

com.jidesoft.tree
Class QuickTreeFilterField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.swing.LabeledTextField
                      extended by com.jidesoft.grid.QuickFilterField
                          extended by com.jidesoft.tree.QuickTreeFilterField
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class QuickTreeFilterField
extends QuickFilterField

QuickTreeFilterField works along with any TreeModel to provide filtering feature.

It is very simple to use it.

 QuickTreeFilterField filterField = new QuickTreeFilterField(anyTreeModel);
Later on, when you display the JTree, instead using your original tree model, use getDisplayTreeModel().
 JTree tree = new JTree(filterField.getDisplayTreeModel());
 filterField.setTree(tree); // optional. Only if you want the selection to be kept before and
 after filtering.
 
Usually you place QuickTreeFilterField somewhere close to the JTree in the user interface. User can type in any text in the text field, you will see the JTree automatically display the data that matches with the text.

See Also:
QuickFilterField, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.grid.QuickFilterField
QuickFilterField.FieldFilter
 
Nested classes/interfaces inherited from class com.jidesoft.swing.LabeledTextField
LabeledTextField.PopupMenuCustomizer
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String PROPERTY_HIDE_EMPTY_PARENT_NODE
          The property to determine if a parent node should be hidden when all its children nodes are filtered away.
static String PROPERTY_KEEP_ALL_CHILDREN
          The property to determine if all its children nodes should be kept when a parent node matches the searching text.
static String PROPERTY_MATCHES_LEAF_NODE_ONLY
          The property to determine if only leaf nodes should be matched with the searching text.
 
Fields inherited from class com.jidesoft.grid.QuickFilterField
_filter, _searchingText, PROPERTY_CASE_SENSITIVE, PROPERTY_FROM_END, PROPERTY_FROM_START, PROPERTY_REGEX_ENABLED, PROPERTY_SEARCH_TEXT, PROPERTY_WILDCARD_ENABLED
 
Fields inherited from class com.jidesoft.swing.LabeledTextField
_button, _contextMenuKeyStroke, _customizer, _hintLabel, _hintText, _icon, _label, _labelText, _showHintTextWhenFocused, _textField
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
QuickTreeFilterField()
          Creates an empty QuickTreeFilterField.
QuickTreeFilterField(TreeModel treeModel)
          Creates a QuickTreeFilterField using the specified treeModel.
 
Method Summary
 void applyFilter(String text)
          Applies the filter with the seaching text.
protected  JidePopupMenu createContextMenu()
          Creates the the context menu.
protected  FilterableTreeModel createDisplayTreeModel(TreeModel treeModel)
          Creates the FilterableTreeModel.
 FilterableTreeModel getDisplayTreeModel()
          Gets the display tree model.
 JTree getTree()
          Gets the tree that is using the displayTreeModel.
 TreeModel getTreeModel()
          Gets the tree model.
protected  String getTreeResourceString(String key)
          Gets the localized string from resource bundle.
 boolean isHideEmptyParentNode()
          Returns the value of hideEmptyParentNode property.
 boolean isKeepAllChildren()
          If a parent node matches, all its children will be kept if this flag is true.
 boolean isMatchesLeafNodeOnly()
          If the filters matches the leaf node only.
 void setHideEmptyParentNode(boolean hideEmptyParentNode)
          Sets the value of hideEmptyParentNode property.
 void setKeepAllChildren(boolean keepAllChildren)
          Sets the value of keepAllChildren property.
 void setMatchesLeafNodeOnly(boolean matchesLeafNodeOnly)
          Sets the value of matchesLeafNodeOnly property.
 void setTree(JTree tree)
          Sets the tree that is using the displayTreeModel.
 void setTreeModel(TreeModel treeModel)
          Sets the tree model used by this component.
 
Methods inherited from class com.jidesoft.grid.QuickFilterField
adjustMismatchColor, applyFilter, compare, compare, convertElementToString, createButton, createFilter, getDefaultFilterIcon, getDefaultResetIcon, getDefaultResetRolloverIcon, getFilter, getFilterIcon, getMismatchColor, getResetIcon, getResetRolloverIcon, getResourceString, getSearchingDelay, getSearchingText, getWildcardSupport, initComponent, installListeners, isCaseSensitive, isConfigurationChanged, isFromEnd, isFromStart, isRegexEnabled, isShowMismatchColor, isWildcardEnabled, matches, setCaseSensitive, setConfigurationChanged, setDefaultFilterIcon, setDefaultResetIcon, setDefaultResetRolloverIcon, setFilterIcon, setFromEnd, setFromStart, setMismatchColor, setRegexEnabled, setResetIcon, setResetRolloverIcon, setSearchingDelay, setSearchingText, setShowMismatchColor, setWildcardEnabled, setWildcardSupport, uninstallListeners
 
Methods inherited from class com.jidesoft.swing.LabeledTextField
calculateContextMenuLocation, createLabel, createTextField, customizePopupMenu, getBaseline, getButton, getContextMenuKeyStroke, getHintText, getIcon, getLabel, getLabelText, getPopupMenuCustomizer, getText, getTextField, initLayout, isShowHintTextWhenFocused, setColumns, setContextMenuKeyStroke, setEnabled, setHintText, setIcon, setLabelText, setPopupMenuCustomizer, setShowHintTextWhenFocused, setText, showContextMenu, updateUI
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_HIDE_EMPTY_PARENT_NODE

public static final String PROPERTY_HIDE_EMPTY_PARENT_NODE
The property to determine if a parent node should be hidden when all its children nodes are filtered away.

See Also:
Constant Field Values

PROPERTY_MATCHES_LEAF_NODE_ONLY

public static final String PROPERTY_MATCHES_LEAF_NODE_ONLY
The property to determine if only leaf nodes should be matched with the searching text.

See Also:
Constant Field Values

PROPERTY_KEEP_ALL_CHILDREN

public static final String PROPERTY_KEEP_ALL_CHILDREN
The property to determine if all its children nodes should be kept when a parent node matches the searching text.

See Also:
Constant Field Values
Constructor Detail

QuickTreeFilterField

public QuickTreeFilterField()
Creates an empty QuickTreeFilterField. This method is useless since QuickTreeFilterField has to have a tree model in order to work correctly. So we have this method in place mainly to make it JavaBean compatible. You must call setTreeModel(TreeModel) after you create QuickTreeFilterField using this constructor.


QuickTreeFilterField

public QuickTreeFilterField(TreeModel treeModel)
Creates a QuickTreeFilterField using the specified treeModel.

Parameters:
treeModel - the TreeModel
Method Detail

isHideEmptyParentNode

public boolean isHideEmptyParentNode()
Returns the value of hideEmptyParentNode property. By default it will return true, meaning if none of the parent node's children match with the searching text, the parent will be hidden too. This flag will take effect only when isMatchesLeafNodeOnly() returns true.

Returns:
true or false.

setHideEmptyParentNode

public void setHideEmptyParentNode(boolean hideEmptyParentNode)
Sets the value of hideEmptyParentNode property. By default this value is true. Changing this value will cause the filters to be applied again.

Parameters:
hideEmptyParentNode - true or false

isMatchesLeafNodeOnly

public boolean isMatchesLeafNodeOnly()
If the filters matches the leaf node only. By default it is true, meaning only leaf node will be compared to the searching text.

Returns:
true if only leaf node will be compared to the searching text. False if all nodes will be compared to the searching text.

setMatchesLeafNodeOnly

public void setMatchesLeafNodeOnly(boolean matchesLeafNodeOnly)
Sets the value of matchesLeafNodeOnly property. By default this value is true. Changing this value will cause the filters to be applied again.

Parameters:
matchesLeafNodeOnly - true or false

isKeepAllChildren

public boolean isKeepAllChildren()
If a parent node matches, all its children will be kept if this flag is true. Otherwise, we will further filter all the children and only leave those matched children visible.

Returns:
true if all children nodes will be kept if the parent node matches the filter condition.

setKeepAllChildren

public void setKeepAllChildren(boolean keepAllChildren)
Sets the value of keepAllChildren property. By default this value is false.

Parameters:
keepAllChildren - the flag

createContextMenu

protected JidePopupMenu createContextMenu()
Creates the the context menu. It will call super.createContextMenu() first, then add three menu items for QuickTreeFilterField. You can override this method if you want to customize the popup menu. The three menu items' name are "Filter.matchLeafNodeOnly", "Filter.hideNodesWithoutChildren" and "Filter.keepAllChildren" respectively. If you need to remove any of the menu items, you can always look it up by name and remove it.

Overrides:
createContextMenu in class QuickFilterField
Returns:
the popup menu.

applyFilter

public void applyFilter(String text)
Applies the filter with the seaching text.

Specified by:
applyFilter in class QuickFilterField
Parameters:
text - the searching text

setTreeModel

public void setTreeModel(TreeModel treeModel)
Sets the tree model used by this component. It could be any tree model, not necessarily be a FilterableTreeModel.

Parameters:
treeModel - the TreeModel

createDisplayTreeModel

protected FilterableTreeModel createDisplayTreeModel(TreeModel treeModel)
Creates the FilterableTreeModel. By default, it will always create a new FilterableTreeModel that wraps the treeModel but you can always override it to return an existing FilterableTreeModel if you want.

Parameters:
treeModel - the tree model.
Returns:
the FilterableTreeModel that wraps the tree model.

getTreeModel

public TreeModel getTreeModel()
Gets the tree model.

Returns:
the tree model.

getDisplayTreeModel

public FilterableTreeModel getDisplayTreeModel()
Gets the display tree model. QuickTreeFilterField doesn't modify the tree model that you passed in but wrap it in FilterableTreeModel. So if you want to display the result after being filtered, you should use this method to get the display tree model and set it to your tree.

Returns:
the table model to be displayed.

getTree

public JTree getTree()
Gets the tree that is using the displayTreeModel.

Returns:
the tree that is using the displayTreeModel.

setTree

public void setTree(JTree tree)
Sets the tree that is using the displayTreeModel. The only reason we want to know the tree is to keep the selection during filtering. For example, if node A is selected before filtering, and since it matches with the searching text, the selection should be kept after filtering. If you didn't call this method to let QuickTreeFilterField what the tree is, the selection will be gone.

Please note, this method will be set displayTreeModel onto the tree. You still need to call getDisplayTreeModel() to get the model and set it to the tree.

Parameters:
tree - the JTree

getTreeResourceString

protected String getTreeResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in grid.properties that begin with "Filter.".

Parameters:
key - the resource key
Returns:
the localized string.

JIDE 3.5.15