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 71764 - Save, Print cookies ignored in platform applicaion
Summary: Save, Print cookies ignored in platform applicaion
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Actions (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jiri Rechtacek
URL: http://openide.netbeans.org/servlets/...
Keywords: PLATFORM
Depends on:
Blocks:
 
Reported: 2006-01-23 17:20 UTC by pblemel
Modified: 2008-12-23 14:31 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
A project that illustrates the bug, and work around (100.22 KB, application/x-gzip)
2006-01-23 17:23 UTC, pblemel
Details
simplest test case (1.90 KB, application/octet-stream)
2006-08-15 19:52 UTC, numeropi
Details
modified test (2.06 KB, text/plain)
2006-11-22 12:34 UTC, Jiri Rechtacek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pblemel 2006-01-23 17:20:27 UTC
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.
Comment 1 pblemel 2006-01-23 17:23:43 UTC
Created attachment 28554 [details]
A project that illustrates the bug, and work around
Comment 2 Jiri Rechtacek 2006-01-30 07:20:04 UTC
Thanks for test application. I'm evaluating the problems.
Comment 3 numeropi 2006-08-10 00:48:55 UTC
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() ?
Comment 4 David Strupl 2006-08-15 09:33:03 UTC
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
Comment 5 Jaroslav Tulach 2006-08-15 15:52:10 UTC
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.
Comment 6 numeropi 2006-08-15 19:52:43 UTC
Created attachment 32969 [details]
simplest test case
Comment 7 numeropi 2006-08-15 19:58:26 UTC
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();

Comment 8 Jiri Rechtacek 2006-11-22 12:33:20 UTC
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.
Comment 9 Jiri Rechtacek 2006-11-22 12:34:29 UTC
Created attachment 36208 [details]
modified test
Comment 10 numeropi 2006-11-22 13:23:31 UTC
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.
Comment 11 Jiri Rechtacek 2006-11-22 16:00:58 UTC
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
Comment 12 Quality Engineering 2008-12-23 14:31:36 UTC
This issue had *1 votes* before move to platform component