JIDE 3.5.15

com.jidesoft.combobox
Class TreeExComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by com.jidesoft.combobox.ExComboBox
                      extended by com.jidesoft.combobox.TreeExComboBox
All Implemented Interfaces:
ConverterContextSupport, ActionListener, ImageObserver, ItemSelectable, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, ListDataListener
Direct Known Subclasses:
CheckBoxTreeExComboBox

public class TreeExComboBox
extends ExComboBox

TreeComboBox is just like a normal JComboBox which you can choose a value from a drop-down tree.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.combobox.ExComboBox
ExComboBox.LazyDelegateAction
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager
 
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
protected  Object _object
           
protected  TreeModel _treeModel
           
protected  int maximumRowCount
          This protected field is implementation specific.
protected  TreeCellRenderer renderer
          This protected field is implementation specific.
static String TREE_MODEL_PROPERTY
           
 
Fields inherited from class com.jidesoft.combobox.ExComboBox
CLIENT_PROPERTY_HIDE_POPUP_ON_LIST_DATA_CHANGED, CLIENT_PROPERTY_POPUP_PANEL, CLIENT_PROPERTY_TABLE_CELL_EDITOR, CLIENT_PROPERTY_TABLE_CELL_RENDERER, COMMIT, COMMIT_OR_RESET, COMMIT_OR_REVERT, DIALOG, DOWN_KEY_BEHAVIOR_SELECT_NEXT, DOWN_KEY_BEHAVIOR_SHOW_POPUP, DROPDOWN, PERSIST, PROPERTY_BUTTON_VISIBLE, PROPERTY_SELECTED_ITEM, RESET, REVERT
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, selectedItemReminder
 
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
TreeExComboBox()
           
TreeExComboBox(Hashtable<?,?> objects)
          Creates a new TreeComboBox.
TreeExComboBox(Object[] objects)
          Creates a new TreeComboBox.
TreeExComboBox(TreeModel model)
          Creates a new TreeComboBox.
TreeExComboBox(TreeNode root)
          Creates a new TreeComboBox.
TreeExComboBox(TreeNode root, boolean asksAllowsChildren)
          Creates a new TreeComboBox.
TreeExComboBox(Vector<?> objects)
          Creates a new TreeComboBox.
 
Method Summary
 String convertElementToString(Object object)
          Converts the element from object to string so that i can display in the text field of TreeComboBox.
 PopupPanel createPopupComponent()
          Subclass should implement this method to create the actual popup component.
protected  JTree createTree(TreeModel model)
          Creates the tree.
protected  TreeChooserPanel createTreeChooserPanel(TreeModel model)
          Creates the TreeChooserPanel.
 TreeCellRenderer getCellRenderer()
          Returns the renderer used to display the selected item in the JComboBox field.
protected  JComponent getDelegateTarget(PopupPanel panel)
           
 int getMaximumRowCount()
          Returns the maximum number of items the combo box can display without a scrollbar.
 JTree getTree()
          Gets the underlying JTree.
 TreeModel getTreeModel()
          Gets the tree model that will be used by the tree in the popup.
protected  void initComboBox()
           
 boolean isDoubleClickExpand()
          Get the flag indicating if the mouse double click would expand the tree path instead of just select it.
 boolean isSearchUserObjectToSelect()
          Gets the flag indicating if TreeExComboBox will search all its tree path's userObject to make the selection if the selected object is set to a non-TreePath value.
protected  boolean isValidSelection(TreePath path)
          Checks if a given tree path is a valid selection for combobox.
protected  List<TreePath> populateTreePaths(JTree tree)
           
 void setCellRenderer(TreeCellRenderer aRenderer)
          Sets the renderer that paints the list items and the item selected from the list in the JComboBox field.
 void setDoubleClickExpand(boolean doubleClickExpand)
          Set the flag indicating if the mouse double click would expand the tree path instead of just select it.
 void setMaximumRowCount(int count)
          Sets the maximum number of rows the JComboBox displays.
 void setPopupVisible(boolean v)
           
 void setSearchUserObjectToSelect(boolean searchUserObjectToSelect)
          Sets the flag indicating if TreeExComboBox will search all its tree path's userObject to make the selection if the selected object is set to a non-TreePath value.
 void setTreeModel(TreeModel treeModel)
          Sets the tree model that will be used by the tree in the popup.
protected  void setupTree(JTree tree)
          Setups the JTree for the tree used in the popup panel.
 
Methods inherited from class com.jidesoft.combobox.ExComboBox
comboBoxSelected, commitEdit, commitEditWithFocusLostBehavior, convertElementToString, convertStringToElement, convertStringToElement, createButtonComponent, customizeDialog, customizeDialogLocation, customizePopup, customizeRendererComponent, delegateKeyStrokes, equals, fireActionEvent, fireItemStateChanged, getActualUIClassID, getConverter, getConverterContext, getDefaultCancelAction, getDefaultOKAction, getDelegateKeyStrokes, getDialogCancelAction, getDialogOKAction, getDownKeyBehavior, getFocusLostBehavior, getPopupCancelBehavior, getPopupLocation, getPopupType, getSelectedItem, getType, getUIComboBoxEditorClassID, getUIComboBoxPopupClassID, getUIComboBoxRendererClassID, installColorFontAndBorder, isButtonOnly, isButtonVisible, isEmptyStringNull, isKeepPopupSize, isPopupVolatile, isReallyFocusLost, isRetrievingValueFromPopup, isStretchToFit, isStretchToFitSet, isUpdateFromPopupOnFly, notifyUser, popupMenuCanceled, processKeyBinding, propertyChange, resetEdit, revertEdit, selectWithKeyChar, setButtonOnly, setButtonVisible, setConverter, setConverterContext, setDownKeyBehavior, setEditable, setEmptyStringNull, setFocusLostBehavior, setKeepPopupSize, setModel, setPopupCancelBehavior, setPopupLocation, setPopupType, setPopupVolatile, setSelectedItem, setSelectedItem, setStretchToFit, setType, undelegateKeyStrokes, updateUI, validateValueForNonEditable
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, setAction, setActionCommand, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setUI, showPopup
 
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, getBaseline, 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, 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

renderer

protected TreeCellRenderer renderer
This protected field is implementation specific. Do not access directly or override. Use the accessor methods instead.

See Also:
getCellRenderer(), setCellRenderer(javax.swing.tree.TreeCellRenderer)

maximumRowCount

protected int maximumRowCount
This protected field is implementation specific. Do not access directly or override. Use the accessor methods instead.

See Also:
getMaximumRowCount(), setMaximumRowCount(int)

_object

protected Object _object

_treeModel

protected TreeModel _treeModel

TREE_MODEL_PROPERTY

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

TreeExComboBox

public TreeExComboBox()

TreeExComboBox

public TreeExComboBox(Object[] objects)
Creates a new TreeComboBox.

Parameters:
objects - the objects

TreeExComboBox

public TreeExComboBox(Vector<?> objects)
Creates a new TreeComboBox.

Parameters:
objects - the objects

TreeExComboBox

public TreeExComboBox(Hashtable<?,?> objects)
Creates a new TreeComboBox.

Parameters:
objects - the objects

TreeExComboBox

public TreeExComboBox(TreeNode root)
Creates a new TreeComboBox.

Parameters:
root - the root node

TreeExComboBox

public TreeExComboBox(TreeNode root,
                      boolean asksAllowsChildren)
Creates a new TreeComboBox.

Parameters:
root - the root node
asksAllowsChildren - the flag indicating if allows children

TreeExComboBox

public TreeExComboBox(TreeModel model)
Creates a new TreeComboBox.

Parameters:
model - the tree model
Method Detail

initComboBox

protected void initComboBox()
Overrides:
initComboBox in class ExComboBox

populateTreePaths

protected List<TreePath> populateTreePaths(JTree tree)

createPopupComponent

public PopupPanel createPopupComponent()
Description copied from class: ExComboBox
Subclass should implement this method to create the actual popup component.

Specified by:
createPopupComponent in class ExComboBox
Returns:
the popup component

createTreeChooserPanel

protected TreeChooserPanel createTreeChooserPanel(TreeModel model)
Creates the TreeChooserPanel. Subclass can override this method to create its own TreeChooserPanel. Below is the default implement of this method.

 TreeChooserPanel panel = new TreeChooserPanel(object) {
      protected void setupTree(final JTree tree) {
          super.setupTree(tree);
          tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                  if (e.getPath() != null && !Boolean.TRUE.equals(tree.getClientProperty(PopupPanel.SELECTED_BY_MOUSE_ROLLOVER)))
 {
                      if (isValidSelection(e.getPath())) {
                          setSelectedObject(item, false);
                          getEditor().setItem(e.getPath());
                          getEditor().selectAll();
                      }
                  }
              }
          });
          TreeComboBox.this.setupTree(tree);
      }
 

protected boolean isValidSelection(TreePath path) { return TreeComboBox.this.isValidSelection(path); } };

Parameters:
model - the tree model
Returns:
TreeChooserPanel.

createTree

protected JTree createTree(TreeModel model)
Creates the tree. By default, we will return null, meaning the default JTree created by TreeChooserPanel will be used. Subclass can override this method to create other types of tree.

Parameters:
model - the tree model.
Returns:
the tree.

setupTree

protected void setupTree(JTree tree)
Setups the JTree for the tree used in the popup panel. You can override this method to customize the JTree.

Parameters:
tree - the JTree instance

setMaximumRowCount

public void setMaximumRowCount(int count)
Sets the maximum number of rows the JComboBox displays. If the number of objects in the model is greater than count, the combo box uses a scrollbar.

Overrides:
setMaximumRowCount in class JComboBox
Parameters:
count - an integer specifying the maximum number of items to display in the list before using a scrollbar description: The maximum number of rows the popup should have

getMaximumRowCount

public int getMaximumRowCount()
Returns the maximum number of items the combo box can display without a scrollbar.

Overrides:
getMaximumRowCount in class JComboBox
Returns:
an integer specifying the maximum number of items that are displayed in the list before using a scrollbar

setCellRenderer

public void setCellRenderer(TreeCellRenderer aRenderer)
Sets the renderer that paints the list items and the item selected from the list in the JComboBox field. The renderer is used if the JComboBox is not editable. If it is editable, the editor is used to render and edit the selected item.

The default renderer displays a string or an icon. Other renderers can handle graphic images and composite items.

To display the selected item, aRenderer.getListCellRendererComponent is called, passing the list object and an index of -1.

Parameters:
aRenderer - the ListCellRenderer that displays the selected item expert: true description: The renderer that paints the item selected in the list.
See Also:
JComboBox.setEditor(javax.swing.ComboBoxEditor)

getCellRenderer

public TreeCellRenderer getCellRenderer()
Returns the renderer used to display the selected item in the JComboBox field.

Returns:
the ListCellRenderer that displays the selected item.

getTree

public JTree getTree()
Gets the underlying JTree. It will return a not null value only when the tree has ever been displayed. If you want to customize the tree, it's better to override createTreeChooserPanel(javax.swing.tree.TreeModel) method and create your own TreeChooserPanel and JTree.

If you want to programmatically set selected row on the JTree, you can use this method. However do not keep the returned value and use it later because combobox may create a new JTree if the popup is volatile.

Please note, this method will show the popup automatically if the combobox itself is showing (isShowing returns true). Otherwise, it could return null if the popup was never shown before.

Returns:
tree

setPopupVisible

public void setPopupVisible(boolean v)
Overrides:
setPopupVisible in class JComboBox

getDelegateTarget

protected JComponent getDelegateTarget(PopupPanel panel)
Overrides:
getDelegateTarget in class ExComboBox

convertElementToString

public String convertElementToString(Object object)
Converts the element from object to string so that i can display in the text field of TreeComboBox. Subclass can override this method to provide one's own conversion.

Overrides:
convertElementToString in class ExComboBox
Parameters:
object - the object
Returns:
the string representing the object.

isValidSelection

protected boolean isValidSelection(TreePath path)
Checks if a given tree path is a valid selection for combobox. By default it always return true, meaning all tree path could be used as a valid value of combo box.Subclass can override this method to limit the valid selection to certain tree path. For example, check if last node in the tree path is leaf node and only allow leaf node to be a valid selection.

Parameters:
path - the tree path
Returns:
true or false.

getTreeModel

public TreeModel getTreeModel()
Gets the tree model that will be used by the tree in the popup.

Returns:
the tree model.

setTreeModel

public void setTreeModel(TreeModel treeModel)
Sets the tree model that will be used by the tree in the popup.

Parameters:
treeModel - the tree model

isDoubleClickExpand

public boolean isDoubleClickExpand()
Get the flag indicating if the mouse double click would expand the tree path instead of just select it.

By default, the flag is false to keep the original behavior. You could set it to true if you want choose leaf node only.

Returns:
true if the mouse double click would expand the tree path. Otherwise false.

setDoubleClickExpand

public void setDoubleClickExpand(boolean doubleClickExpand)
Set the flag indicating if the mouse double click would expand the tree path instead of just select it.

Parameters:
doubleClickExpand - the flag
See Also:
isDoubleClickExpand()

isSearchUserObjectToSelect

public boolean isSearchUserObjectToSelect()
Gets the flag indicating if TreeExComboBox will search all its tree path's userObject to make the selection if the selected object is set to a non-TreePath value.

Returns:
true if searching to select is required. Otherwise false.
Since:
3.4.1
See Also:
setSearchUserObjectToSelect(boolean)

setSearchUserObjectToSelect

public void setSearchUserObjectToSelect(boolean searchUserObjectToSelect)
Sets the flag indicating if TreeExComboBox will search all its tree path's userObject to make the selection if the selected object is set to a non-TreePath value.

By default, the flag is false to improve the performance.

Parameters:
searchUserObjectToSelect - the flag
Since:
3.4.1

JIDE 3.5.15