Sunday, July 28, 2013

Re: GWT - Tree - Replace the cross event by clicking on the parent item

thank you for your help, the cross disappeared, but nothing happens when I click on the parent menu, the menu does open.
Here is my code:

    public void onModuleLoad() {
        Tree staticTree = new Tree() {
            public void onBrowserEvent(Event event) {
                Element el = event.getEventTarget().cast();
                if (el == null)
                switch (event.getTypeInt()) {
                case Event.ONCLICK:
                    for (int i = 0; i < getItemCount(); i++) {
                        TreeItem treeItem = getItem(i);
                        TableElement table = getTableElement(treeItem);
                        if (table != null) {
                            NodeList<Element> nodeList = table.getElementsByTagName("div");
                            if (nodeList.getLength() > 0)
                                if (el.equals(nodeList.getItem(0))) {
                                }// end if
                        }// end if
                    }// end for
                }// end switch
            }// end onBrowserEvent

            private final TableElement getTableElement(TreeItem treeItem) {
                return (TableElement) treeItem.getElement().getFirstChildElement();
            }// end getTableElement

        TreeItem item1 = staticTree.addTextItem("Item 1");

        item1.addTextItem("Item 1 - 1");
        item1.addTextItem("Item 1 - 2");

        TreeItem item2 = staticTree.addTextItem("Item 2");

        item2.addTextItem("Item 2 - 1");
        item2.addTextItem("Item 2 - 2");

        Tree t = new Tree();
        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element

Le dimanche 28 juillet 2013 13:12:25 UTC+2, michelin pierre a écrit :

Hello, I want to replace the cross event by clicking on the parent item: It is possible to open the menu on click on the treeitem parent (like click on the little cross on the left)?

Concretely in the example below, by clicking on "Item 1" will open the menu, by clicking a second time closes the menu.

Is there a solution?

String[] composers = new String[]{"Item 1","Item 2","Item 3"};    Resources treeResource = GWT.create(TreeResources.class);     Tree staticTree = new Tree(treeResource);    TreeItem item1 = staticTree.addTextItem(composers[0]);              TreeItem item2 = staticTree.addTextItem(composers[1]);    // add sub items  addItemSection(item1, "item 1 - 1",new String[]{});  addItemSection(item1, "item 1 - 2", new String[]{});    addItemSection(item2, "item 2 - 1",new String[]{});  addItemSection(item2, "item 2 - 2", new String[]{});  addItemSection(item2, "item 2 - 3", new String[]{});    TreeItem item = new TreeItem();  item1.addItem(item);  item2.addItem(item);    Tree t = new Tree();  t.addItem(item1);  t.addItem(item2);    private void addItemSection(TreeItem parent, String label, String[] composerWorks)   {     TreeItem section = parent.addTextItem(label);               for (String work : composerWorks) {      section.addTextItem(work);     }  }

The result:

  + Item 1
Item 1-1

ANd it would be nice if could hide the cross in the left.

Thanks in advance

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment