Hello Sumit Chandel,

it does not work in hosted mode, with IE7 and Firefox3.
I added no widgets to the tree, only Strings in the Constructor of
TreeItem, my implementation of setDefaults() looked like yours.
So when I run the app (in hosted mode) I can click on "root" and the
branch is opened. If I click on a leaf below the root item, the
controller is called once and performs the Window.alert(item.getText
()); command. Clicking on "moreitems" performs the action like
expected. But if I click once more on moreitems, the event is fired
twice and the branch will be closed and opened again. This behavior
seems weird to me.


Greetings meandi

I tried again in a new project, to ensure that no side effects appear.
Here is the source code:

NavigationView.java

package de.jomawo.tree.client;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.VerticalPanel;

public class NavigationView extends Composite implements
SelectionHandler<TreeItem> {

        // Attribute
        Panel panel = new VerticalPanel();
        Tree tree = new Tree();
        ApplicationController controller = null;

        public NavigationView(ApplicationController controller){
                setDefaults();
                panel.add(tree);
                tree.addSelectionHandler(this);
                initWidget(panel);
                this.controller = controller;
        }

        private void setDefaults(){
                TreeItem root = new TreeItem("root");
                  root.addItem("item0");
                  root.addItem("item1");
                  root.addItem("item2");
                  TreeItem moreItems = new TreeItem("moreitems");
                  moreItems.addItem("moreitems1");
                  moreItems.addItem("moreitems2");
                  moreItems.addItem("moreitems3");
                  root.addItem(moreItems);
                  tree.addItem(root);
        }

        public void onSelection(SelectionEvent<TreeItem> event) {
                TreeItem item = event.getSelectedItem();
                if(item.getChildCount() == 0) {
                        controller.navigationChanged(item);
                }
                else {
                        item.setState(!item.getState());
                        // Window.alert(item.getState());
                }
        }
}

Tree.java

package de.jomawo.tree.client;

import com.google.gwt.core.client.EntryPoint;

public class Tree implements EntryPoint {

        public void onModuleLoad() {
                ApplicationController controller = new ApplicationController();
                RootPanel.get().add(new NavigationView(controller));
        }
}

ApplicationController.java

package de.jomawo.tree.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.TreeItem;

public class ApplicationController {
        public void navigationChanged(TreeItem item){
                Window.alert(item.getText());
        }
}



On 12 Mai, 01:43, Sumit Chandel <[email protected]> wrote:
> Hi meandi,
> I couldn't reproduce the issue you described using the code snippet you
> provided (along with the setDefault() method implementation below.
>
> private void setDefaults(){
>   // Building the tree ...
>   TreeItem root = new TreeItem("root");
>   root.addItem("item0");
>   root.addItem("item1");
>   root.addItem("item2");
>
>   TreeItem moreItems = new TreeItem("moreitems");
>   moreItems.addItem("moreitems1");
>   moreItems.addItem("moreitems2");
>   moreItems.addItem("moreitems3");
>
>   root.addItem(moreItems);
>   tree.addItem(root);
>
> }
>
> Could you provide more details about which browser you were using when you
> encountered this issue? As well as which type of widgets you were adding to
> the Tree when the double-fire error occurred?
>
> Cheers,
> -Sumit Chandel
>
> On Fri, May 8, 2009 at 3:12 AM, meandi <[email protected]> wrote:
>
> > Hi,
>
> > I defined an SelectionHandler to my tree, that will call a method of
> > my controller when the user clicks on a leaf. This part works fine. If
> > the user clicks on a node (with childs) the branch state (of folding)
> > should be changed.There encounters a problem: Clicking/Selecting a
> > leaf fires the event once, clicking on a folded (state false) node
> > fires the event once too. But if the branch is unfolded (state true)
> > the event is fired twice.
> > Is it an error in reasoning or does it still referres to the bug that
> > was fixed in Version 1.1.0?
>
> > I'm working with GWT Version 1.6.4
>
> > sourcecode looks like this:
>
> > public class NavigationView extends Composite implements
> > SelectionHandler<TreeItem> {
>
> >        Panel panel = new VerticalPanel();
> >        Tree tree = new Tree();
> >                Navigation controller = new NavigationController();
>
> >        public NavigationView(){
> >                setDefaults();
> >                panel.add(tree);
> >                tree.addSelectionHandler(this);
> >                initWidget(panel);
> >        }
>
> >        private void setDefaults(){
> >                // Building the tree ...
> >        }
>
> >        public void onSelection(SelectionEvent<TreeItem> event) {
> >                TreeItem item = event.getSelectedItem();
>
> >                if(item.getChildCount() == 0) {
> >                        Window.alert(item.getText());
> >                        //controller.selectionChanged(item);
> >                }
> >                else {
> >                        item.setState(!item.getState());
> >                }
> >        }
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to