Announcement

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

    clickHandler problem on adding and removing standard GWT panels

    Hi,
    I'm quite new in smartgwt and i have some troubles with registering clickHandler on IButton added to panels which I then show and hide depending on what panel I need.
    The problem is that only last registered clickHandler works properly.
    I uploaded attachement with sample code (I know it's ugly written, but I made it only to show the problem)

    Can anyone help me with this problem?

    Here's the code:
    Code:
    package com.test.testevent.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.ClickListener;
    import com.google.gwt.user.client.ui.HorizontalPanel;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.VerticalPanel;
    import com.google.gwt.user.client.ui.Widget;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    
    public class TestClass implements EntryPoint
    {
    
        public void onModuleLoad()
        {
            final VerticalPanel vMainPanel = new VerticalPanel();
            final HorizontalPanel hMenuPanel = new HorizontalPanel();
            final HorizontalPanel hContainerPanel = new HorizontalPanel();
            
            final VerticalPanel  vPanel1 = new VerticalPanel();
            IButton iButton1 = new IButton();
            iButton1.setTitle("button on panel 1");
            iButton1.addClickHandler(new ClickHandler()
            {
                public void onClick(ClickEvent event)
                {
                    Window.alert("Hello world FlexTable 1!!");
                }
            });
            vPanel1.add(iButton1);
            
            final VerticalPanel vPanel2 = new VerticalPanel();
            IButton iButton2 = new IButton();
            iButton2.setTitle("button on panel 2");
            iButton2.addClickHandler(new ClickHandler()        
            {
                public void onClick(ClickEvent event)
                {
                    Window.alert("Hello world from VerticalPanel 2 !!");
                }
            });
            vPanel2.add(iButton2);
            
            
            Button button1 = new Button("panel 1");
            Button button2 = new Button("panel 2");
    
            
            button1.addClickListener(new ClickListener(){
                public void onClick(Widget sender)
                {
                    for(int i = 0;i < hContainerPanel.getWidgetCount(); i++){
                        hContainerPanel.remove(i);
                    }
                    hContainerPanel.add(vPanel1);
                }
            });
            
            button2.addClickListener(new ClickListener(){
                public void onClick(Widget sender)
                {
                    for(int i = 0;i < hContainerPanel.getWidgetCount(); i++){
                        hContainerPanel.remove(i);
                    }
                    hContainerPanel.add(vPanel2);
                }
            });
            
            hMenuPanel.add(button1);
            hMenuPanel.add(button2);
            
            vMainPanel.add(hMenuPanel);
            vMainPanel.add(hContainerPanel);
            
            RootPanel.get().add(vMainPanel);
        }
        
    }
    Attached Files
    Last edited by b0b3k; 26 Mar 2009, 01:33.

    #2
    Any news on this issue? Or should I report this as a bug?

    Comment


      #3
      This my well be a bug (haven't tried to run it), however, the recommendation is not to mix components where you don't have to. Search the forums for "interoperability" for a few notes on this and why it makes sense.

      Comment


        #4
        Hi,
        I'm still trying to somehow integrate standard gwt and gwtsmart, because I need some of standard GWT functionality, but I still have some troubles. I now use HLayout and VLayout.
        On first initialization all buttons are visible, but after removeMember only iButton is visible. (standard button does not appear).

        What am I doing wrong? Or, what's the best practice to deal with switching between two or more panels/layouts ?

        Here's the code:
        Code:
        public class TestClass implements EntryPoint
        {
        
            public void onModuleLoad()
            {
                final VLayout vMainPanel = new VLayout();
                final HLayout hMenuPanel = new HLayout();
                final HLayout hContainerPanel = new HLayout();
                
                VLayout  vPanel1 = new VLayout();
                IButton iButton1 = new IButton();
                iButton1.setTitle("button on panel 1");
                iButton1.setWidth(200);
                
                iButton1.addClickHandler(new ClickHandler()
                {
                    public void onClick(ClickEvent event)
                    {
                        Window.alert("Hello world FlexTable 1!!");
                    }
                });
                Button gwtButton1 = new Button("GWT Button 1");
                gwtButton1.addClickListener(new ClickListener(){
        
                    public void onClick(Widget sender)
                    {
                    Window.alert("GWT BUTTON - 1");
                    }
                });
                vPanel1.addMember(iButton1);
                vPanel1.addMember(gwtButton1);
                vPanel1.setHeight(500);
                final VLayout tmp1 = vPanel1;
                
                final VLayout vPanel2 = new VLayout();
                IButton iButton2 = new IButton();
                iButton2.setTitle("button on panel 2");
                iButton2.setID("iButton2");
                iButton2.setWidth(200);
                iButton2.addClickHandler(new ClickHandler()        
                {
                    public void onClick(ClickEvent event)
                    {
                        Window.alert("Hello world from VLayout 2 !!");
                    }
                });
                Button gwtButton2 = new Button("GWT button 2");
                gwtButton2.addClickListener(new ClickListener(){
        
                    public void onClick(Widget sender)
                    {
                    Window.alert("GWT BUTTON - 2");
                    }
                });
                vPanel2.addMember(iButton2);
                vPanel2.addMember(gwtButton2);
                final VLayout tmp2 = vPanel2;
                
                Button button1 = new Button("show layer 1");
                Button button2 = new Button("show layer 2");
        
                
                button1.addClickListener(new ClickListener(){
                    public void onClick(Widget sender)
                    {
                        hContainerPanel.removeMember(tmp2); 
                        hContainerPanel.addMember(tmp1);
                    }
                });
                
                button2.addClickListener(new ClickListener(){
                    public void onClick(Widget sender)
                    {
                        hContainerPanel.removeMember(tmp1); 
                        hContainerPanel.addMember(tmp2);
                    }
                });
                
                hMenuPanel.addMember(button1);
                hMenuPanel.addMember(button2);
                
                vMainPanel.addMember(hMenuPanel);
                vMainPanel.addMember(hContainerPanel);
        
                
                RootPanel.get().add(vMainPanel);
            }

        Comment


          #5
          Your mix of buttons is necessarily going to have tabOrder issues. Is there really some reason you need to use a plain GWT button?

          Comment


            #6
            The main problem was that I already have working aplication framework made in plain gwt (whith a little help from book - Google Web Toolkit Applications (Prentice Hall, 2008) ) and I just wanted to add smartgwt grid as a widget or component on that framework.
            The problem is with custom tab (made with plain gwt components (4 tabs)) when on only one tab your Listgrid has proper functionality and that is the one which is last initialized.

            PS
            How can I contact forum admin for some forum questions/troubles?
            Last edited by b0b3k; 26 Mar 2009, 01:40.

            Comment


              #7
              Old thread but I came across it when I had this issue so just in case anyone else comes across this.

              It is not unbelievable that you need to migrate bit by bit, I overcame this problem with a deadline fast approaching by doing the following.

              1. Probably best to extend your smartGWT widget and sink click events manually
              Code:
              class InterimLabel extends Label {
              
                      public InterimLabel () {
                          super();
                          sinkEvents(Event.ONCLICK);
                      }
              }
              2. Override your widgets onBrowserEvent()
              Code:
                 public void onBrowserEvent(Event event) {
                          super.onBrowserEvent(event);
                          if (event.getTypeInt() == Event.ONCLICK) {
                            //do what you need to do here
                          }
                      }
              I tried to implement GWT's HasClickHandlers but I could not get it to work so I got around this by passing a Command (simple interface with an execute method) into the Label and calling execute on that in onBrowserEvent().
              Code:
               public void onBrowserEvent(Event event) {
                          super.onBrowserEvent(event);
                          if (event.getTypeInt() == Event.ONCLICK) {
                              if (onClickCommand != null) {
                                  onClickCommand.execute();
                              }
                          }
                      }
              you might also want to override your addClickHandler method to do :
              Code:
              @Override
                      public HandlerRegistration addClickHandler(com.smartgwt.client.widgets.events.ClickHandler handler) {
                          throw new RuntimeException("Due to the mixing of smartGWT and GWT, normal click handlers do not work reliably here, pass a command to setOnClickCommand instead.");
                      }
              It is not a long term solution but should get you through.

              Comment

              Working...
              X