Bug 202187 - [Contributions] WorkbenchWindowControlContribution getWorkbenchWindow returns null
Summary: [Contributions] WorkbenchWindowControlContribution getWorkbenchWindow returns...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-09-04 14:30 EDT by Kris Klindworth CLA
Modified: 2009-11-19 15:26 EST (History)
4 users (show)

See Also:
remy.suen: pmc_approved-


Attachments
Simple RCP app demonstrating the issue (9.09 KB, application/zip)
2007-10-31 16:59 EDT, Kris Klindworth CLA
no flags Details
Patch to set the contribution's IWorkbenchWindow when it is being constructed. (962 bytes, patch)
2007-11-02 22:32 EDT, Remy Suen CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kris Klindworth CLA 2007-09-04 14:30:40 EDT
Build ID: I20070621-1340

The getWorkbenchWindow method in WorkbenchWindowControlContribution returns null for control contributions to the global toolbar.

Steps To Reproduce:
1. Create a control contribution that extends from WorkbenchWindowControlContribution.
2. In the createControl method call getWorkbenchWindow. This will be null at runtime.
3. Add the control contribution to a toolbar via the org.eclipse.ui.menus ext point.
4. Run the application and the call to getWorkbenchWindow will be null.

More information:
I put a break point in InternalControlContribution.setWorkbenchWindow(IWorkbenchWindow) and debugged, but never saw it get called.  I noticed TrimContributionManager calls this setWorkbenchWindow method, but that is used for Trim contributions, whereas I'm doing a toolbar contribution.
Comment 1 Remy Suen CLA 2007-10-28 23:30:06 EDT
Hm, that's a public method exposed by an internal class. Is it supposed to be used by adopters? The javadoc is kind of lacking so I guess the specifications haven't really been fleshed out. For all we know it could be spec'ed to allow for null returns.
Comment 2 Kris Klindworth CLA 2007-10-31 12:35:08 EDT
(In reply to comment #1)
> Hm, that's a public method exposed by an internal class. Is it supposed to be
> used by adopters? The javadoc is kind of lacking so I guess the specifications
> haven't really been fleshed out. For all we know it could be spec'ed to allow
> for null returns.
> 

Remy,

I'm not sure what you mean - WorkbenchWindowControlContribution [1] is not an internal class.  Per the javadoc, any control contributed via the org.eclipse.ui.menus ext point must extend this class.

I debugged the internal class, InternalControlContribution, looking for clues as to what the problem could be, but the API for getWorkbenchWindow is on WorkbenchWindowControlContribution.

[1] http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/menus/WorkbenchWindowControlContribution.html
Comment 3 Remy Suen CLA 2007-10-31 13:09:28 EDT
(In reply to comment #2)
> I'm not sure what you mean - WorkbenchWindowControlContribution [1] is not an
> internal class.  Per the javadoc, any control contributed via the
> org.eclipse.ui.menus ext point must extend this class.

I meant that InternalControlContribution is an internal class. But I see that WWCC is exposing it again as a public method. I must've gotten it confused with another class or something. Sorry about the confusion.
Comment 4 Remy Suen CLA 2007-10-31 15:34:05 EDT
Kris, could you attach a zip file of a simple project that shows this problem?
Comment 5 Kris Klindworth CLA 2007-10-31 16:59:07 EDT
Created attachment 81783 [details]
Simple  RCP app demonstrating the issue

The attached RCP app has a control contribution added to both the main toolbar, and also to the trim status area.  Clicking the button in the contribution will display the result of "getWorkbenchWindow()".  The main toolbar one will return null, and the trim contribution will return the correct value.
Comment 6 Remy Suen CLA 2007-11-02 22:32:06 EDT
Created attachment 82023 [details]
Patch to set the contribution's IWorkbenchWindow when it is being constructed.

Thanks for the test case, Kris, I have reproduced the error locally.
Comment 7 Paul Webster CLA 2008-04-08 14:10:06 EDT
Released to HEAD >20080408
PW
Comment 8 Paul Webster CLA 2008-04-29 14:59:34 EDT
In I20080429-0100
Comment 9 Shawn Minto CLA 2009-11-19 14:43:53 EST
This seems to be a problem again, but with the DynamicToolBarContributionItem class that was recently added.
Comment 10 Paul Webster CLA 2009-11-19 14:55:22 EST
Please open a new bug, as this is marked fixed in 3.4
PW
Comment 11 Paul Webster CLA 2009-11-19 14:55:35 EST
.
Comment 12 Remy Suen CLA 2009-11-19 15:26:37 EST
(In reply to comment #9)
> This seems to be a problem again, but with the DynamicToolBarContributionItem
> class that was recently added.

See bug 294118.