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 :

((ITreeContentProvider)fViewer.getContentProvider()).getElements

    (fViewer.getInput())) {

   for (Object contents : ((ITreeContentProvider) 

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

                if (((ITreeContentProvider) 

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

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

 contents.toString());

                fViewer.expandToLevel(contents, 

AbstractTreeViewer.ALL_LEVELS);
        }   

The code below is about the node model:

package model;

import java.io.File;
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){
        this.name = name;
        this.path = path;
    }
    public void setName(String name) {
        this.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);
        System.out.println("获取当前文件夹********************"+path);
        File[] fs = file.listFiles();
        children = new ArrayList();
        if(fs != null){
        for(File f : fs){
            if(f.exists()){             
                children.add(new LocalFileDir(path+"/"+f.getName(),            f.getName()));
        }
    }
    }
    return children;
}

}


Source: eclipse

Leave a Reply