This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 207477 - BooleanStateAction Main Menu bug
Summary: BooleanStateAction Main Menu bug
Status: REOPENED
Alias: None
Product: platform
Classification: Unclassified
Component: Actions (show other bugs)
Version: 7.1
Hardware: Macintosh (x86) Mac OS X
: P3 normal (vote)
Assignee: Jan Peska
URL: http://wiki.netbeans.org/JDK7u4forMac...
Keywords: JDK_SPECIFIC
Depends on:
Blocks:
 
Reported: 2012-01-18 16:52 UTC by kiyut
Modified: 2013-05-30 14:03 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample Nb Platform project that show the bug (12.58 KB, application/zip)
2012-01-18 16:52 UTC, kiyut
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kiyut 2012-01-18 16:52:46 UTC
Created attachment 115045 [details]
Sample Nb Platform project that show the bug

Hi,

BooleanStateAction when referenced from Main Menu in Mac OSX, does not respond on setEnabled(true/false) and setBooleanState(true/false).

The problem is only in Mac OSX, in the MS Windows or Linux it is fine.

Attached is Sample NB Platform application that indicate the bug
note: it is just plain Nb Platform (nothing added), only added BooleanStateAction and TopComponent with button, which show the bug.

Just run the above sample
- click on the button (on displayed TopComponent) to setEnabled or setChecked the menu
- and see the Main Menu, it does not respond at all.

Tested on Mac OSX 10.6.2, with default Java that come with it.
Nb Platform 7.1

Regards
Tonny Kohar
Comment 1 Jaroslav Tulach 2012-02-03 12:18:21 UTC
I don't have Mac.
Comment 2 Stanislav Aubrecht 2012-03-12 12:16:48 UTC
BooleanStateAction.setBooleanState() isn't working on windows either (jdk 1.6). Action.setEnabled() doesn't work on mac but it does work on windows. debugging shows there are no listeners registered to the action instance. so i guess our menu implementation refreshes the appropriate menu item in popup menu listener and the check for checked/unchecked state is missing.
Comment 3 Jaroslav Tulach 2012-05-21 15:29:03 UTC
BooleanStateAction is not really the preferred solution for "checkbox" action anymore: ergonomics#d2e57fd4b6d3
Comment 4 Jaroslav Tulach 2012-05-21 15:58:55 UTC
The sample application seems to work quite fine on Linux. If you still have problems on Mac, please re-open, I pass to Mac OS X guys again.
Comment 5 kiyut 2012-05-21 16:22:35 UTC
Yes, as far as my test go, the bug is still exists on Mac OSX.

For me (my own test) the bug does not occur on Linux and MS Windows, it happend only on Mac OSX 10.6.2, with default Java that come with it.

note, I am not sure about Mac OSX higher than 10.6.2 because I do not have it. My test is on Mac OSX 10.6.2
Comment 6 Jaroslav Tulach 2012-05-21 18:30:37 UTC
Assigning to Tonda. Either he find somebody with Mac or he can buy me one.
Comment 7 Quality Engineering 2012-05-23 09:42:56 UTC
Integrated into 'main-golden', will be available in build *201205230300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/d2e57fd4b6d3
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: Result of #207477: Offer alternative
Comment 8 kiyut 2012-06-18 09:09:01 UTC
how to workaround this bug without modifying Nb codes. This workaround is in user code.

The idea is to maintain the JMenuItem reference ourselves and set the appropriate (checked/enabled) state.
So you can inherit from WorkaroundBooleanStateAction instead of original BooleanStateAction

public abstract class WorkaroundBooleanStateAction extends BooleanStateAction {
    // if needed do you own stuff
    
    /* XXX Netbeans Platform bug 207477
     * Workaround for Mac OSX Bug with BooleanStateAction enabled and selected
     * so keep track JMenuItem ourselves
     */
    private WeakHashMap<JMenuItem, WeakReference<JMenuItem>> menuItemsMap = new WeakHashMap<JMenuItem, WeakReference<JMenuItem>>();
    
    @Override
    public JMenuItem getMenuPresenter() {
        if (Utilities.isWindows()) {
            return super.getMenuPresenter();
        }
        JMenuItem menuItem = super.getMenuPresenter();
        menuItemsMap.put(menuItem,new WeakReference<JMenuItem>(menuItem));
        return menuItem;
    }
    
    @Override
    public void setBooleanState(boolean value) {
        super.setBooleanState(value);
        if (!Utilities.isWindows()) {
            for (JMenuItem menuItem : menuItemsMap.keySet()) {
                menuItem.setSelected(value);
            }
        }
    }
    
    @Override
    public void setEnabled(boolean value) {
        super.setEnabled(value);
        if (!Utilities.isWindows()) {
            for (JMenuItem menuItem : menuItemsMap.keySet()) {
                menuItem.setEnabled(value);
            }
        }
    }
    
    // if needed do you own stuff
}