Java 如何在RCP3.x中将子节点添加到TreeViewer的选定节点
[工作]我有一个预定义的treeviewer,在这里我可以动态地将节点添加到树中,并在最后追加节点 如果选择一个节点并添加一个新节点,则该新节点应作为子节点附加到选定节点。有人能帮我吗 我的工作代码片段 getRootNode() 类项目树Java 如何在RCP3.x中将子节点添加到TreeViewer的选定节点,java,eclipse-rcp,jface,rcp,treeviewer,Java,Eclipse Rcp,Jface,Rcp,Treeviewer,[工作]我有一个预定义的treeviewer,在这里我可以动态地将节点添加到树中,并在最后追加节点 如果选择一个节点并添加一个新节点,则该新节点应作为子节点附加到选定节点。有人能帮我吗 我的工作代码片段 getRootNode() 类项目树 公共类项目树{ 私有字符串名称; private ArrayList children=new ArrayList(); 私有项目树父级; 私有字符串文件路径; 公共项目树(字符串n){ name=n; } 公共项目树addChild(项目树子级,字符串文件
公共类项目树{
私有字符串名称;
private ArrayList children=new ArrayList();
私有项目树父级;
私有字符串文件路径;
公共项目树(字符串n){
name=n;
}
公共项目树addChild(项目树子级,字符串文件路径){
添加(child);
child.parent=这个;
child.filepath=文件路径;
child.name=child.name;
System.out.println(“Children:+Children”);
归还这个;
}
}
对结构的更改必须在查看器的内容提供程序中完成。我将结合使用EditingSupport和ICellEditorListener。它将在所选节点中放置一个单元格编辑器,用户键入任何内容,然后您可以任意处理输入treeviewer是经典的MVC设计模式视图。将子对象添加到模型中。
add.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Shell dShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
ShowDialog1 dialog = new ShowDialog1(dShell);
dialog.create();
if (dialog.open() == Window.OK) {
first = dialog.getFirstName();
treeViewer.setInput(getRootNode(first));
}
}
});
public static ProjectTree mc = new ProjectTree("root");
private static ProjectTree getRootNode(String first) {
ProjectTree node1 = new ProjectTree(first);
mc.addChild(node1, "");
return mc;
}
public class ProjectTree {
private String name;
private ArrayList<ProjectTree> children = new ArrayList<ProjectTree>();
private ProjectTree parent;
private String filepath;
public ProjectTree(String n) {
name = n;
}
public ProjectTree addChild(ProjectTree child, String filepath) {
children.add(child);
child.parent = this;
child.filepath = filepath;
child.name = child.name;
System.out.println("Children : " + children);
return this;
}
}