Announcement

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

    Strange bug when using ButtonItem + FormItemIcon in 5.1p

    Hi Isomorphic,

    please see this no-DataSource 5.1p testcase (tested with v10.1p_2017-03-02 in FF26 Dev Mode).

    Observations:
    1. with FormItemIcon:
      1. The empty area next to the ButtonItem acts like the FormItemIcon when clicked (unexpected)
      2. The button itself also triggers the FormItemIcon clickhandler (see Developer Console log) (unexpected)
    2. without FormItemIcon:
      1. (OK)
    3. without FormItemIcon attached:
      1. Like "with FormItemIcon". This is really strange, as the FormItemIcon is not used and if you simplify the code, Eclipse will even warn that FormItemIcon is not used?!? (unexpected)
    I have the behavior of 1) also in my application.

    BuiltInDS.java:
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ButtonItem;
    import com.smartgwt.client.widgets.form.fields.FormItemIcon;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS implements EntryPoint {
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            VLayout mainLayout = new VLayout(20);
            mainLayout.setWidth100();
            mainLayout.setHeight100();
    
            {
                IButton btn = new IButton("Recreate with FormItemIcon");
                btn.setWidth(300);
                btn.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        recreate(true);
                    }
                });
                mainLayout.addMember(btn);
            }
            {
                IButton btn = new IButton("Recreate without FormItemIcon");
                btn.setWidth(300);
                btn.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        recreate(false);
                    }
                });
                mainLayout.addMember(btn);
            }
            {
                IButton btn = new IButton("Recreate without FormItemIcon attached");
                btn.setWidth(300);
                btn.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        recreate(null);
                    }
                });
                mainLayout.addMember(btn);
            }
            recreate(true);
            mainLayout.draw();
        }
    
        private void recreate(Boolean withFormItemIcon) {
            Window w = new Window();
            w.setWidth("95%");
            w.setHeight("95%");
            w.setMembersMargin(0);
            w.setModalMaskOpacity(70);
            w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
            w.setTitle("ButtonItem-Titlearea acts like FormItemIcon" + w.getTitle());
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            w.addItem(new DynamicFormClearViewState(withFormItemIcon));
            w.show();
        }
    
        private final class DynamicFormClearViewState extends DynamicForm {
            public DynamicFormClearViewState(Boolean withFormItemIcon) {
                super();
                setIsGroup(true);
                setGroupTitle("To see DynamicForm dimensions");
                setWidth(400);
    
                final ButtonItem clearViewStateButton = new ButtonItem("TEST", "Testbutton");
                clearViewStateButton.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
                    @Override
                    public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
                        SC.say("Button clicked");
                        SC.logWarn("Button clicked");
                    };
                });
                clearViewStateButton.setWidth(190);
                clearViewStateButton.setAlign(Alignment.RIGHT);
    
                if (withFormItemIcon == null || withFormItemIcon == true) {
                    FormItemIcon helperIcon = new FormItemIcon() {
                        {
                            setSrc("http://www.famfamfam.com/lab/icons/silk/icons/sport_soccer.png");
                            setTooltip("Explanation");
                            addClickHandler(new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent event) {
                                    SC.say("Explanation");
                                    SC.logWarn("FormItemIcon clicked");
                                }
                            });
                        }
                    };
                    if (withFormItemIcon != null && withFormItemIcon == true)
                        clearViewStateButton.setIcons(helperIcon);
                }
                setFields(clearViewStateButton);
            }
        }
    }
    Best regards
    Blama

    #2
    When you call ButtonItem.addClickHandler(), this is the same as FormItem.addClickHandler(), so it's expected that you'll get fired for a click anywhere on the item, including the icons and empty space. It looks like no one's ever noticed or reported this since they don't use FormItemIcons with ButtonItem.

    For the next release, we'll add a separate event just for the Button-as-such and add docs that clarify the distinction. In the meantime, if you are using icons and want a button-only click event, you could just check if the mouse is currently over the button-as-such.

    Comment


      #3
      Hi Isomorphic,

      because especially case#3 was so strange I revisited. It seems there is everything all right today.
      The problem was nesting anonymous classes, where the 2nd addClickHandler() did not target FormItemIcon-anonymous subclass, as I wanted it to, but some outer item, perhaps the DynamicForm itself.
      It works if you move the anonymous class to a nested private one, see the code:
      Code:
      package com.smartgwt.sample.client;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.smartgwt.client.Version;
      import com.smartgwt.client.core.KeyIdentifier;
      import com.smartgwt.client.types.Alignment;
      import com.smartgwt.client.util.Page;
      import com.smartgwt.client.util.PageKeyHandler;
      import com.smartgwt.client.util.SC;
      import com.smartgwt.client.widgets.IButton;
      import com.smartgwt.client.widgets.Window;
      import com.smartgwt.client.widgets.events.ClickEvent;
      import com.smartgwt.client.widgets.events.ClickHandler;
      import com.smartgwt.client.widgets.form.DynamicForm;
      import com.smartgwt.client.widgets.form.fields.ButtonItem;
      import com.smartgwt.client.widgets.form.fields.FormItemIcon;
      import com.smartgwt.client.widgets.form.fields.events.FormItemClickHandler;
      import com.smartgwt.client.widgets.form.fields.events.FormItemIconClickEvent;
      import com.smartgwt.client.widgets.layout.VLayout;
      
      public class BuiltInDS implements EntryPoint {
          public void onModuleLoad() {
              KeyIdentifier debugKey = new KeyIdentifier();
              debugKey.setCtrlKey(true);
              debugKey.setKeyName("D");
      
              Page.registerKey(debugKey, new PageKeyHandler() {
                  public void execute(String keyName) {
                      SC.showConsole();
                  }
              });
      
              VLayout mainLayout = new VLayout(20);
              mainLayout.setWidth100();
              mainLayout.setHeight100();
      
              {
                  IButton btn = new IButton("Recreate with FormItemIcon");
                  btn.setWidth(300);
                  btn.addClickHandler(new ClickHandler() {
                      @Override
                      public void onClick(ClickEvent event) {
                          recreate(true);
                      }
                  });
                  mainLayout.addMember(btn);
              }
              {
                  IButton btn = new IButton("Recreate without FormItemIcon");
                  btn.setWidth(300);
                  btn.addClickHandler(new ClickHandler() {
                      @Override
                      public void onClick(ClickEvent event) {
                          recreate(false);
                      }
                  });
                  mainLayout.addMember(btn);
              }
              {
                  IButton btn = new IButton("Recreate without FormItemIcon attached");
                  btn.setWidth(300);
                  btn.addClickHandler(new ClickHandler() {
                      @Override
                      public void onClick(ClickEvent event) {
                          recreate(null);
                      }
                  });
                  mainLayout.addMember(btn);
              }
              recreate(true);
              mainLayout.draw();
          }
      
          private void recreate(Boolean withFormItemIcon) {
              Window w = new Window();
              w.setWidth("95%");
              w.setHeight("95%");
              w.setMembersMargin(0);
              w.setModalMaskOpacity(70);
              w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
              w.setTitle("ButtonItem-Titlearea acts like FormItemIcon" + w.getTitle());
              w.setShowMinimizeButton(false);
              w.setIsModal(true);
              w.setShowModalMask(true);
              w.centerInPage();
      
              w.addItem(new DynamicFormClearViewState(withFormItemIcon));
              w.show();
          }
      
      [B]    private final class MyFII extends FormItemIcon {
              {
                  setSrc("http://www.famfamfam.com/lab/icons/silk/icons/sport_soccer.png");
                  addFormItemClickHandler(new FormItemClickHandler() {
                      @Override
                      public void onFormItemClick(FormItemIconClickEvent event) {
                          SC.say("Explanation");
                          SC.logWarn("FormItemIcon clicked");
                      }
                  });
              }
          }[/B]
      
          private final class DynamicFormClearViewState extends DynamicForm {
      
              public DynamicFormClearViewState(Boolean withFormItemIcon) {
                  super();
                  setIsGroup(true);
                  setGroupTitle("To see DynamicForm dimensions");
                  setWidth(400);
      
                  final ButtonItem clearViewStateButton = new ButtonItem("TEST", "Testbutton");
                  clearViewStateButton.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
                      @Override
                      public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
                          SC.say("Button clicked");
                          SC.logWarn("Button clicked");
                      };
                  });
                  clearViewStateButton.setWidth(190);
                  clearViewStateButton.setAlign(Alignment.RIGHT);
      
                  if (withFormItemIcon == null || withFormItemIcon == true) {
                      [B]FormItemIcon helperIcon = new MyFII();[/B]
                      if (withFormItemIcon != null && withFormItemIcon == true)
                          clearViewStateButton.setIcons(helperIcon);
                  }
                  setFields(clearViewStateButton);
              }
          }
      }
      Thank you for the fast answer,
      Blama

      Comment

      Working...
      X