Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Dynamically change icon on the toolbar(Possible to change icon to bigger size on the toolbar dynamically?)
Dynamically change icon on the toolbar [message #1396362] Tue, 08 July 2014 07:44 Go to next message
Page Wang is currently offline Page WangFriend
Messages: 16
Registered: July 2009
Junior 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 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 194
Registered: January 2012
Senior Member

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.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Dynamically change icon on the toolbar [message #1396999 is a reply to message #1396715] Wed, 09 July 2014 03:59 Go to previous messageGo to next message
Page Wang is currently offline Page WangFriend
Messages: 16
Registered: July 2009
Junior Member
Thanks, Brian. We are still on Eclipse 3.8 and not ready to upgrade to Eclipse 4.x yet.

Another thing I tried is modify ApplicationActionBarAdvisor::fillCoolBar(), and swap the icon to a larger size, just to see if window is able to display.
    protected void fillCoolBar(ICoolBarManager coolBar) {
        IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
        coolBar.add(new ToolBarContributionItem(toolbar, "main"));   
        toolbar.add(openViewAction);
        toolbar.add(messagePopupAction);
        toolbar.add(switchIconAction);
        
        switchIconAction.setToolBarMgr((ToolBarManager)toolbar);
        
        ImageDescriptor desc = org.eclipse.ui.tutorials.rcp.part3.Part3Plugin.getImageDescriptor(
              "/icons/default_search_32.png" ); 
        openViewAction.setImageDescriptor(desc);
    }


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?
Re: Dynamically change icon on the toolbar [message #1397293 is a reply to message #1396999] Wed, 09 July 2014 14:11 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 194
Registered: January 2012
Senior Member

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.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Dynamically change icon on the toolbar [message #1397681 is a reply to message #1397293] Thu, 10 July 2014 02:59 Go to previous message
Page Wang is currently offline Page WangFriend
Messages: 16
Registered: July 2009
Junior Member
Thanks. Bug 439304 is filed.
Previous Topic:How do we add a combo control to the main toolbar and update it when a new editor is activated
Next Topic:Perspective UI Design best practices
Goto Forum:
  


Current Time: Fri Dec 19 12:13:18 GMT 2014

Powered by FUDForum. Page generated in 0.01666 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software