SWT/JFace控件中最复杂的应该是TreeViewer吧,每次要实现一个TreeViewer都得想半天,这回发现JFace本身包含一个TreeNode(org.eclipse.jface.viewers.TreeNode)和TreeNodeContentProvider(org.eclipse.jface.viewers.TreeNodeContentProvider)的实现,参考写了一个基本通用的示例。
TreeNode:
import java.util.ArrayList;
import java.util.List;
public abstract class TreeNode {
protected TreeNode parent;
protected List
children = new ArrayList
();
public abstract String getName();
public abstract void setName(String name);
public TreeNode getParent() {
return parent;
}
public void setParent(TreeNode parent) {
this.parent = parent;
}
public TreeNode[] getChildren() {
return (TreeNode[]) children.toArray(new TreeNode[children.size()]);
}
public void setChildren(List
children) {
this.children = children;
}
public boolean hasChildre