Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » is it possible to replace the default item icon in toolbar?
is it possible to replace the default item icon in toolbar? [message #517830] Tue, 02 March 2010 09:46 Go to next message
Eclipse UserFriend
Originally posted by: cheney_chen.i-len.com

Hi,

I'm attempting to add some default actions (e.g. Save action) to an RCP
application. I know this can do in ActionBarAdvisor that use the
ActionFactory, such as:

saveAction = ActionFactory.SAVE.create(window);
register(saveAction);


And then in fillCoolBar:

IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
toolbar.add(saveAction);

The Save item would on the toolbar with the default icon.Because The
default icon register in SaveAction's constructor method:

/**
* Create an instance of this class
*
* @param window the window
*/
public SaveAction(IWorkbenchWindow window) {
super(WorkbenchMessages.SaveAction_text, window);
setText(WorkbenchMessages.SaveAction_text);
setToolTipText(WorkbenchMessages.SaveAction_toolTip);
setId("save"); //$NON-NLS-1$
window.getWorkbench().getHelpSystem().setHelp(this,
IWorkbenchHelpContextIds.SAVE_ACTION);
setImageDescriptor(WorkbenchImages
.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT));
setDisabledImageDescriptor(WorkbenchImages

..getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT_DISAB LED));
setActionDefinitionId(IWorkbenchCommandConstants.FILE_SAVE);
((WorkbenchWindow)window).addBackgroundSaveListener(this);
}

So I want to know is it possible the replace the Save action's default
icon in RCP application? If yes, How?

Best Regards,
Cheney
Re: is it possible to replace the default item icon in toolbar? [message #517831 is a reply to message #517830] Tue, 02 March 2010 09:59 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
you have the action so just say...

saveaction.setImageDescriptor(u r image descriptor)....


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: is it possible to replace the default item icon in toolbar? [message #517848 is a reply to message #517831] Tue, 02 March 2010 05:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cheney_chen.i-len.com

thanks for your reply. That would be a choice as you said.

I know that it can use the menu extension to definition the menu or
toolbar, such as:

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu id="file" label="File" mnemonic="F">
<command
commandId="org.eclipse.ui.file.save"
>
</command>
</menu>
</menuContribution>
</extension>

So I guess it would be ok to redefinition the new icon in plugin.xml. I
will test it then put the result here.

Thanks again.
Cheney

vijay wrote:
> you have the action so just say...
>
> saveaction.setImageDescriptor(u r image descriptor)....
Re: [SOLVED]is it possible to replace the default item icon in toolbar? [message #518101 is a reply to message #517848] Wed, 03 March 2010 03:31 Go to previous message
Eclipse UserFriend
Originally posted by: cheney_chen.i-len.com

Hi All,

I use the menu extension to define the menu and toolbar, and set the
icon attribute to replace the standard action's default icon, it works
fine as expected.

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="file"
label="File">
<command
commandId="org.eclipse.ui.file.save"
icon="icons/save.png"
style="push">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="org.eclipse.ui.workbench.file">
<command
commandId="org.eclipse.ui.file.save"
icon="icons/save.png"
style="push">
</command>
</toolbar>
</menuContribution>
</extension>

or use the commandImage extension to prevent set the icon attribute
duplicate.

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="file"
label="File">
<command
commandId="org.eclipse.ui.file.save"
style="push">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="org.eclipse.ui.workbench.file">
<command
commandId="org.eclipse.ui.file.save"
style="push">
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commandImages">
<image
commandId="org.eclipse.ui.file.save"
icon="icons/save.png">
</image>
</extension>

Best Regards,
Cheney

Cheney Chen wrote:
> thanks for your reply. That would be a choice as you said.
>
> I know that it can use the menu extension to definition the menu or
> toolbar, such as:
>
> <extension
> point="org.eclipse.ui.menus">
> <menuContribution
> locationURI="menu:org.eclipse.ui.main.menu">
> <menu id="file" label="File" mnemonic="F">
> <command
> commandId="org.eclipse.ui.file.save"
> >
> </command>
> </menu>
> </menuContribution>
> </extension>
>
> So I guess it would be ok to redefinition the new icon in plugin.xml. I
> will test it then put the result here.
>
> Thanks again.
> Cheney
>
> vijay wrote:
>> you have the action so just say...
>>
>> saveaction.setImageDescriptor(u r image descriptor)....
Previous Topic:Interrupt the UI Thread
Next Topic:Change Splash Image depending on a user preference
Goto Forum:
  


Current Time: Sat Dec 20 18:49:18 GMT 2014

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

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