Here you can find the source of findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode, Object userObject)
Parameter | Description |
---|---|
userObject | a parameter |
public static DefaultMutableTreeNode findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode, Object userObject)
//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; } }