Bug 411765 - AbstractContributionFactory doesn't work in 4.x
Summary: AbstractContributionFactory doesn't work in 4.x
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-27 08:14 EDT by Ralph P CLA
Modified: 2021-02-07 02:09 EST (History)
7 users (show)

See Also:


Attachments
Exported plug-in that makes a contribution to the menu bar (13.96 KB, application/zip)
2013-06-27 08:14 EDT, Ralph P CLA
no flags Details
Expected result from the attached plug-in project (4.33 KB, image/png)
2013-06-27 08:15 EDT, Ralph P CLA
no flags Details
Dynamic toolbar example (5.89 KB, application/zip)
2014-02-17 08:54 EST, Christian Pontesegger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph P CLA 2013-06-27 08:14:41 EDT
Created attachment 232836 [details]
Exported plug-in that makes a contribution to the menu bar

Hi,

I've implemented a plug-in in Eclipse 3.7 which can dynamically populate the Eclipse menu bar.
To achieve this I had to extend the AbstractContributionFactory, implemented its createContributionItems(...) method and register the factory to the IMenuService of the WorkbenchWindow.

The code works fine in Eclipse 3.7, even in Eclipse 3.8.

The only problem in Eclipse 4.2.2 is now that the AbstractContributionFactory#createContributionItems() method is never called.
The javadoc says:
"This method is not meant to be called by clients. It will be called by the menu service at the appropriate time."

That doesn't seem to be true in Eclipse 4.3 (also tried with 4.2.2).

I attached a simple project that contributes to the menu bar on startup.
It works in Eclipse 3.7 or higher, but not 4.x.
Comment 1 Ralph P CLA 2013-06-27 08:15:32 EDT
Created attachment 232837 [details]
Expected result from the attached plug-in project
Comment 2 Curtis Windatt CLA 2013-06-27 09:39:47 EDT
Moving to Platform UI
Comment 3 Paul Webster CLA 2013-06-27 09:44:10 EDT
The method should be called in Kepler (4.3).  If you contribute to a menu, we got that working.  Is it that you are contributing to the main menu bar?

PW
Comment 4 Ralph P CLA 2013-06-27 09:47:49 EDT
(In reply to comment #3)
> The method should be called in Kepler (4.3).  If you contribute to a menu,
> we got that working.  Is it that you are contributing to the main menu bar?
> 
> PW

Yes, I'm contributing to the main menu bar (see Attachments).
Comment 5 Ralph P CLA 2013-06-27 10:44:35 EDT
I encountered another problem that is related to this one:

Contributing to an editor context menu in Eclipse 4.x works in principle. 
But the invocation of the method 
org.eclipse.core.commands.AbstractHandler(Object) 
does not work properly for me:

Eclipse 4.2.2:
Method is called with an 
org.eclipse.e4.ui.workbench.modeling.ExpressionContext 
as parameter, instead of an 
org.eclipse.core.expressions.EvaluationContext (Eclipse 3.7).

This has two downsides:
1) It adds a dependency to org.eclipse.e4...
2) It has discouraged access:
Discouraged access: The type ExpressionContext is not accessible due to restriction on required library C:\Eclipse\Eclipse 4.2.2 SDK\plugins\org.eclipse.e4.ui.workbench_0.11.0.v20130125-100758.jar

Eclipse 4.3:
The method is not called at all. The ExpressionContext class does not exist (at least not in the same package).

The effect is, that the editor contribution is always disabled for me. I managed to get it to work in Eclipse 4.2.2 by using the ExpressionContext, though.
Comment 6 Paul Webster CLA 2013-06-27 11:08:12 EDT
Those are the implementation classes, you should use the interface to access it: org.eclipse.core.expressions.IEvaluationContext

Which method call are you mentioning?  org.eclipse.core.commands.AbstractHandler(Object) doesn't seem correct.

PW
Comment 7 Ralph P CLA 2013-06-27 11:19:05 EDT
(In reply to comment #6)
> Those are the implementation classes, you should use the interface to access
> it: org.eclipse.core.expressions.IEvaluationContext
>> Of course, thank you!
> 
> Which method call are you mentioning? 
> org.eclipse.core.commands.AbstractHandler(Object) doesn't seem correct.
> 
> PW

Sorry, I was to hasty on this one!

org.eclipse.core.commands.AbstractHandler.setEnabled(Object) is the correct method.
Comment 8 Christian Pontesegger CLA 2014-02-17 08:51:25 EST
I ran into a similar problem which might be related:

When contributing via ContributionFactory to a view that was not rendered before, the factory works as expected. But when contributing to an already visible view the contribution is not used. Even calling
((ViewPart) part).getViewSite().getActionBars().updateActionBars();
will not help.

Might be related to the main toolbar/menu problem as these components are also already rendered when the factory comes into play.
Comment 9 Christian Pontesegger CLA 2014-02-17 08:54:27 EST
Created attachment 240030 [details]
Dynamic toolbar example

Shows a new toolbar button in "Package Explorer": Example.
When the button is clicked a dynamic contribution is added (see command handler).
The new toolbar entry is not shown. After closing and re-opening the Package Explorer view the dynamic entry is visible.
Comment 10 Holger Schill CLA 2014-09-10 08:48:32 EDT
ping. This is still an issue with Luna.
Comment 11 Daniel Rolka CLA 2014-09-11 07:50:21 EDT
(In reply to Holger Schill from comment #10)
> ping. This is still an issue with Luna.

Nobody is looking at it at this moment. Patch would be appreciated - http://wiki.eclipse.org/Platform_UI/How_to_Contribute

thanks in advance for your help,
Daniel
Comment 12 Denis Anisimov CLA 2015-10-05 04:32:39 EDT
This bug exists in Mars as well.

It's not possible to register AbstractContributionFactory for status line toolbar.

As I understand WorkbenchMenuService is responsible for factory registration.
Its method addContributionFactory contains the code:


MenuLocationURI location = new MenuLocationURI(factory.getLocation());
.......

if (inToolbar(location)) {
			if (MenuAdditionCacheEntry.isInWorkbenchTrim(location)) {
				// processTrimChildren(trimContributions, toolBarContributions,
				// configElement);
			} else {


As you can see there is a special section which should handle the case of "toolbar:org.eclipse.ui.trim.status" URL (status line toolbar) but it does nothing: code is commented out.

The same is in Luna.
Comment 13 Stephan Herrmann CLA 2016-11-01 09:08:51 EDT
This bug was mentioned in a comment in http://stackoverflow.com/questions/39225379/multiple-eclipse-instances-with-oomph as an example of Eclipse's decreasing quality / lack of reaction to bug reports.
Just saying.
Comment 14 Eclipse Genie CLA 2021-02-07 02:08:51 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.

--
The automated Eclipse Genie.
Comment 15 Eclipse Genie CLA 2021-02-07 02:09:09 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.

--
The automated Eclipse Genie.
Comment 16 Eclipse Genie CLA 2021-02-07 02:09:20 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.

--
The automated Eclipse Genie.