Announcement

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

    Checked Menu Items don't display correctly

    SmartGWT 2.5 in Chrome (but probably others too)

    Here is a CheckedMenuItem class I built so that the graphical display would look like the underlying status. If I call getChecked() the state is reported correctly, but I can't seem to get the menu to reflect this by hiding/displaying the checkbox.

    Code:
    package com.imagehawk.tcv.client;
    
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.menu.Menu;
    import com.smartgwt.client.widgets.menu.MenuItem;
    import com.smartgwt.client.widgets.menu.MenuItemIfFunction;
    
    public class CheckedMenuItem extends MenuItem implements MenuItemIfFunction {
    
    	private boolean isChecked = true;
    	
    	CheckedMenuItem(String title) {
    		super(title);
                    this.setChecked(this.isChecked);
    		this.setCheckIfCondition(this);
    	}
    
    	@Override
    	public void setChecked(Boolean checked) {
    		isChecked = checked;
    		super.setChecked(checked);
    	}
    
    	@Override
    	public boolean execute(Canvas target, Menu menu, MenuItem item) {
    		CheckedMenuItem thisItem = (CheckedMenuItem)item;
    		return thisItem.isChecked;
    	}
    }

    #2
    See FAQ on problems with Chrome - Chrome is broken with GWT in general.

    Don't try to override setChecked(), thats not actually doing anything. If you need a notification of the state being changed, add a handler for the ChangedEvent.

    Comment


      #3
      The main reason I was using chrome was the note about firebug making it everything very slow.

      I've been disappointed trying to debug in Chrome. So which browser (today) is the one to use for development? Am I better off using FF with Firebug than Chrome.

      Also, I tried this code in FF tonight too, and it still doesn't work. Why can't I get the checkbox to display correctly next to the menu item? What is the magic bullet needed to get the menu to show the true checked state.

      From reading the FAQ and bug listed there, it seems like the Chrome/GWT breakage is in the debugger/development mode, not in just using Chrome. However, the pdf located @ http://www.smartclient.com/technolog...Tech_Brief.pdf doesn't list chrome as a supported client. Is this just a very old pdf or is Chrome really not supported?
      Attached Files
      Last edited by mark0978; 11 Oct 2011, 04:19.

      Comment


        #4
        Any chance of getting an answer about this?

        Comment


          #5
          Chrome is supported for compiled applications but not when running in development mode.

          In terms of your original question - we realize its not clear what you're trying to achieve here. If you have a standard MenuItem you can set its checked status via 'setChecked' and retrieve it via 'getChecked'.
          If you need the check mark to show up conditionally when the menu is shown you can use a checkIf condition to set up a dynamic condition to check, and the execute method will be run each time the menu is shown.

          It seems like you are looking for some other behavior that MenuItems don't handle by default but its not clear what.

          Comment


            #6
            So is this the optimum solution? Is there some other way I should be doing it?

            The code below solves the problem I initially set out to handle. What I can't understand is WHY I need it?

            If I call setChecked, it ignores any icon I have set and draws the checkbox. So the solution down below looks wrong, but actually works. You would think that if you called setChecked, it would hook up the checked state watcher/dynamic icon automagically, especially if it is going to override the icon anyway.

            Maybe this code should be added to the core? Maybe ONE of the samples should show this kind of code. I checked, and nothing deals with this in any of the showcase examples. They used setChecked, but nothing dealt with showing/not showing the check beside a menu item, or dynamically changing the menu item icon.

            Is this the optimum solution? Is there some other way I should be doing it?

            Code:
            package com.imagehawk.tcv.client;
            
            import com.smartgwt.client.widgets.Canvas;
            import com.smartgwt.client.widgets.menu.Menu;
            import com.smartgwt.client.widgets.menu.MenuItem;
            import com.smartgwt.client.widgets.menu.MenuItemStringFunction;
            import com.smartgwt.client.widgets.menu.events.ClickHandler;
            import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
            
            public class CheckedMenuItem extends MenuItem implements MenuItemStringFunction, ClickHandler {
            
            	CheckedMenuItem(String title) {
            		super(title);
            		this.setDynamicIconFunction(this);
            		this.addClickHandler(this);
            	}
            
            	@Override
            	public void setChecked(Boolean checked) {
            		super.setChecked(checked);
            	}
            
            	@Override
            	public String execute(Canvas target, Menu menu, MenuItem item) {
            		if(item.getChecked()) {
            			return "";
            		}
            		return null;
            	}
            
            	@Override
            	public void onClick(MenuItemClickEvent event) {
            		this.setChecked(!this.getChecked());
            	}
            }

            Comment


              #7
              What is "the problem you initially set out to handle"?

              Comment

              Working...
              X