Dynamically change icon on the toolbar [message #1396362] |
Tue, 08 July 2014 07:44 |
Page Mising name Messages: 31 Registered: July 2009 |
Member |
|
|
Hi,
We need to add an option to our RCP application's view toolbar, where it will switch the icons to bigger size.
To try out, I used the sample from rcp tutorial part 3 (http://eclipse.org/articles/Article-RCP-3/tutorial3.html), added a new action called "SwitchIconAction" to the toolbar, if user clicks on it, it will get the ToolBarManager, get all the items on this toolbar, then set the icon to a larger size icon.
IContributionItem[] tbItems = tbMgr.getItems();
if( tbItems != null && tbItems.length > 0 )
{
for( IContributionItem item : tbItems )
{
if( item instanceof ActionContributionItem )
{
IAction action = ( (ActionContributionItem) item ).getAction();
// find the 1st action and change it's icon to 32x32
ImageDescriptor desc = org.eclipse.ui.tutorials.rcp.part3.Part3Plugin.getImageDescriptor(
"/icons/default_search_32.png" ); //$NON-NLS-1$
action.setImageDescriptor( desc );
action.setHoverImageDescriptor( desc );
//break;
}
}
}
tbMgr.update( true );
I do see the icon is changed, but not displayed in 32x32. I have attached my test program.
Is this supported by Eclipse? Is there a way to achieve this?
Thanks for the help!
|
|
|
Re: Dynamically change icon on the toolbar [message #1396715 is a reply to message #1396362] |
Tue, 08 July 2014 17:23 |
Eclipse User |
|
|
|
Hmm, interesting. I'm not sure if this will work, but I'd suggest using the Eclipse 4.x model instead where you can update the icons shown explicitly. Any MUILabel element can have its icon URI explicitly updated, which should take immediate effect. You also need to explicitly deal with the overridden icon. Take a look at the Modelled Workbench CSS engine I put together for an example of how to change the icon URI.
I wonder if you might hit a deeper problem though as most of the tool items are hosted in a native ToolBar and I think they're restricted to 16 pixels on some platforms (Windows). Be sure to report back.
Brian.
|
|
|
|
Re: Dynamically change icon on the toolbar [message #1397293 is a reply to message #1396999] |
Wed, 09 July 2014 14:11 |
Eclipse User |
|
|
|
Page Wang wrote on Tue, 08 July 2014 23:59
This does change the icon to 32x32, and interesting I found is I only need to change the icon for the very 1st item, the rest of the toolbar items will be also enlarged; however, if I change any icon that's not the 1st toolbar item, it has no effect on the size.
Is this an Eclipse bug?
It could be a restriction of the underlying native widget. File a bug with SWT with a reproducible test case.
Brian.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03843 seconds