Announcement

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

    TreeGrid blur handler?

    Hello,

    (yes I'm new)

    I'm making a form with a field that requires selecting the value from a tree, as well as filtering the tree's contents before value selection. I extended TextItem by adding a TreeGrid for picking the value, and used the TextItem's value in filtering the tree.

    Seems to work fine, but I'm having a hard time hiding the TreeGrid if the user selects nothing and clicks on some other item. There seems to be no addBlurHandler method for TreeGrid?

    Any thoughts on how to get rid of the TreeGrid? Can I somehow add a blur handler to it (addHandler seemed promising, but I could not get it to work)? I guess I could put the TreeGrid in a borderless window or something, but it just feels a bit .. wrong :).

    I'm using SmartGWT 1.2.

    TY,
    pm

    #2
    See the FocusChangedHandler in the superclass, Canvas.

    Comment


      #3
      Thank you for the reply. Can't seem to get it to work, though. Seems that the focus changed event is never fired.

      br,
      pm

      Code:
      picker = new TreeGrid();
      
      picker.setDataSource(ds);
      picker.setAutoFetchData(false);
      picker.setLoadDataOnDemand(false);
      picker.setSelectionType(SelectionStyle.SINGLE);
      picker.setShowHeader(false);
      
      picker.setFields(
              new TreeGridField("value")
      );
      
      addFocusHandler(new FocusHandler(){
          public void onFocus(FocusEvent focusEvent) {
              if(showPickerOnFocus){
                  showPicker();
              }
              showPickerOnFocus = true;
          }
      });
      
      addKeyUpHandler(new KeyUpHandler(){
          public void onKeyUp(KeyUpEvent keyUpEvent) {
              SC.logWarn("koodistotree.onkeyup: " + keyUpEvent.getKeyName());
              if(keyUpEvent.getKeyName().equals("Arrow_Down")){
                  picker.focus();
                  if(picker.getSelectedRecord() == null){
                      picker.selectRecord(0);
                  }
              }
          }
      });
      
      picker.addSelectionChangedHandler(new SelectionChangedHandler(){
          public void onSelectionChanged(SelectionEvent selectionEvent) {
              SC.logWarn("picker.onselectionchanged");
              selectValue(selectionEvent.getRecord(), false);
          }
      });
      
      picker.addFocusChangedHandler(new FocusChangedHandler(){
          public void onFocusChanged(FocusChangedEvent focusChangedEvent) {
              SC.logWarn("onFocusChanged yay!");
          }
      });

      Comment


        #4
        I've got the same problem with a ListGrid. The addFocusHandler doesn't seem to fire.

        Comment


          #5
          Ive got the same problem with ListGrid. Allthough focus changes between two listgrids (I have keylisteners on both which catch key events appropriatly) the focusChangedEvent is not fired.

          Comment


            #6
            ...

            Still can't find a way to hide the picker..

            How do the default date picker and combobox widgets handle this? They seem to hide their pickers on blur.

            Comment


              #7
              Likewise, the FocusChangedHandler did not work for me.

              However, I did get the effect I wanted by adding a BlurHandler to my class, easiest to explain through the showcase code: http://www.smartclient.com/smartgwt/..._custom_picker

              Code:
                    public YesNoMaybeItem() {  
                          //use default trigger icon here. User can customize.  
                          //[SKIN]/DynamicForm/default_formItem_icon.gif  
                          FormItemIcon formItemIcon = new FormItemIcon();  
                          setIcons(formItemIcon);  
              
              //ADDED THIS
              		addBlurHandler(new BlurHandler() {
              			@Override
              			public void onBlur(BlurEvent event) {
              				dialog.hide();
              			}
              		});

              Comment

              Working...
              X