Bug 12116 - [Contributions] widgets: MenuManager.setImageDescriptor() method needed
Summary: [Contributions] widgets: MenuManager.setImageDescriptor() method needed
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P5 enhancement with 2 votes (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2002-03-22 09:38 EST by Alex Sprizhitsky CLA
Modified: 2007-09-18 14:13 EDT (History)
5 users (show)

See Also:


Attachments
Patch to add two new constructors for instantiating a MenuManager with an ImageDescriptor. (7.81 KB, patch)
2007-08-15 21:03 EDT, Remy Suen CLA
no flags Details | Diff
MenuManager + ImageDescriptor v02 (7.30 KB, patch)
2007-08-16 14:52 EDT, 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 Alex Sprizhitsky CLA 2002-03-22 09:38:13 EST
Currently there seems to be no API to assign image to menu item that contains 
submenu, the only way is to override MenuManager.fill() methods.

That seems to be inconsistent.
Comment 1 Kevin Haaland CLA 2002-05-31 16:43:34 EDT
Consider as a post 2.0 enhancement
Comment 2 Randy Giffen CLA 2002-08-09 16:06:56 EDT
Reopen to investigate
Comment 3 Simon Arsenault CLA 2002-09-04 11:58:06 EDT
Maybe someone from the community would be interested in coming up with a design 
for this? If so, please annotate this report and include a date when the design 
would be done and implementation could start.
Comment 4 Peter Schaich CLA 2004-07-21 05:53:12 EDT
how is the state of this enhancement? It would be nice to have this in Eclipse 3.0.
Comment 5 Michael Van Meekeren CLA 2006-04-21 13:56:46 EDT
Moving Dougs bugs
Comment 6 Paul Webster CLA 2007-04-05 19:01:18 EDT
Assigning to component owner
PW
Comment 7 Remy Suen CLA 2007-05-29 06:41:19 EDT
What kind of challenges are involved with implementing this?
Comment 8 Paul Webster CLA 2007-05-29 08:47:26 EDT
You would potentially need to add it to the constructor, then include it in the update logic that is updating menuText.  Using a local resource manager to keep track of the Image from the descriptor, and disposing the resource manager at the correct time.

Then this could be considered for 3.4

PW
Comment 9 Remy Suen CLA 2007-08-15 08:16:23 EDT
(In reply to comment #8)
> You would potentially need to add it to the constructor, then include it in the
> update logic that is updating menuText.

What do you mean by "updating menuText"? That field in MenuManager seems to only ever get set once in the constructor. 

> Using a local resource manager to keep
> track of the Image from the descriptor, and disposing the resource manager at
> the correct time.

This "local resource manager" makes it sound more complicated then just holding on to a reference to the Image from createImage() and then calling dispose() within MenuManager's dispose() implementation. Is there something inherently wrong with just doing this?
Comment 10 Paul Webster CLA 2007-08-15 09:02:55 EDT
(In reply to comment #9)
> 
> What do you mean by "updating menuText"? That field in MenuManager seems to
> only ever get set once in the constructor. 

You would need the complimentory image code in update(String).

> This "local resource manager" makes it sound more complicated then just holding
> on to a reference to the Image from createImage() and then calling dispose()
> within MenuManager's dispose() implementation. Is there something inherently
> wrong with just doing this?

You want the pattern similar to ActionContributionItem or CommandContributionItem.  Use a LocalResourceManager to turn your ImageDescriptor into an Image.  That way, if there same image is used mutliple times in your program, then it only gets instantiate once.

disposing the local resource manager will remove that specific ref to the Image.

PW

Comment 11 Remy Suen CLA 2007-08-15 21:03:45 EDT
Created attachment 76186 [details]
Patch to add two new constructors for instantiating a MenuManager with an ImageDescriptor.

This patch implements the desired functionality based on Paul's comment #10 using some copy/paste magic from CommandContributionItem.

The bug's summary's original request for a setImageDescriptor(ImageDescriptor) method is not implemented because there is currently no API for setting the text for the menu so I also chose not to expose any new API for setting the image for the menu.

New API:
-MenuManager(String, ImageDescriptor)
-MenuManager(String, ImageDescriptor, String)
-ImageDescriptor getImage()

Paul, 7 out of the 674 JFace tests (via running org.eclipse.jface.tests.AllTests) failed both before and after I applied the patch. Running 3.4M1 on 32-bit Windows XP.

Failures:
SimpleVirtualLazyTreeViewerTest
-testCreation
-testRemoveAt
VirtualLazyTreeViewerTest
-testDeleteSibling
-testInsertSibling
-testInsertSiblings
-testSomeChildrenChanged
-testWorldChanged
Comment 12 Paul Webster CLA 2007-08-16 14:52:58 EDT
Created attachment 76251 [details]
MenuManager + ImageDescriptor v02

This is a few updates to Remy's patch.

1) Since the 2 arg constructor could be ambiguous with MenuManager(text, id), I've just removed it ... if you want an icon, we'll just say use the 3 arg constructor

2) I've added the disposeOldImages() to the dispose() call

3) I've added a small optimization that checks for image==null and doesn't create a LocalResourceManager if it is not necessary.

All of the JFace and UI test pass for me with the patch.

Remy, if these changes are fine I'll commit them.

PW
Comment 13 Remy Suen CLA 2007-08-16 15:05:33 EDT
(In reply to comment #12)
> Remy, if these changes are fine I'll commit them.

Hi Paul, the updated patch looks okay. I applied it locally and also reran my test plug-in and the image is getting displayed fine in my view's context menu. Thanks for the help! :)
Comment 14 Paul Webster CLA 2007-08-16 15:22:07 EDT
Released into HEAD >20070816

Thanx, Remy.
PW
Comment 15 Paul Webster CLA 2007-09-18 14:13:51 EDT
In I20070918-0010
PW