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.
The Rich Client Platform in NetBeans 5.0 RC2 ignores cookies for framework- supplied menu actions (E.g. SaveAction and PrintAction). These menu picks will remain disabled even when an active node has the appropriate action in its CookeSet. Specifics: The application that illustrates this bug is a simple TopComponent- only application, much like the Paint tutorial, that does not have an explorer view. The problem can be reproduced in a very small test case. 1) Create a new Module Suite Project (E.g. DrawApp) 2) Create a new Module Project (E.g. Draw) 3) Select the DrawApp node, open properties, select "Application", and then enable the bullet "Create Standalone Application". Omit platform libraries. 4) Select Draw node and add APIs for Actions and TopComponents. 5) Create a new TopComponent class that activates a node containing Save and Print cookies (attached as DrawTopComponent.java). 6) Create a new 'NewCanvasAction' menu action in the File menu. Add a performAction body that creates the CanvasTopComponent and activates it (attached as NewCanvasAction.java). 7) Run the project 8) Create the TopComponent using File -> New When the TC is active, the File Save and File Print menu items will remain disabled, however the SaveCookie and PrintCookie should result in these items being enabled. Work around : Add a toolbar action such as <file name="org-openide-actions- SaveAction.instance"/> to the application's Toolbars folder in layers.xml. The addition of this action will cause the RCP framework to correctly enable actions when cookies are presented. It is not necessary to add a toolbar action for each menu action. I.e. the presence of the toolbar SaveAction means that I don't need to add a toolbar PrintAction to enable the File Print menu pick. It appears that any action is good enough.
Created attachment 28554 [details] A project that illustrates the bug, and work around
Thanks for test application. I'm evaluating the problems.
I would like to see this bug solved so I have spent some time trying to figure it out. I think I have tracked it to NodeAction.addNotify() never being called when the NodeAction is added to a menu, therefore, NodeAction never initializes its static listener list and so, cookie changes in the selected nodes are not accounted for. Patching NodeAction.java so that initialize() calls addNotify(), which initializes the listeners, seems to solve the problem. I suppose the real fix should be that creating the action from MenuBar should result in NodeAction.addNotify() being called from somewhere. Maybe from Actions.connect() ?
Hello, I have also noticed this. If the patch is simple I will back port it to our branch based on release50 (platform_32247-50). Jirka will you create some patch? Thanks a lot, David
Anyone to write a test? There is plenty of tests in http://www.netbeans.org/source/browse/openide/nodes/test/unit/src/org/openide/util/actions/NodeActionTest.java?rev=1.3&view=markup so it should be pretty simple to write a unit test for this bug. Then the fix will be piece of cake.
Created attachment 32969 [details] simplest test case
I have attached a really simple test case. I'm not too fluent with the platform yet, so the test case may be invalid. Currently (platform 5.0 ) it fails. It will pass just by adding a call to saveAction.addNotify(); before Node node = new TestNode();
The numeropi is right, the method NodeAction.addNotify() attaches the listener of node changes. If you can use ContextAwareAction then use saveAction.createContextAwareAction(<lookup with activated nodes>) or call addNotify(). See the attached test, it's passing.
Created attachment 36208 [details] modified test
I don't think this is resolved - IMO addNotify() should be called by the platform automatically at the time the action is made visible. Calling it manually is a workaround for the bug.
NodeAction initializes its listener list on the first demand and should response to cookie changes immediately. Checking in src/org/openide/util/actions/NodeAction.java; /shared/data/ccvs/repository/openide/nodes/src/org/openide/util/actions/NodeAction.java,v <-- NodeAction.java new revision: 1.22; previous revision: 1.21 done RCS file: /shared/data/ccvs/repository/openide/nodes/test/unit/src/org/openide/util/actions/Issue71764Test.java,v done Checking in test/unit/src/org/openide/util/actions/Issue71764Test.java; /shared/data/ccvs/repository/openide/nodes/test/unit/src/org/openide/util/actions/Issue71764Test.java,v <-- Issue71764Test.java initial revision: 1.1 done
This issue had *1 votes* before move to platform component