Hi meandi,
Thanks for the repro code. I was able to reproduce what you're talking
about.

It seems like the double-fire only occurs if a TreeItem was in a previously
open state, and has transitioned from open to close. The double-fire doesn't
occur if instead the previous state was closed and the transition was from
close to open. That said, I'm not sure why the double-fire occurs in the
first case. As I see it, this is probably an issue that needs some fixing.

I've opened Issue #3660 to track and investigate this issue.

Issue #3660:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3660

In the meantime, here is an albeit messy workaround that should get you
running for the time being.

int comingFromSetState = 0;
boolean prevOpenState = true;

public void onSelection(SelectionEvent<TreeItem> event) {
  TreeItem item = event.getSelectedItem();
  if(item.getChildCount() == 0) {
    controller.navigationChanged(item);
  }
  else {
    if(comingFromSetState == 1 && prevOpenState) {
      comingFromSetState++;
    }
    if(comingFromSetState != 2) {
      comingFromSetState++;
      item.setState(!item.getState());
      prevOpenState = !item.getState();

    } else {
      comingFromHere = 0;
      prevOpenState = true;
    }
  }
}

Hope that helps,
-Sumit Chandel

On Wed, May 13, 2009 at 3:18 AM, meandi <[email protected]> wrote:

>
> 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