Sunday, July 28, 2013

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

you should use staticTree variable.... or override onBrowserEvent  method in t instance....

....

    public void onModuleLoad() {

       Tree t = new Tree() {
            @Override
            public void onBrowserEvent(Event event) {
                Element el = event.getEventTarget().cast();
                if (el == null)
                    return;
                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))) {
                                    treeItem.setState(!treeItem.getState());
                                    break;
                                }// end if
                        }// end if
                    }// end for
                    break;
                }// end switch
                super.onBrowserEvent(event);
            }// end onBrowserEvent

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

TreeItem item1 = t.addTextItem("Item 1");
        item1.addTextItem("Item 1 - 1");
        item1.addTextItem("Item 1 - 2");
        item1.setStyleName("parent");
        DOM.getFirstChild(item1.getElement()).addClassName("nocross");

        TreeItem item2 = t.addTextItem("Item 2");
        item2.addTextItem("Item 2 - 1");
        item2.addTextItem("Item 2 - 2");
        item2.setStyleName("parent");
        DOM.getFirstChild(item2.getElement()).addClassName("nocross");


        t.addItem(item1);
        t.addItem(item2);
       
        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element
        RootPanel.get("nameFieldContainer").add(t);
    }


...


--
Vagner Araujo

Orsic.org

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment