How to expand a specific node in TreeViewer(org.eclipse.jface)

I have a jFace treeViewer. I want to expand a particular node in that.And I kown there has a function ExpandToLevel(),but i do not know how to use it,this problem has disturbed me serveral days.

In addition, i am a Chinese student,so my English is poor,but i hope the question is clear.Thanks!

The code below,I do not know where is the problem,The tree did not expand at all.

for (Object item :


    (fViewer.getInput())) {

   for (Object contents : ((ITreeContentProvider) 

    fViewer.getContentProvider()).getChildren(item)) {

                if (((ITreeContentProvider) 

fViewer.getContentProvider()).getChildren(contents) != null)

                    System.out.println("the content is :" + 




The code below is about the node model:

package model;

import java.util.ArrayList;
import java.util.List;

public class LocalFileDir {
    private String name;
    private List children;
    private String path;
    public LocalFileDir(String path, String name){ = name;
        this.path = path;
    public void setName(String name) { = name;
    public String getName() {
        return name;

    public String getPath(){
         return path;
    public void setChildren(List children) {
        this.children = children;

    public List getChildren() {
        File file = new File(path);
        File[] fs = file.listFiles();
        children = new ArrayList();
        if(fs != null){
        for(File f : fs){
                children.add(new LocalFileDir(path+"/"+f.getName(),            f.getName()));
    return children;


Source: eclipse

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.