Java JTree Node findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode, Object userObject)

Here you can find the source of findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode, Object userObject)

Description

This method will traverse the sub-tree whose root is itself and including itself to find a tree Node whose userObject matches the given one.

License

BSD License

Parameter

Parameter Description
userObject a parameter

Return

the default mutable tree node matching the given object.

Declaration

public static DefaultMutableTreeNode findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode,
        Object userObject) 

Method Source Code


//package com.java2s;
/*L//  w w  w.j  av  a 2s .  com
 *  Copyright Ekagra Software Technologies Ltd.
 *  Copyright SAIC, SAIC-Frederick
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/cacore-sdk/LICENSE.txt for details.
 */

import javax.swing.tree.DefaultMutableTreeNode;

public class Main {
    /**
     * This method will traverse the sub-tree whose root is itself and including itself to
     * find a tree Node whose userObject matches the given one. If none is found, return null.
     * @param userObject
     * @return the default mutable tree node matching the given object.
     */
    public static DefaultMutableTreeNode findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode,
            Object userObject) {
        /*Object selfUserObject = treeNode.getUserObject();
        if(selfUserObject!=null && selfUserObject instanceof ElementMetaLoader.MyTreeObject)
           selfUserObject = ((ElementMetaLoader.MyTreeObject)selfUserObject).getUserObject();
        boolean boolEquals = selfUserObject==null? userObject==null : selfUserObject.equals(userObject);
        if(boolEquals)
        {
           return treeNode;
        }
        else
        {
           DefaultMutableTreeNode foundTarget = null;
           int childCount = treeNode.getChildCount();
           for(int i=0; i<childCount; i++)
           {
        foundTarget = null;
        Object obj = treeNode.getChildAt(i);
        if(obj instanceof DefaultMappableTreeNode)
        {
           DefaultMappableTreeNode childNode = (DefaultMappableTreeNode) obj;
           foundTarget = findFirstTreeNodeMatchUserObject(childNode, userObject);
           if(foundTarget!=null)
           {
          break;
           }
        }
           }
           return foundTarget;
        }*/
        return null;
    }
}

Related

  1. expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot)
  2. expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)
  3. expandTree(final JTree tree, final DefaultMutableTreeNode node)
  4. expandTreeRecurser(JTree tree, DefaultMutableTreeNode node)
  5. export(File file, DefaultMutableTreeNode node)
  6. findTreeNodesWithLowestLevel(List multipleTreeNodes)
  7. findTreeNodeWithXmlPath(DefaultMutableTreeNode treeNode, String nodeXmlPath)
  8. getAllChildCount(TreeNode node)
  9. getAllTreeNodes(TreeModel model, int startLevel, Class clazz, DefaultMutableTreeNode root)