@Test public void testGetTreePathForSelection() { RepositoryTreeModel treeModel = new RepositoryTreeModel(); assertNotNull( treeModel ); treeModel.setFileSystemRoot( repositoryRoot ); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn( childFiles ).when( repositoryRoot ).getChildren(); doReturn( childFileName1 ).when( childFile1 ).getName(); doReturn( childFileName2 ).when( childFile2 ).getName(); doReturn( childFileName3 ).when( childFile3 ).getName(); doReturn( repositoryRoot ).when( childFile1 ).getParent(); doReturn( repositoryRoot ).when( childFile2 ).getParent(); doReturn( repositoryRoot ).when( childFile3 ).getParent(); TreePath path = treeModel.getTreePathForSelection( childFile2, null ); assertEquals( 2, path.getPath().length ); assertEquals( childFile2, path.getLastPathComponent() ); } catch ( FileSystemException e ) { e.printStackTrace(); } }
public TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ) throws FileSystemException { if ( root.getRoot() == null ) { return null; } if ( root.getRoot().equals( selectedFolder ) ) { return new TreePath( root ); } final LinkedList<Object> list = new LinkedList<Object>(); while ( selectedFolder != null ) { list.add( 0, selectedFolder ); final FileObject parent = selectedFolder.getParent(); if ( selectedFolder.equals( parent ) ) { break; } if ( root.getRoot().equals( parent ) ) { break; } selectedFolder = parent; } list.add( 0, root ); return new TreePath( list.toArray() ); }
RepositoryTreeModel implements TreeModel { public TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ) throws FileSystemException { if ( root.getRoot() == null ) { return null; } if ( root.getRoot().equals( selectedFolder ) ) { return new TreePath( root ); } final LinkedList<Object> list = new LinkedList<Object>(); while ( selectedFolder != null ) { list.add( 0, selectedFolder ); final FileObject parent = selectedFolder.getParent(); if ( selectedFolder.equals( parent ) ) { break; } if ( root.getRoot().equals( parent ) ) { break; } selectedFolder = parent; } list.add( 0, root ); return new TreePath( list.toArray() ); } }
RepositoryTreeModel implements TreeModel { public TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ) throws FileSystemException { if ( root.getRoot() == null ) { return null; } if ( root.getRoot().equals( selectedFolder ) ) { return new TreePath( root ); } final LinkedList<Object> list = new LinkedList<Object>(); while ( selectedFolder != null ) { list.add( 0, selectedFolder ); final FileObject parent = selectedFolder.getParent(); if ( selectedFolder.equals( parent ) ) { break; } if ( root.getRoot().equals( parent ) ) { break; } selectedFolder = parent; } list.add( 0, root ); return new TreePath( list.toArray() ); } RepositoryTreeModel();  RepositoryTreeModel( final FileObject repositoryRoot, final String[] filters, final boolean showFoldersOnly ); }
RepositoryTreeModel implements TreeModel { public TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ) throws FileSystemException { if ( root.getRoot() == null ) { return null; } if ( root.getRoot().equals( selectedFolder ) ) { return new TreePath( root ); } final LinkedList<Object> list = new LinkedList<Object>(); while ( selectedFolder != null ) { list.add( 0, selectedFolder ); final FileObject parent = selectedFolder.getParent(); if ( selectedFolder.equals( parent ) ) { break; } if ( root.getRoot().equals( parent ) ) { break; } selectedFolder = parent; } list.add( 0, root ); return new TreePath( list.toArray() ); } RepositoryTreeModel();  RepositoryTreeModel( final FileObject repositoryRoot, final String[] filters, final boolean showFoldersOnly ); void setShowFoldersOnly( final boolean showFoldersOnly ); boolean isShowFoldersOnly(); boolean isShowHiddenFiles(); void setShowHiddenFiles( final boolean showHiddenFiles ); String[] getFilters(); void setFilters( final String[] filters ); FileObject getFileSystemRoot(); void setFileSystemRoot( final FileObject root ); Object getRoot(); Object getChild( Object parent, final int index ); int getChildCount( Object parent ); boolean isLeaf( final Object node ); void valueForPathChanged( final TreePath path, final Object newValue ); int getIndexOfChild( Object parent, final Object childNode ); void addTreeModelListener( final TreeModelListener l ); void removeTreeModelListener( final TreeModelListener l ); void fireTreeDataChanged(); TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ); static FileObject findNodeByName( final FileObject node, final String name ); }
RepositoryTreeModel implements TreeModel { public TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ) throws FileSystemException { if ( root.getRoot() == null ) { return null; } if ( root.getRoot().equals( selectedFolder ) ) { return new TreePath( root ); } final LinkedList<Object> list = new LinkedList<Object>(); while ( selectedFolder != null ) { list.add( 0, selectedFolder ); final FileObject parent = selectedFolder.getParent(); if ( selectedFolder.equals( parent ) ) { break; } if ( root.getRoot().equals( parent ) ) { break; } selectedFolder = parent; } list.add( 0, root ); return new TreePath( list.toArray() ); } RepositoryTreeModel();  RepositoryTreeModel( final FileObject repositoryRoot, final String[] filters, final boolean showFoldersOnly ); void setShowFoldersOnly( final boolean showFoldersOnly ); boolean isShowFoldersOnly(); boolean isShowHiddenFiles(); void setShowHiddenFiles( final boolean showHiddenFiles ); String[] getFilters(); void setFilters( final String[] filters ); FileObject getFileSystemRoot(); void setFileSystemRoot( final FileObject root ); Object getRoot(); Object getChild( Object parent, final int index ); int getChildCount( Object parent ); boolean isLeaf( final Object node ); void valueForPathChanged( final TreePath path, final Object newValue ); int getIndexOfChild( Object parent, final Object childNode ); void addTreeModelListener( final TreeModelListener l ); void removeTreeModelListener( final TreeModelListener l ); void fireTreeDataChanged(); TreePath getTreePathForSelection( FileObject selectedFolder, final String selection ); static FileObject findNodeByName( final FileObject node, final String name );  }