Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TabSet onTabSelected event firing when no tab is selected?

    SC_SNAPSHOT-2011-01-06/PowerEdition Deployment 2011-01-06
    GWT 1.7.1
    IE 7 Dev Console

    Perhaps I'm not doing something correctly, but the TabSelected event is firing when there is no tab selected. Below I am simply assembling a TabSet but not explicitly selecting a Tab:
    Code:
    public MainEntryPoint() {
        }
    
        private TabSet tabSet;
    
        public void onModuleLoad() {
            HLayout layout = new HLayout();  
            layout.setWidth(300);
            layout.setHeight(200);
            layout.setMembersMargin(20);
    
            tabSet = new TabSet();
            tabSet.setTabBarPosition(Side.TOP);
            tabSet.setWidth100();
            tabSet.setHeight100();
            tabSet.setTabBarThickness(22);
    
            Tab manager = new Tab("one");
            Tab broker = new Tab("two");
            Tab stock = new Tab("three");
            Tab multi = new Tab("four");
            Tab none = new Tab("none");
    
            tabSet.addTab(manager);  //0
            tabSet.addTab(broker);   //1
            tabSet.addTab(stock);    //2
            tabSet.addTab(multi);    //3
            tabSet.addTab(none);        //4
    
            VLayout spacer1 = new VLayout();
            spacer1.setWidth("10px");
    
            tabSet.setTabBarControls(TabBarControls.TAB_SCROLLER, TabBarControls.TAB_PICKER);
    
            tabSet.addTabSelectedHandler(tabSetTabSelectedHandler);
    
            layout.addMember(tabSet);
            layout.draw();
        }
    
        private TabSelectedHandler tabSetTabSelectedHandler = new TabSelectedHandler() {
    
            public void onTabSelected(TabSelectedEvent event) {
                GWT.log("TabSelectedHandler.onTabSelected:" + event.getTab().getTitle(), null);
            }
        };
    You can see the output of the Dev Console with my debug statements:
    Code:
    [INFO] TabSelectedHandler.onTabSelected:one

    #2
    Expected: the first tab becomes selected as the TabSet draws.

    Comment


      #3
      To follow up on this example, I added a button to actually select the first tab, and now the event does not fire:

      Code:
      private TabSet tabSet;
      
          public void onModuleLoad() {
              HLayout layout = new HLayout();  
              layout.setWidth(300);
              layout.setHeight(200);
              layout.setMembersMargin(20);
      
              tabSet = new TabSet();
              tabSet.setTabBarPosition(Side.TOP);
              tabSet.setWidth100();
              tabSet.setHeight100();
              tabSet.setTabBarThickness(22);
      
              Tab manager = new Tab("one");
              Tab broker = new Tab("two");
              Tab stock = new Tab("three");
              Tab multi = new Tab("four");
              Tab none = new Tab("none");
      
              tabSet.addTab(manager);  //0
              tabSet.addTab(broker);   //1
              tabSet.addTab(stock);    //2
              tabSet.addTab(multi);    //3
              tabSet.addTab(none);        //4
      
              VLayout spacer1 = new VLayout();
              spacer1.setWidth("10px");
      
              tabSet.setTabBarControls(TabBarControls.TAB_SCROLLER, TabBarControls.TAB_PICKER);
      
              tabSet.addTabSelectedHandler(tabSetTabSelectedHandler);
      
              IButton button = new IButton("ClickMe");
              button.addClickHandler(new ClickHandler() {
      
                  public void onClick(ClickEvent event) {
                      GWT.log("selecting tabSet.selectTab(0)", null);
                      tabSet.selectTab(0);
                  }
              });
      
              layout.addMember(tabSet);
              layout.addMember(button);
              layout.draw();
      
          }
      
          private TabSelectedHandler tabSetTabSelectedHandler = new TabSelectedHandler() {
      
              public void onTabSelected(TabSelectedEvent event) {
                  GWT.log("TabSelectedHandler.onTabSelected:" + event.getTab().getTitle(), null);
              }
          };
      Here is my Dev Console output:
      Code:
      [INFO] TabSelectedHandler.onTabSelected:one
      [INFO] selecting tabSet.selectTab(0)
      After pushing the button, I am explicitly selecting the first tab, and the onTabSelected event does not fire?

      Comment


        #4
        It is already selected.

        This API is designed around dynamic construction of the tab pane. Look at it that way and you'll see it's firing at just the right times.

        Comment


          #5
          So when the first Tab is added to the TabSet, that first tab added will fire the event?

          Comment


            #6
            Not necessarily. Again, the first tab becomes selected as the TabSet draws. If you are adding a series of tabs to an undrawn TabSet, TabSelected doesn't fire.

            Comment


              #7
              Ok, that clarifies things. I need to setup my TabSet before it is drawn, it is the drawing of the TabSet that fires the onTabSelected event.

              Comment


                #8
                You could try adding the tab selected handler in a TabSet.addDrawHandler(..)

                Comment

                Working...
                X