public static TreePath translatePath ( TreeModel newTreeModel , TreePath oldPath , BiPredicate < Object , Object > equality ) { Object newRoot = newTreeModel . getRoot ( ) ; List < Object > newPath = new ArrayList < Object > ( ) ; newPath . add ( newRoot ) ; Object newPreviousElement = newRoot ; for ( int i = 1 ; i < oldPath . getPathCount ( ) ; i ++ ) { Object oldElement = oldPath . getPathComponent ( i ) ; Object oldUserObject = getUserObjectFromTreeNode ( oldElement ) ; Object newElement = getChildWith ( newPreviousElement , oldUserObject , equality ) ; if ( newElement == null ) { return null ; } newPath . add ( newElement ) ; newPreviousElement = newElement ; } return new TreePath ( newPath . toArray ( ) ) ; }
Translates one TreePath to a new TreeModel . This methods assumes DefaultMutableTreeNodes and identifies the path based on the equality of user objects using the given equality predicate .