Bug 306036 - [Contributions] Duplicate menu item contributions creates duplicate menu items
Summary: [Contributions] Duplicate menu item contributions creates duplicate menu items
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-16 11:59 EDT by Chris Frank CLA
Modified: 2019-09-06 15:37 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Frank CLA 2010-03-16 11:59:57 EDT
Build Identifier: M20090211-1700

I have a plugin and several fragments for my plugin. These fragments are intended to be delivered to different end users, separately in most cases. The plugin contributes menu items that I want to be available to all fragments, and the fragments contribute menu items that apply to only that fragment. However, some of these fragment-specific menu items are the same across fragments, and since sometimes these fragments are delivered together, we get duplicate menu items when really we just want one.

In case I have not explained clearly enough, here is an example structure:
MyPlugin
 - MyFragmentA
    - Contributes MenuItemA to 'File' menu
    - Contributes MenuItemB to 'File' menu
 - MyFragmentB
    - Contributes MenuItemA to 'File' menu
    - Contributes MenuItemC to 'File' menu

If I deliver the two plugins together, I get this:
 - MenuItemA
 - MenuItemA
 - MenuItemB
 - MenuItemC

When what I want is this:
 - MenuItemA
 - MenuItemB
 - MenuItemC

Note that the implementation of each action is the same for each fragment, except for the icon file's path.

I am not sure whether this is intended behavior, but I also can't think of any reason why two actions with the same id, class, and path should ever be duplicated, even if listed twice in plugins. Maybe I am misusing the framework? I'm guessing, however, that's it's a minor deficiency.


Reproducible: Always

Steps to Reproduce:
N/A
Comment 1 Thomas Schindl CLA 2010-04-06 08:50:45 EDT
And which one should win? The first one loaded? This would lead to strange behavior because for Customer A it will show the icon from "Fragment A" and for Customer B the one from "Fragment B" (the order is random and defined by the order Equinox resolves the plugin.xml).
Comment 2 Chris Frank CLA 2010-04-06 09:07:24 EDT
In my case the icons are the same, the paths are only different because they are delivered with the fragments (I believe this is because they cannot refer to icons in the plugin).

Alternatively, having different icons for the same contribution isn't something I would expect anyone to do. We could consider whether different versions of the same plugin might create this situation, but I think p2 prevents that from happening.

It would probably be fine to just choose whichever is discovered first, as long as the other important fields are equal (id, class, menu path, etc.).
Comment 3 Paul Webster CLA 2010-04-06 09:33:15 EDT
Because in the case of menus IDs are not unique (this is a legacy requirement) we have no way of guessing which menu item to pick.  If the objects were truly equal we could only add one, but even in your case that's not true.

You are acting as an aggregator for multiple functionality, it sounds like you are using fragments to deliver slightly different product configurations.  I think you have 2 choices:

1) if MenuItemA is common to your 2 fragments, include it from a common fragment.

2) in fragmentB, add a visibleWhen that checks to see if fragmentA is installed so you can be not visible.  See http://wiki.eclipse.org/Command_Core_Expressions#Property_Testers

Once the system is running, the system doesn't usually know which Extension comes from which fragment.  They live in the host bundle namespace and host bundle classpath.

PW
Comment 4 Chris Frank CLA 2010-04-07 10:00:13 EDT
What do you mean by "in the case of menus IDs are not unique"?

The action set ID? The action ID? Some other ID I might not be aware of?
Comment 5 Paul Webster CLA 2010-04-07 10:35:41 EDT
(In reply to comment #4)
> The action set ID? The action ID? Some other ID I might not be aware of?

The contribution ID (which most times, but not always, is the action ID).

Most SWT menu items are rendered by a matching IContributionItem.  In the case of IActions, when placed in the menu we create the matching ActionContributionItem.

When you start looking at the MenuManager it will have a set of IContributionItems where any number of them can have the same ID.

PW
Comment 6 Chris Frank CLA 2010-04-09 13:11:50 EDT
I'm trying to understand what you're saying but the lack of subject knowledge is a significant barrier.

You said that if they were truly equal it would make sense to just add one. What about this situation?

ContributionC (in fragment A)
ID: com.company.functionC
class: com.company1.ClassA (in host plugin)
icon path: /icons/iconA.png (in fragment A)
menu path: /com/company/additions

ContributionC (in fragment B)
ID: com.company.functionC
class: com.company1.ClassA (in host plugin)
icon path: /icons/iconA.png (in fragment B)
menu path: /com/company/additions

Would they be considered identical in this case, even though the icons are technically separate files? Or would you have to do the comparison later on, when the icons have been loaded and the IDs may not be unique any more?
Comment 7 Chris Frank CLA 2010-04-09 13:13:16 EDT
Sorry, that should be:

ContributionC (in fragment A)
ID: com.company.functionC
class: com.company.ClassC (in host plugin)
icon path: /icons/iconC.png (in fragment A)
menu path: /com/company/additions

ContributionC (in fragment B)
ID: com.company.functionC
class: com.company.ClassC (in host plugin)
icon path: /icons/iconC.png (in fragment B)
menu path: /com/company/additions
Comment 8 Paul Webster CLA 2010-11-09 10:26:04 EST
(In reply to comment #7)
> ContributionC (in fragment A)
> ID: com.company.functionC
> class: com.company.ClassC (in host plugin)
> icon path: /icons/iconC.png (in fragment A)
> menu path: /com/company/additions
> 
> ContributionC (in fragment B)
> ID: com.company.functionC
> class: com.company.ClassC (in host plugin)
> icon path: /icons/iconC.png (in fragment B)
> menu path: /com/company/additions

The problem is we don't see /icons/iconC.png, instead we see something like:
bundleentry://34//icons/iconC.png and bundleentry://182//icons/iconC.png

We can merge menus that seem to come from separate contributions (most of the time) but not these actions, as they're different.

PW
Comment 9 Eclipse Webmaster CLA 2019-09-06 15:37:25 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.