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 13505 - NodeAction.enable() called twice in Popup Menus
Summary: NodeAction.enable() called twice in Popup Menus
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Nodes (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords: PERFORMANCE
Depends on: 17196
Blocks:
  Show dependency tree
 
Reported: 2001-07-11 09:50 UTC by _ mruflin
Modified: 2008-12-22 19:39 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump of this bug (11.86 KB, text/plain)
2001-07-11 09:54 UTC, _ mruflin
Details
Testing module JAR (installs actions and shows enablement) (9.51 KB, application/octet-stream)
2001-11-01 21:48 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description _ mruflin 2001-07-11 09:50:28 UTC
When right clicking on a Node in Explorer, the enable() method of 
MoveUp/MoveDownAction is called twice. This bug may exist in other NodeActions 
as well.

(Made priority to P2 because if it exist in all NodeActions this is also a 
performance bug that should be fixed. Not startup performance but runtime, 
which is even more important)
Comment 1 _ mruflin 2001-07-11 09:54:59 UTC
Created attachment 1851 [details]
Thread dump of this bug
Comment 2 _ ttran 2001-10-17 08:05:42 UTC
phrebejk is the "owner" of Nodes subsystem
Comment 3 Jesse Glick 2001-10-25 21:28:29 UTC
Let me know if you want me to investigate, I don't have any P2s at the
moment...
Comment 4 Petr Nejedly 2001-10-30 15:28:38 UTC
If you'd like, you're welcome.
I'd take look at it but I'm taking some days off now.

Hints:
It is actually called 3 times in my case.
The problem of the first two seems to lay in
org.openide.awt.Actions.MenuBridge:457,
or in implementation of NodeAction:
                button.setEnabled (action.isEnabled ());
action.isEnabled drives one direct call to enable(), while
button.setEnabled() calls it indirectly through PropertyChangeEvent

Why does the Bridge react to changes of "enabled" property of the
component?
Comment 5 Petr Nejedly 2001-10-30 15:55:50 UTC
Adding Jesse to cc:
I thought you're already on cc, but realized you aren't.
Comment 6 Jesse Glick 2001-10-30 20:06:41 UTC
OK, I can try to track it down.
Comment 7 Petr Hrebejk 2001-10-31 10:07:46 UTC
Sure, if you want. I was investigating this bug and I think that the 
problem is the call to updateState( null ). In the four connect()
methods in org.openide.awt.Actions.

Jarda said that ot should be OK when the call is avoided. However
when I did it the IDE didn't started because of VCS module. This is
relatively easy to fix and is maybe already fixed.

The second problem is that after the change menus in main window 
sometimes become very small. I didn't have time to further investigate
this, but I think that some initialization in the menu items is not
called and the size of the component is not computed correctly.
Comment 8 Jesse Glick 2001-10-31 12:04:11 UTC
I can confirm that NodeAction.enable(Node[]) is called way too often.
If you install a tools action and switch Explorer nodes, it is called
for every switch, even though the popup is not showing at all, and
nobody is actually calling isEnabled()! Probably it should (1) after
firing a change in PROP_ENABLED, stop calling enable(Node[[]) on
subsequent selection changes until someone next calls isEnabled(); (2)
keep a weak cache of the last node selection it actually checked and
not do anything if the enablement has already been computed for this
selection. addNotify() and removeNotify() seem to be called at
appropriate times, but this does not seem to help avoid calls to
enable(Node[]). CookieAction may need similar treatment. I am trying
to write a test suite for org.openide.util.actions.* to assist in
checking these things. My guess is that it is better to fix the
redundancy directly in the actions, rather than trying to make the
action bridges more complicated.
Comment 9 Jesse Glick 2001-11-01 21:33:16 UTC
Issue #17196 has a proposed patch attached.
Comment 10 Jesse Glick 2001-11-01 21:46:00 UTC
Would somebody (esp. Yarda or Petr N.) like to review the patch in
#17196? It seems to work well. I still need to check up on strange
problems with S-F10 (popup) and creating popups from the editor;
either file separate bugs if they exist without this patch, or figure
out what to do if this patch causes them.

Is it too late in the release cycle to make significant changes to
NodeAction do you think? Looking at what is actually called right now
when you have some actions installed (toolbars, menus, tools actions,
context actions), enable(Node[]) is really called too often. The patch
ensures it is only called once per node selection, and only called at
all when somebody is actually going to use the information. (E.g.
changing node selection should not do enablement checks on tools
actions that are not even showing!)

I will attach a mini module which installs some actions in typical
ways: a tools action (Node); main menu item (Cookie); context menu
(Cookie); toolbar presenter (Node). It shows you when isEnabled(),
enable(), addNotify(), and removeNotify() are called.
Comment 11 Jesse Glick 2001-11-01 21:48:07 UTC
Created attachment 3236 [details]
Testing module JAR (installs actions and shows enablement)
Comment 12 Jesse Glick 2001-11-02 13:11:47 UTC
Comment from Yarda: WeakListener could probably be used for the
listeners in CbSA and NA, which would perhaps simplify the code
(though I think with the same result).

Note the change in behavior of NA as far as PROP_ENABLED goes: with
the patch, if you call isEnabled() and it says true (e.g.), and you
have the focus listener turned on (addNotify() has been called), and
the node selection changes--it will now fire PROP_ENABLED but with a
new value of null. So anyone listening to changes will get a change
notification. However, the actual new value (true or false) will not
really be computed yet. So long as nobody calls isEnabled(), no more
PROP_ENABLED changes will be fired as the node selection continues to
change. I think this is acceptable; if you don't know what the new
value is, it cannot matter if it changes again before you ask. I did a
search thru nb_all and f4j_all looking for code using PROP_ENABLED or
"enabled" from NodeAction; in all cases I could find it simply checks
if a PROP_ENABLED is fired, and if so calls some refresh method, which
would then call isEnabled() and get the new value. Hypothetical code
which used the new value from the property change would find that it
is now null (but correctly written listeners will accept this and call
isEnabled() as a fallback, and so continue to work as before). Note
that PROP_ENABLED may now be fired when in fact the value did not
really change (because it is fired before this is known); I think this
is preferable to recomputing enablement too much, as most listeners
would just call e.g. JButton.setEnabled(...) which should do nothing
if called with the same value as it already has.
Comment 13 Jesse Glick 2001-11-06 11:19:45 UTC
Fixed:

Actions.java 1.52
(CookieAction.java 1.18)
NodeAction.java 1.29
Comment 14 Jaromir Uhrik 2002-10-23 13:08:35 UTC
Verified.
Comment 15 Quality Engineering 2003-07-01 16:28:59 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.