0

I am creating a RCP application which will display a tree structure. I used the following code for this purpose. But, I need to make the nodes editable. How to do that? Please find the below code which I have written.

public class TreeView extends ViewPart {

    public static final String ID = "TreeProject.project";

    public TreeView() {
    }

    public static ProjectTree mc = new ProjectTree("root");
    public static TreeViewer treeViewer;

    @Override
    public void createPartControl(Composite parent) {

        Composite composite = new Composite(parent, SWT.NONE);
        treeViewer = new TreeViewer(composite);
        Tree tree = treeViewer.getTree();
        tree.setLocation(0, 0);
        tree.setSize(181, 469);

        StyledText styledText = new StyledText(composite, SWT.BORDER);
        styledText.setText("Welcome\"!");
        styledText.setBounds(179, 0, 415, 469);
        treeViewer.setContentProvider(new ProjectContentProvider());
        treeViewer.setInput(getRootNode());
        treeViewer.expandAll();

        System.out.println(tree.getSelection());
    }

    private ProjectTree getRootNode() {
        ProjectTree node0 = new ProjectTree("Node0");
        ProjectTree node1 = new ProjectTree("Node1");
        mc.addChild(node0, "");
        node0.addChild(node1, "");
        return mc;
    }

    @Override
    public void setFocus() {
    }
    }
Srijani Ghosh
  • 3,935
  • 7
  • 37
  • 68
  • What do you mean by 'editable'? Edit the node text? Add / remove nodes? – greg-449 Aug 27 '15 at 12:35
  • Sorry for the wrong impression I ahve given. Editing the text of a node - I ahve done that. I need to remove or add more node under a parent from UI. – Srijani Ghosh Aug 27 '15 at 12:37

1 Answers1

0

You need to use a selection listener on the treeViewer which would give you the node selected. You then have to remove the node object and its children,if any, from the model . Here I see that your model is the object mc. Then call treeViewer.refresh(). Similarly for add .

ssdimmanuel
  • 448
  • 10
  • 29