Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 385565 - [Contributions] Menu contribution processing has different results in 4.2 than 3.8
Summary: [Contributions] Menu contribution processing has different results in 4.2 tha...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P1 major (vote)
Target Milestone: 4.4 RC3   Edit
Assignee: Paul Webster CLA
QA Contact: Paul Webster CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-20 02:46 EDT by Uwe Stieber CLA
Modified: 2014-05-29 05:28 EDT (History)
11 users (show)

See Also:
pwebster: review+
bsd: review+


Attachments
Context menu as rendered with Eclipse 3.8 (6.55 KB, image/gif)
2012-07-20 11:20 EDT, Uwe Stieber CLA
no flags Details
Same menu, unmodified XML, but rendered by Eclipse 4.2 (8.36 KB, image/gif)
2012-07-20 11:24 EDT, Uwe Stieber CLA
no flags Details
menu order plugins (19.49 KB, application/zip)
2014-02-28 16:59 EST, Paul Webster CLA
no flags Details
MenuPersistence (9.83 KB, text/plain)
2014-03-28 15:10 EDT, Dave Dresser CLA
no flags Details
ContributionsAnalyzer (35.56 KB, text/plain)
2014-03-28 15:10 EDT, Dave Dresser CLA
no flags Details
menu order plugin with File from ActionBarAdvisor (19.86 KB, multipart/x-zip)
2014-05-09 14:45 EDT, Paul Webster CLA
no flags Details
2 plugins to simulate the problem (21.22 KB, multipart/x-zip)
2014-05-13 13:01 EDT, Paul Webster CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Uwe Stieber CLA 2012-07-20 02:46:03 EDT
The processing of the contributions done via the "org.eclipse.ui.menus" extension point does not end up with the same layout in 4.2 than we have in 3.8. This is extremely bad and is a blocker to support Eclipse 4.2 with the tools.cdt.tcf project.

Things observed so far:

- If two or more visible separators are left in the menu one directly after the others, they are not longer "collapsed" to a single separator.

In 4.2, you get something like

    ...
    ---------------
    ---------------
    ...

In 3.8, this is correctly detected and you end up with only one separator

    ...
    ---------------
    ...

- Somehow, the order of the processing changed.

In 4.2, you get something like

    ...
    Always Make Available Offline
    Add To                         >
    ...

In 3.8, the (correct/expected) order is

    ...
    Add To                         >
    Always Make Available Offline
    ...

- <dynamic ... /> contributions appears to have issues with the visibleWhen expression. Looks like as they are ignored in 4.2 for <dynamic .../> contributions.

Except for the processing order, these things are really blocking for us in order to support Eclipse 4.2.
Comment 1 Paul Webster CLA 2012-07-20 10:05:10 EDT
(In reply to comment #0)
> 
> In 4.2, you get something like
> 
>     ...
>     Always Make Available Offline
>     Add To                         >
>     ...
> 
> In 3.8, the (correct/expected) order is
> 
>     ...
>     Add To                         >
>     Always Make Available Offline
>     ...
> 

Could you please attach enough of your menuContributions to show the menu/menu item switch?

> - <dynamic ... /> contributions appears to have issues with the visibleWhen
> expression. Looks like as they are ignored in 4.2 for <dynamic .../>
> contributions.

This is bug 383815

PW
Comment 2 Uwe Stieber CLA 2012-07-20 11:20:54 EDT
Created attachment 218998 [details]
Context menu as rendered with Eclipse 3.8
Comment 3 Uwe Stieber CLA 2012-07-20 11:24:17 EDT
Created attachment 218999 [details]
Same menu, unmodified XML, but rendered by Eclipse 4.2
Comment 4 Uwe Stieber CLA 2012-07-20 11:25:21 EDT
For the "Add To" menu contribution, see o.e.tcf.te.ui.views/plugin.xml (http://git.eclipse.org/c/tcf/org.eclipse.tcf.git/tree/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml), line 284 - 314.


...
      <menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.categories">
         <menu
               id="org.eclipse.tcf.te.ui.views.menu.categories.add"
               label="%menu.categories.addto.label">
               <dynamic
                     id="org.eclipse.tcf.te.ui.views.dynamic.categories.add.multi"
                     class="org.eclipse.tcf.te.ui.views.handler.CategoryAddToContributionItem">
               </dynamic>
               <visibleWhen checkEnabled="false">
                  <with variable="selection">
                     <test property="org.eclipse.tcf.te.ui.views.validAddToCategoriesCount" value="(1-"/>
                     <iterate operator="and" ifEmpty="false">
                         <adapt type="org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable"/>
                     </iterate>
                  </with>
               </visibleWhen>
         </menu>

         ...
      </menuContribution>
...

The "Always available offline" menu item contributions is going to the same URI, but is from another plug-in. See o.e.tcf.te.tcf.ui/plugin.xml (http://git.eclipse.org/c/tcf/org.eclipse.tcf.git/tree/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml), line 279 - 290.

...
      <menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.categories">
         <command
               commandId="org.eclipse.tcf.te.tcf.ui.command.offline"
               helpContextId="org.eclipse.tcf.te.tcf.ui.command_Offline"
               id="org.eclipse.tcf.te.tcf.ui.commands.offline"
               label="%command.offline.label"
               mnemonic="f"
               style="push"
               tooltip="%command.offline.tooltip">
            <visibleWhen checkEnabled="true"/>
         </command>
      </menuContribution>
...

I've attached two screenshots of the same menu using the same unmodified XML source once rendered by Eclipse 3.8 and once rendered by Eclipse 4.2.
Comment 5 Thomas Schindl CLA 2012-07-20 11:30:35 EDT
On the ordering. I don't think there's a guarantee on which plugin.xml is processed first is there?

You can force some ordering like we do it on the model-extension where we order stuff based upon dependencies. So is there some dependency between ui and ui.views.
Comment 6 Uwe Stieber CLA 2012-07-20 11:46:25 EDT
o.e.tcf.te.tcf.ui requires o.e.tcf.ui.views.

There might be no guarantee for the plugin.xml processing order, but the rendering of UI contributions should be consistent. Otherwise you force projects which requires to support both Eclipse 3.8 and Eclipse 4.2 at the same time to have either to maintain two code streams or duplicate the contributions in the plugin.xml with a custom <visibleWhen .../> checking for the platform version. None of those options are really effort able.
Comment 7 Paul Webster CLA 2012-07-23 09:15:52 EDT
(In reply to comment #5)
> On the ordering. I don't think there's a guarantee on which plugin.xml is
> processed first is there?

IExtensionRegistry doesn't provide for an order when returning IExtensions (it can vary from install to install).

But in Platform UI we sort them by contributing plugin ID to provide some level of consistency.

And in org.eclipse.ui.menus, we are supposed to apply elements within one menuContribution in document order.

Those are 2 things we need to make sure we honour.  I think this is more of a slip-up on our part, since I think o.e.ui.menus should end up (more or less) in the same order.

PW
Comment 8 Martin Oberhuber CLA 2012-11-08 04:35:04 EST
CQ:WINDE4BLOCKING

This issue is blocking Wind River's adoption of Eclipse 4.x - we're going to stay on 3.x until this is fixed.
Comment 9 Martin Oberhuber CLA 2013-06-14 16:31:29 EDT
(In reply to comment #7)
> Those are 2 things we need to make sure we honour.  I think this is more of
> a slip-up on our part, since I think o.e.ui.menus should end up (more or
> less) in the same order.

Hmm, this sounds like not overly complex, can this be scheduled for 4.3.1 ?
Comment 10 Martin Oberhuber CLA 2014-01-22 05:15:48 EST
This bug is targeted for 4.4m5 , is it going to make the milestone ?
Can it be backported into 4.3.2 ?
Comment 11 Dani Megert CLA 2014-01-22 05:45:07 EST
(In reply to Martin Oberhuber from comment #10)
> This bug is targeted for 4.4m5 , is it going to make the milestone ?
> Can it be backported into 4.3.2 ?

This is
Comment 12 Dani Megert CLA 2014-01-22 05:48:21 EST
(In reply to Dani Megert from comment #11)
> (In reply to Martin Oberhuber from comment #10)
> > This bug is targeted for 4.4m5 , is it going to make the milestone ?
> > Can it be backported into 4.3.2 ?

The menu ordering is a sensitive area that we don't want to touch on the day we build our M5 candidate.

If we find a good fix early M6, we can still consider it for backporting.

Paul, can you look at this?
Comment 13 Dave Dresser CLA 2014-02-25 12:03:46 EST
We are having the same issue moving our RCP app from 3.x to 4.x.  We see issues with menu ordering both in the main menu and with order of contributions to the File and Help Menus where both eclipse plugins and our plugins are contributing.

The main menu ordering can be demonstrated with the following demo. I can provide more documentation on the Help and File menu ordering if needed. I haven't analyzed these yet.

Create a RCP application plugin using the Hello RCP template and add the following extension.
 <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="com.example.menu.order.myfirstmenu"
               label="First"
               mnemonic="F">
            <command
                  commandId="org.eclipse.ui.newWizard"
                  style="push">
            </command>
         </menu>
         <separator
                name="additions"
                visible="true">
         </separator>
         <menu
               id="com.example.menu.order.mylastmenu"
               label="Last"
               mnemonic="L">
            <command
                  commandId="org.eclipse.ui.window.newWindow"
                  id="newWindow"
                  label="new Window"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>

Create a second plugin to contribute to the main menu with the following extension:

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu?after=additions">
         <menu
               id="com.example.menu.mainmenu.contribution.configure"
               label="Configure">
            <command
                  commandId="org.eclipse.ui.help.aboutAction"
                  style="push">
            </command>
         </menu>
         <menu
               id="com.example.menu.mainmenu.contribution.example"
               label="Example">
            <command
                  commandId="org.eclipse.ui.help.aboutAction"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>

The Configure and Example menus show up first.  In Eclipse 3.x the Configure and Example menus are placed between First and Last. If I rename the separator to myadditions and change the corresponding locationURI, then the main menu looks like Eclipse 3.x, First Configure Example Last.
Comment 14 Paul Webster CLA 2014-02-28 16:59:20 EST
Created attachment 240419 [details]
menu order plugins

Here are the 2 plugins I used to test this.

On 3.8 I get: First Configure Example File Last

On 4.4 I get: File First Last Configure Example

PW
Comment 15 Dave Dresser CLA 2014-03-03 12:07:46 EST
I've also been looking at how org.eclipse.core.externaltools and org.eclipse.ui.externaltools contributes.  We use these plugins in our RCP application.  If I enable external tools and its required plugins with your attachments I get:

On 3.8: First Run Configure Example File Last

On 4.4: Run File First Last Configure Example

The behavior of the Run menu contribution seems to show also that the additions separator is not being processed or processed correctly.

Why did you put the File menu under its own MenuContribution?  

Was it a bug in 3.8 that the File menu showed up between First and Last (two menus from the next contribution)?
Comment 16 Paul Webster CLA 2014-03-03 17:07:57 EST
(In reply to Dave Dresser from comment #15)
> 
> Was it a bug in 3.8 that the File menu showed up between First and Last (two
> menus from the next contribution)?

That was the way it showed up in the test plugin.  I've added the File menu through the ApplicationActionBuilder now and removed it from the menuContribution:
MenuManager file = new MenuManager("&File", "file");
menuBar.add(file);
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

Now I get

3.8: File Configure Example First Last

4.4: File First Last Configure Example

PW
Comment 17 Dave Dresser CLA 2014-03-03 17:38:07 EST
Are you considering the 4.4 results correct?  Shouldn't it be after the separator but before the next item following the separator in the menu contribution?
Comment 18 Paul Webster CLA 2014-03-03 19:30:25 EST
(In reply to Dave Dresser from comment #17)
> Are you considering the 4.4 results correct?  Shouldn't it be after the
> separator but before the next item following the separator in the menu
> contribution?

I'm considering the 3.8 results "correct" for my example (although correct is a pretty loose term here, stable is probably better).  I was going to look into how to process the incoming contributions in 4.4 to get them applied similar to 3.8.

PW
Comment 19 Dave Dresser CLA 2014-03-04 08:18:31 EST
Regarding the Run menu contributed by external tools in our full application this is associated with a perspective.  On startup the Run menu shows up at the very end after Help.  However, if I close the perspective and reopen it the Run menu relocates to the additions separator.
Comment 20 Dave Dresser CLA 2014-03-28 15:09:13 EDT
In regards to ordering the menu's like they were ordered in Eclipse 3.x, I have some preliminary results which work well for my company's RCP app. The ordering is not totally the same but it is close. I have been working with Eclipse 4.2.2 because of product requirements. I have been experimenting with org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer. The modification that seems to work well for menus is in mergeContributions method when merging children into an existing contribution.  Instead of adding the menu contributions to the end of the list of children, I tried to account for the location URI in the list.  See attached ContributionsAnalyzer source.

I'm currently experimenting if similar logic helps with the toolbar and trimbar contributions (initially not but I haven't had a chance to step through with the debugger). 

Initially, I started with modifying the sort in org.eclipse.ui.internal.menus.MenuPersistence. My thinking was that starting from the top down (i.e. org.eclipse.ui.main...) it would help resolve ordering issues (see attached MenuPersistence).  I'm not sure that it helps though and maybe the HashMaps in ContributionsAnalyzer.mergeContributions functionally do a similar thing.
Comment 21 Dave Dresser CLA 2014-03-28 15:10:23 EDT
Created attachment 241399 [details]
MenuPersistence
Comment 22 Dave Dresser CLA 2014-03-28 15:10:47 EDT
Created attachment 241400 [details]
ContributionsAnalyzer
Comment 23 Paul Webster CLA 2014-03-28 15:19:07 EDT
Thanks Dave for your experimentation.

I hope to look at this next week.

PW
Comment 24 Paul Webster CLA 2014-04-30 10:23:25 EDT
I'd still like for analysis to be done in RC1

PW
Comment 25 Paul Webster CLA 2014-05-08 16:50:53 EDT
(In reply to Dave Dresser from comment #13)
> We are having the same issue moving our RCP app from 3.x to 4.x.  
> [...snip...]
> The Configure and Example menus show up first.  In Eclipse 3.x the Configure
> and Example menus are placed between First and Last. If I rename the
> separator to myadditions and change the corresponding locationURI, then the
> main menu looks like Eclipse 3.x, First Configure Example Last.

I'm able to fix the problem here by taking into account "after=additions", which was missing from 4.2 but in 3.8.


https://git.eclipse.org/r/26239

Uwe, What part or parts of TCF should I install to be able to reproduce your popup menus?

Should I be installing the Juno version?

PW
Comment 26 Uwe Stieber CLA 2014-05-09 01:14:55 EDT
Hi Paul,
the context menu screenshots had been taken from the "TCF Target Explorer" component. You can install what is available in either the Juno or Kepler release repositories. Once installed, open the view "System Management". Than you are in the place where I had been taking the original screenshots.

Thanks
Comment 27 Wojciech Sudol CLA 2014-05-09 04:12:41 EDT
Here is my approach that orders menu items based on 3.x alghoritm: https://git.eclipse.org/r/26255 .
I am still working on it but so far in my tests I get the same order as in 3.x.
Comment 28 Wojciech Sudol CLA 2014-05-09 06:20:32 EDT
(In reply to Uwe Stieber from comment #26)
> the context menu screenshots had been taken from the "TCF Target Explorer"
> component. You can install what is available in either the Juno or Kepler
> release repositories. Once installed, open the view "System Management".
> Than you are in the place where I had been taking the original screenshots.

What elements need to be added/selected in the "System Management" view to show the "Add To" and "Always Make Available Offline" items? For testing purposes I enabled them by removing visibleWhen conditions and it seems that neither my nor Paul's patch fixes the problem.

Also my patch does not work correctly with the org.eclipse.ui.externaltools contributions.
Comment 29 Uwe Stieber CLA 2014-05-09 06:47:55 EDT
(In reply to Wojciech Sudol from comment #28)
> What elements need to be added/selected in the "System Management" view to
> show the "Add To" and "Always Make Available Offline" items? For testing
> purposes I enabled them by removing visibleWhen conditions and it seems that
> neither my nor Paul's patch fixes the problem.

"Always Make Available Offline" ... To get this, you need to run a TCF agent on your host. The agent will be discovered and appear below the "Neighborhood" root node. You can build the agent from the org.eclipse.tcf.agent.git repository.

"Add To" ... It will be visible if there is more than one root node (category)
the selected node can be added to. If I recall it correctly, this should be the case for discovered TCF agents below the "Neighborhood" root node also.
Comment 30 Paul Webster CLA 2014-05-09 14:45:19 EDT
Created attachment 242911 [details]
menu order plugin with File from ActionBarAdvisor
Comment 32 Paul Webster CLA 2014-05-12 14:16:15 EDT
I think I still have more work to do here.

PW
Comment 33 Paul Webster CLA 2014-05-13 09:36:07 EDT
I grabbed the target explorer from luna (so I could pull in some TCF plugins from master) but now my context menu only has two items in it.

Is that expected?

PW
Comment 34 Wojciech Sudol CLA 2014-05-13 09:46:00 EDT
Paul,
You need to create some targets and follow instructions described in the comment #29.
Comment 35 Paul Webster CLA 2014-05-13 09:53:00 EDT
(In reply to Wojciech Sudol from comment #34)
> Paul,
> You need to create some targets and follow instructions described in the
> comment #29.

I had an agent running, and the context menu when the agent was selected was almost empty.  Contrast with Kepler Target Explorer running in a 4.4 SDK, where the context menu with the agent selected looked more like your screen shots.

PW
Comment 36 Uwe Stieber CLA 2014-05-13 10:02:55 EDT
(In reply to Paul Webster from comment #33)
> I grabbed the target explorer from luna (so I could pull in some TCF plugins
> from master) but now my context menu only has two items in it.
> 
> Is that expected?

Right, things changed a bit since I have filed the bug. You see "Connect" and "Show in" if you select a node below "Neighborhood"? For luna, yes, that's correct. By using "Connect", the node is "copied" to the "Connections" category and the context menu is much richer. Down side is, with the luna stream, the "Always Make Available Offline" menu entry is gone.
Comment 37 Uwe Stieber CLA 2014-05-13 10:16:19 EDT
With the luna stream of the Target Explorer, it looks like that the menu ordering is not different between 3.x and 4.3.x. Just checked with HEAD in both target Eclipse versions.
Comment 38 Paul Webster CLA 2014-05-13 10:21:05 EDT
(In reply to Uwe Stieber from comment #37)
> With the luna stream of the Target Explorer, it looks like that the menu
> ordering is not different between 3.x and 4.3.x. Just checked with HEAD in
> both target Eclipse versions.

OK, I can still reproduce the problem (sorta) with Kepler Target Explorer in both 3.8 and 4.4.

PW
Comment 39 Paul Webster CLA 2014-05-13 12:08:59 EDT
OK, there were 2 areas that we didn't port from the menu contribution processing in 3.8:

1) popup any contributions were processed before other popup contributions.

2) while menu contributions were processed in order and their children inserted in order, in 3.8 each contribution's children were merged into the menu starting at the insertion point.  In 4.x we were just appending each contribution's children to those already merged at the insertion point.  Our pre-processing merge optimization should insert each contributions children at the beginning of the merge list, (children within one contribution still in order relative to each  other).

https://git.eclipse.org/r/26465

PW
Comment 40 Paul Webster CLA 2014-05-13 13:01:10 EDT
Created attachment 243043 [details]
2 plugins to simulate the problem

usecase:

1) include the 2 plugins and launch and SDK

2) open the Popup Order view

3) open the context menu on the root.

In 3.8 the menu items are Show first, Show Second.  With 4.3 or 4.4, they're Show Second, Show first.

The patch fixes 4.x

PW
Comment 41 Eric Moffatt CLA 2014-05-13 15:00:21 EDT
Committed:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=9ad07e9258d2b49c461ef674e6b572cb80be9f84

Daniel will also independently review this tomorrow...
Comment 42 Daniel Rolka CLA 2014-05-14 05:45:42 EDT
(In reply to Eric Moffatt from comment #41)
> Committed:
> 
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/
> ?id=9ad07e9258d2b49c461ef674e6b572cb80be9f84
> 
> Daniel will also independently review this tomorrow...

Looks good for me too,
Daniel
Comment 43 Paul Webster CLA 2014-05-14 06:24:25 EDT
OK, this now addresses some order problems in the main menus and in popup menus.

PW
Comment 44 Paul Webster CLA 2014-05-26 14:52:57 EDT
(In reply to Paul Webster from comment #16)
> 
> 3.8: File Configure Example First Last
> 
> 4.4: File First Last Configure Example

This is failing again the RC2

PW
Comment 45 Wojciech Sudol CLA 2014-05-27 05:01:07 EDT
Reverting the first fix (commit 82c0f585aa66fef5b40cf6008e9f330200af3410, class MenuAdditionCacheEntry) and leaving the second commit (9ad07e9258d2b49c461ef674e6b572cb80be9f84) unchanged, brings back the correct order in both - main menu and popup menu. Tested with the plugins attached to comment 30 and comment 40. I am verifying if it is only a coincidence or if the second commit really fixes both issues.
Comment 46 Dani Megert CLA 2014-05-27 07:49:02 EDT
The project's context menu is mangled (try it on a Git shared Java project):

Team
Compare
Replace With
Restore from Local History...

are now no longer a group. This is a major regression which we have to fix for 4.4.


In addition,

Run As
Debug As

are still inverted with or without the fix, i.e. appear as

Debug As
Run As

This is not a regression and only nice to have for 4.4.
Comment 47 Wojciech Sudol CLA 2014-05-28 09:14:06 EDT
Here is a patch that fixes the two recent regression bugs - main menu and project's context menu order - https://git.eclipse.org/r/#/c/27445/ .
Now I am testing it to make sure it doesn't introduce any other regression.
Comment 48 Paul Webster CLA 2014-05-28 10:04:13 EDT
(In reply to Wojciech Sudol from comment #47)
> Here is a patch that fixes the two recent regression bugs - main menu and
> project's context menu order - https://git.eclipse.org/r/#/c/27445/ .

+1 Component lead.

PW
Comment 49 Paul Webster CLA 2014-05-28 10:06:13 EDT
(In reply to Dani Megert from comment #46)
> are still inverted with or without the fix, i.e. appear as
> 
> Debug As
> Run As


Our fix still doesn't address this, so I've opened Bug 436062

PW
Comment 51 Dani Megert CLA 2014-05-29 05:28:05 EDT
Verified in I20140528-2000 using steps from comment 40 and comment 46.