Bug 136397 - [ActionSets] toolbar: specifying pull-down forces plugin load
Summary: [ActionSets] toolbar: specifying pull-down forces plugin load
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M3   Edit
Assignee: Paul Webster CLA
QA Contact:
URL: http://wiki.eclipse.org/index.php?tit...
Whiteboard:
Keywords: performance
: 53979 (view as bug list)
Depends on: 189092 207263 207744
Blocks: 72322 171558
  Show dependency tree
 
Reported: 2006-04-12 13:57 EDT by Martin Aeschlimann CLA
Modified: 2008-05-23 11:57 EDT (History)
13 users (show)

See Also:


Attachments
Fix (1.27 KB, patch)
2007-04-20 04:08 EDT, Dani Megert CLA
no flags Details | Diff
Fix (4.01 KB, application/octet-stream)
2007-04-22 12:18 EDT, Dani Megert CLA
no flags Details
Fix with different approach (3.09 KB, patch)
2007-04-23 05:45 EDT, Dani Megert CLA
no flags Details | Diff
Proxy fix proof of concept v02 (4.14 KB, patch)
2007-08-28 15:06 EDT, Paul Webster CLA
no flags Details | Diff
Proxy fix proof of concept v03 (4.51 KB, patch)
2007-08-29 10:30 EDT, Paul Webster CLA
no flags Details | Diff
MenuManager approach v01 (2.91 KB, patch)
2007-08-29 13:40 EDT, Paul Webster CLA
no flags Details | Diff
MenuManager + ActionContributionItem approach v03 (4.78 KB, patch)
2007-08-29 15:02 EDT, Paul Webster CLA
no flags Details | Diff
MenuManager + ActionContributionItem approach v04 (4.71 KB, patch)
2007-08-30 08:03 EDT, Paul Webster CLA
no flags Details | Diff
ActionContributionItem with a proxy v04 (1.85 KB, patch)
2007-09-10 13:04 EDT, Paul Webster CLA
no flags Details | Diff
Menu Manager fix only v04 (2.91 KB, patch)
2007-09-10 13:05 EDT, Paul Webster CLA
no flags Details | Diff
ActionContributionItem clones menu v01 (4.66 KB, patch)
2007-09-15 15:59 EDT, Paul Webster CLA
no flags Details | Diff
PluginAction defer loading v01 (1.71 KB, patch)
2007-10-04 11:01 EDT, Paul Webster CLA
no flags Details | Diff
Defer Plugin Loading v3.2.2 (11.97 KB, patch)
2007-12-14 12:47 EST, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2006-04-12 13:57:50 EDT
20060412-0010

A toolbar action that specifies 'pull down' and is not retargetable is forced to load when added to the toolbar.

WWinPluginAction line 121 does a refreshSelection()
and 
PluginAction line 277 tests isOkToCreateDelegate()
which is implemented as

    protected boolean isOkToCreateDelegate() {
    	if (getStyle() == IAction.AS_DROP_DOWN_MENU) {
    		return true;
    	}

        // test if the plugin has loaded
        String bundleId = configElement.getNamespace();
        return BundleUtility.isActive(bundleId);
    }

This seems to be related to bug 53979, bug 88534

Note that the action ins't really interested in the selection. As I see in the other bug this is also a major issue for other components.
Comment 1 Martin Aeschlimann CLA 2006-04-13 04:31:19 EDT
A non-breaking fix for 3.2 could be to add a new optional attribute to the extension that e.g. states that the action is always enabled and does not need any selection changes.
Comment 2 Eric Moffatt CLA 2006-04-13 09:50:02 EDT
Duong, this is likely more general than simply action sets but its performance related so you first...
Comment 3 Martin Aeschlimann CLA 2006-04-21 06:51:24 EDT
Can you already say something if a fix / workaround can be provided for 3.2?

I agree that changing the current bahviour could be a bit risky, but offering a workaround (e.g. as suggested in comment 1) could bring immediate benefit on the performance tests.
Comment 4 Paul Webster CLA 2007-04-05 19:05:05 EDT
Assigning to component owner
PW
Comment 5 Paul Webster CLA 2007-04-17 12:49:34 EDT
The patch that did this was the fix for bug 105936 as a consequence of bug 90355.  Since the work for bug 90355 has been rolled back, it doesn't look like 105936 is needed anymore.

I'll release the revert into HEAD and watch for suspicious missing menu entries.

PW
Comment 6 Paul Webster CLA 2007-04-17 12:50:18 EDT
Released to HEAD >20070417
PW
Comment 7 Dani Megert CLA 2007-04-18 08:24:52 EDT
Paul, what did you commit? Are you saying this bug is now fixed?
Comment 8 Paul Webster CLA 2007-04-18 10:32:52 EDT
Sorry, I removed:
        if (getStyle() == IAction.AS_DROP_DOWN_MENU) {
                return true;
        }

Yes, it should be fixed.

I'm doing performance today and tomorrow, but I don't want to say this is fixed until I've verified some more of the delegate loading.

PW
Comment 9 Dani Megert CLA 2007-04-19 06:48:42 EDT
This is not fixed :-(

Test Case:
1. add breakpoint to DebugUI.start()
2. start fresh target in debug mode
==> breakpoint is hit due to 
    org.eclipse.debug.internal.ui.actions.RunHistoryMenuAction


WWinPluginPulldown.MenuProxy.getMenu(Menu) needs this at the top:
	if (!isOkToCreateDelegate())
		return null;

AND: make sure *not* to add this to the getMenu(Control).

HTH
Comment 10 Dani Megert CLA 2007-04-19 07:39:48 EDT
Paul, due to bug 183163 the test case is slightly different:
1. start fresh target
2. exit
3. add breakpoint to DebugUI.start()
4. start target in debug mode
==> breakpoint is hit due to 
    org.eclipse.debug.internal.ui.actions.RunHistoryMenuAction
Comment 11 Dani Megert CLA 2007-04-19 07:41:30 EDT
Fixing this will improve startup performance as DebugUI and External Tools won't be loaded any longer on startup.
Comment 12 Dani Megert CLA 2007-04-20 04:08:06 EDT
Created attachment 64392 [details]
Fix
Comment 13 Paul Webster CLA 2007-04-20 08:05:19 EDT
(In reply to comment #12)
> Created an attachment (id=64392) [details]
> Fix
> 

I tried this last night, but it prevents the main menu entries from being populated.

PW
Comment 14 Dani Megert CLA 2007-04-20 08:15:49 EDT
Which main menu entries?
Comment 15 Dani Megert CLA 2007-04-20 08:19:14 EDT
Did you add the code to the right class? Just tried and could not find missing menu entries.
Comment 16 Paul Webster CLA 2007-04-20 08:55:02 EDT
(In reply to comment #15)
> Did you add the code to the right class?

yes :-)

> Just tried and could not find missing
> menu entries.

I applied your patch just to be sure and launched my workspace.  Go to the main Run menu.  My Run As and Run History don't cascade any more.  Popup on a project, Run As doesn't have a cascade.

But clicking on the pull-down does get the cascade.

PW
Comment 17 Paul Webster CLA 2007-04-20 09:05:22 EDT
Removing the initial lines from isOkToCreateDelegate() will delay plugin loading for toolbar pulldown contributions.  But it won't help with the Debug case, as the main menu has entries that need to be filled in.

One possible direction would be to rework ActionContributionItem.  If the action fired anothe property, say PROP_MENU, then the action contribution item could know to replace its current Menu with a new one ... this is risky work and also might involve API.

I'll leave this for consideration for 3.3 and we can decide what to do with it later, but these kinds of changes won't make it in for 3.3M7.

PW
Comment 18 Dani Megert CLA 2007-04-20 12:37:52 EDT
Oh boy - so the WWinPluginPulldown is actually also used for the cascading main menu. Pretty unexpected from the class name and its Javadoc ;-)

Anyway, good we made this iteration as I now also understand the reason why the context menu got broken in some scenarios: the code change you made from comment 8 should not have entirely removed the check as the current comment 8 "fix" also makes the CONTEXT sub-menus disappear without my fix. Here's a simple test case using plain N20070419-0010 (without my fix):
1. start
2. create a Java project
3. disable the Launching and the External Tools action sets
4. exit
5. start
6. open context menu on project
==> no Run or Debug sub-menus because they are no longer built (these are ObjectPluginAction's).

We need to bring back the check from comment 8 into PluginAction but slightly modified:
    	if (getStyle() == IAction.AS_DROP_DOWN_MENU && !WWinPluginPulldown.class.isInstance(this)) {
    		return true;
    	}


Besides that I have a working patch ready that sets a dummy menu and then resolves it when needed but that needs some more testing and proper cleanup of the dummy menu.

Stay tuned.
Comment 19 Paul Webster CLA 2007-04-20 15:04:30 EDT
(In reply to comment #18)
> 
> We need to bring back the check from comment 8 into PluginAction but slightly
> modified:
>         if (getStyle() == IAction.AS_DROP_DOWN_MENU &&
> !WWinPluginPulldown.class.isInstance(this)) {
>                 return true;
>         }
> 

I've released this fix into HEAD in the meantime.
PW
Comment 20 Dani Megert CLA 2007-04-22 12:18:21 EDT
Created attachment 64545 [details]
Fix

This patch fixes the loading of plug-ins for the pulldown and the main menu: only when the corresponding menu item gets armed it will trigger the plug-in to be loaded. Unfortunately there's a flash when the loading happens as the change to the menu causes a redraw. I could not find a way to stop this. (adding Steve as SWT might have an idea here).

NOTE: there is still an issue with the context menu (ObjectPluginAction) where the plug-ins get loaded when the context menu is built for the first time. This will be harder to fix as we do not have access to the owner at creation time.
Comment 21 Dani Megert CLA 2007-04-23 05:45:31 EDT
Created attachment 64584 [details]
Fix with different approach

This second fix uses much less code and loads later but it still causes the flickering: I could not find a way to transfer the menu items of the loaded menu over to the proxy menu. Maybe SWT can help out here.

If we cannot get rid of the flickering we have to discuss whether it makes sense to apply this, especially since opening the context menu will force the loading as well immediately and I doubt we can fix this for 3.3.
Comment 22 Dani Megert CLA 2007-04-23 07:43:28 EDT
Also adding Silenio as Steve is away this week.
Comment 23 Paul Webster CLA 2007-04-23 10:40:08 EDT
(In reply to comment #21)
> Created an attachment (id=64584) [details]
> Fix with different approach

This causes a SEGV on GTK+, because it disposes the proxyMenu in the middle of its  menuShown(*) event.  I'll try putting that in an asyncExec(*)

PW
Comment 24 Paul Webster CLA 2007-04-23 10:54:26 EDT
(In reply to comment #23)
> This causes a SEGV on GTK+, because it disposes the proxyMenu in the middle of
> its  menuShown(*) event.  I'll try putting that in an asyncExec(*)

OK, asyncExec(*) will move the dispose to later.  Now if I start up and go Run>Run As I see nothing ... going to the menu a second time will work however.
PW
Comment 25 Dani Megert CLA 2007-04-23 11:03:21 EDT
>going to the menu a second time will work however.
It should work the first time if you're not too fast with the mouse ;-) You ony moved the dispose into async, right?

Does it also flash under Linux?
Comment 26 Paul Webster CLA 2007-04-23 11:13:11 EDT
(In reply to comment #25)
> It should work the first time if you're not too fast with the mouse ;-) You ony
> moved the dispose into async, right?

Right, after the proxyMenu.removeMenuListener(*):
proxyMenu.getDisplay().asyncExec(new Runnable() {
public void run() {
  proxyMenu.dispose();
} });


> Does it also flash under Linux?

No, I don't get the flashing.  I suspect that linux is slightly re-ordering the OS events.

PW

Comment 27 Dani Megert CLA 2007-04-23 11:16:01 EDT
You don't get the flashing but is the sub-menu there if you move slowly or are you required to leave the menu and come back to get the sub-menu? That would be bad.
Comment 28 Paul Webster CLA 2007-04-23 11:21:57 EDT
(In reply to comment #27)
> You don't get the flashing but is the sub-menu there if you move slowly or are
> you required to leave the menu and come back to get the sub-menu? That would be
> bad.

If I start up and go to Run, and then slowly go down and stop over the highlighted Run As, I don't see the menu.

I have to move my cursor off that menu at least once to get it back.

PW


Comment 29 Paul Webster CLA 2007-04-23 12:32:17 EDT
I've tried some other combinations, including use SWT.Show to get more event information and just trying to pop up the menu:
realMenu.setLocation(event.x, event.y);
realMenu.setVisible(true);

But on linux it always takes 2 selections of Run As and 2 selections of Debug As, even after the plugin has been loaded.

But thank you for the patch, Dani.

PW
Comment 30 Dani Megert CLA 2007-04-23 12:34:21 EDT
What would probably work is if we could somehow transfer the MenuItems from the menu back into the proxy but it seems that under Linux SWT doesn't like the menu to be changed while displayed and there seems to be no aboutToShow hook.
Comment 31 Dani Megert CLA 2007-04-23 12:36:29 EDT
Paul, do you know why the main menus are built at all on startup and not just when needed the first time? Is this still needed? As far as I know this was done in the early days so that the key bindings (accelerators) got registered but this should no longer be needed as this should be handled by the command framework, shouldn't it?
Comment 32 Paul Webster CLA 2007-04-23 13:22:25 EDT
(In reply to comment #31)
> Paul, do you know why the main menus are built at all on startup and not just
> when needed the first time? Is this still needed? As far as I know this was
> done in the early days so that the key bindings (accelerators) got registered
> but this should no longer be needed as this should be handled by the command
> framework, shouldn't it?

Yes, that's the current thinking.  One of the optimizations we're considering for 3.4 is to have a lazy approach for the main menu (and view menus).  That would at least delay the debug startup until clicking on the Run menu.

But our initial investigation indicated that it would mean re-working how MenuManager recursively updates sub MenuManagers, and given how these pull down actions work it would probably involve modifying ActionContributionItem/ActionSetContributionItem as well.

PW
Comment 33 Dani Megert CLA 2007-05-21 10:01:13 EDT
I guess we have to shift this to 3.4. Even if we got any response from SWT on how to build that menu, any change at this point will probably be too risky.
Comment 34 Steve Northover CLA 2007-05-22 11:18:27 EDT
Please make sure there is a bug for the SWT issue and follow up on us as necessary.
Comment 35 Dani Megert CLA 2007-05-22 11:25:52 EDT
I'm not sure there is an issue/bug - just asking for the correct way to replace a menu while it's being opened. We then use that and if that doesn't work we can file a bug report.
Comment 36 Dani Megert CLA 2007-05-22 11:26:40 EDT
But if you think it's easier to track I can file one.
Comment 37 Steve Northover CLA 2007-05-22 11:33:49 EDT
When you say "Replace a menu while it's being opened", you mean replace the items, not the menu itself, right?  You should be able to do this using menuShown().  Somewhere in the bug report, I'm sure there is a good reason why you can't.  Let's have a bug about that.
Comment 38 Dani Megert CLA 2007-05-25 03:54:16 EDT
>Let's have a bug about that.
See bug 189092.
Comment 39 Paul Webster CLA 2007-08-28 15:06:03 EDT
Created attachment 77164 [details]
Proxy fix proof of concept v02

This is attachment #64584 [details] modified to try and copy over the real menu items.  It's just a proof of concept patch.

It works for Run>Run History, but it doesn't work for Run>Run As.  The first time the Run As submenu shows up it will not be populated (Run As populates in its own menuShown(*) method).

PW
Comment 40 Paul Webster CLA 2007-08-29 08:06:34 EDT
(In reply to comment #39)
> Created an attachment (id=77164) [details]
> Proxy fix proof of concept v02
> 
> This is attachment #64584 [details] modified to try and copy over the real menu items. 
> It's just a proof of concept patch.

Also, it would have to recursively populate submenus (or the proxy menu would dispose it).

PW
Comment 41 Paul Webster CLA 2007-08-29 10:30:06 EDT
Created attachment 77258 [details]
Proxy fix proof of concept v03

A proxy menu with proxy items.  It recursively creates other proxy submenus and will fire a menuShown(*) event for the real menu so it can pre-populate

PW
Comment 42 Paul Webster CLA 2007-08-29 13:40:14 EDT
Created attachment 77277 [details]
MenuManager approach v01

In this approach we just remove most of the updateAll(true) calls.  MenuManagers already do an update(*) call to configure their contribution items just before they're about to show.

Debug (and my test plugin) are no longer activated on startup.  The plugins are started when the pulldown item is rendered into a cascading menu.  For example, when you pop up the main Run menu you'll start the debug plugin.

PW
Comment 43 Paul Webster CLA 2007-08-29 15:02:13 EDT
Created attachment 77286 [details]
MenuManager + ActionContributionItem approach v03

This adds some changes to ActionContributionItem to delay loading even more.

When we arm the menu item, it swaps out the proxy menu for the real menu returned from IMenuCreator (which for plugin actions instantiates their delegates).

It looks promising ... but I've only tested it on Linux.

PW
Comment 44 Paul Webster CLA 2007-08-30 08:03:09 EDT
Created attachment 77368 [details]
MenuManager + ActionContributionItem approach v04

Slight modification to the timing.
PW
Comment 45 Paul Webster CLA 2007-08-30 08:57:56 EDT
(In reply to comment #44)
> Created an attachment (id=77368) [details]
> MenuManager + ActionContributionItem approach v04
> 

This looks good for linux gtk and mac, but not for windows.  There's either flickering or the menu disappears completely and you need to bring it back up.

PW
Comment 46 Paul Webster CLA 2007-08-30 10:48:39 EDT
*** Bug 53979 has been marked as a duplicate of this bug. ***
Comment 47 Paul Webster CLA 2007-09-10 13:04:08 EDT
Created attachment 77999 [details]
ActionContributionItem with a proxy v04
Comment 48 Paul Webster CLA 2007-09-10 13:05:06 EDT
Created attachment 78000 [details]
Menu Manager fix only v04

Separate the 2  potential improvements.

PW
Comment 49 Paul Webster CLA 2007-09-10 14:03:59 EDT
(In reply to comment #48)
> Created an attachment (id=78000) [details]
> Menu Manager fix only v04

Released the Menu Manager fix to HEAD >20070910


(In reply to comment #47)
> Created an attachment (id=77999) [details]
> ActionContributionItem with a proxy v04


This type of ActionContributionItem proxy fix will depend on what we can come up with in bug 189092

PW
Comment 50 Paul Webster CLA 2007-09-13 11:58:34 EDT
(In reply to comment #49)
> (In reply to comment #48)
> > Created an attachment (id=78000) [details] [details]
> > Menu Manager fix only v04
> 
> Released the Menu Manager fix to HEAD >20070910

The side effect of this fix can be seen in bug 202994.

A closed editor reference will not be cleaned up until the MenuItem referencing it (via a contribution item) is disposed, and that won't happen until that particular menu manager updates.

PW
Comment 51 Paul Webster CLA 2007-09-15 15:59:33 EDT
Created attachment 78502 [details]
ActionContributionItem clones menu v01

This creates pass through proxy items when the menu is about to show.
PW
Comment 52 Paul Webster CLA 2007-09-18 13:41:35 EDT
The action contribution item clone requires some more investigating.

PW
Comment 53 Paul Webster CLA 2007-10-04 11:01:33 EDT
Created attachment 79733 [details]
PluginAction defer loading v01

Try to have PluginAction defer delegate loading as long as possible.  The IMenuCreator is no longer requested just for rendering in a Menu for dropdowns, and the call to getMenuCreator() will cause load the delegate.

The Menu copy v02 fix in bug 189092 allows this to work in the object contribution menu case.

PW
Comment 54 Paul Webster CLA 2007-10-18 11:46:59 EDT
(In reply to comment #53)
> Created an attachment (id=79733) [details]
> PluginAction defer loading v01
>

Released to HEAD >20071018
PW

Comment 55 Paul Webster CLA 2007-10-26 12:54:07 EDT
We now use the pattern suggested in bug 207263

Released to HEAD >20071025
PW
Comment 56 Markus Keller CLA 2007-10-29 05:58:42 EDT
This fix has probably caused bug 207744.
Comment 57 Paul Webster CLA 2007-10-30 09:46:24 EDT
In I20071030-0010
PW
Comment 58 Paul Webster CLA 2007-12-14 12:47:03 EST
Created attachment 85296 [details]
Defer Plugin Loading v3.2.2

This is a 3.2.2 port that includes the MenuManager changes, ActionContributionItem changes, and PluginAction changes to defer loading of plugins with dropdown toolbars or dropdown actions placed in menus.

PW