Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Small CommandContributionItem improvement
Small CommandContributionItem improvement [message #668336] Thu, 05 May 2011 09:22 Go to next message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
This class has supports for creating buttons, but doesn't use the command image.

Here is what I propose:

public void fill(Composite parent) {
if (command == null) {
return;
}
if (widget != null || parent == null) {
return;
}

// Buttons don't support the pulldown style
int tmpStyle = style;
if (tmpStyle == STYLE_PULLDOWN)
tmpStyle = STYLE_PUSH;

Button item = new Button(parent, tmpStyle);
item.setData(this);
if (workbenchHelpSystem != null) {
workbenchHelpSystem.setHelp(item, helpContextId);
}
item.addListener(SWT.Dispose, getItemListener());
item.addListener(SWT.Selection, getItemListener());

//////////////////////// BEGIN CHANGES
if (icon != null) {
icon.setImage(icon.createImage());
}
//////////////////////// END CHANGES
widget = item;

update(null);
updateIcons();

bindingService.addBindingManagerListener(bindingManagerListe ner);

}


I hope you like this improvement.

David
Re: Small CommandContributionItem improvement [message #668359 is a reply to message #668336] Thu, 05 May 2011 11:52 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 05/05/11 2:52 PM, David Pérez wrote:
> This class has supports for creating buttons, but doesn't use the
> command image.

> //////////////////////// BEGIN CHANGES
> if (icon != null) {
> icon.setImage(icon.createImage());
> }
> //////////////////////// END CHANGES

What are you trying to do here? images for the contributions are set on
the item in the updateIcons() method.

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Small CommandContributionItem improvement [message #668380 is a reply to message #668359] Thu, 05 May 2011 13:51 Go to previous messageGo to next message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
You're right Prakash!
But in 3.6, updateIcons() only handles MenuItem and ToolItem's.

So my proposal is now:

protected  void updateIcons() {
if (widget instanceof MenuItem) {
                             .. ...
} else if (widget instanceof ToolItem) {
                             .. ...

                //////BEGIN CHANGES
                else if (widget instanceo f Button) {
                        Button butt on = (Button)widget;
LocalResourceManager m = new LocalResourceManager(JFaceR esources
.getResources());
try {
button.setImage(icon == null ? null : m.createImage(ic on));
} catch (DeviceResourceException e) {
icon = ImageDescriptor.getMissingImageDescriptor();
item.setImage(m.createImage(icon));
// as we replaced the failed icon, log the message
Re: Small CommandContributionItem improvement [message #668383 is a reply to message #668380] Thu, 05 May 2011 13:54 Go to previous message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
I don't know why, but my previous code was clipped:

protected  void updateIcons() {
if (widget instanceof MenuItem) {
                            .... .
} else if (widget instanceof ToolItem) {
                           .....

       //////BEGIN CHANGES
        else if (widget instanceof Button) {
              Button button = (Button)widge t;
LocalResourceManager m = new LocalResourceManager(JFaceR esources.getResources());
try {
button.setImage(icon == null ? null : m.createImage(ic on));
} catch (DeviceResourceException e) {
icon = ImageDescriptor.getMissingImageDescriptor();
item.setImage(m.createImage(icon));
StatusManager.getManager().handle(
new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, "Failed to load image", e)); //$NON-NLS-1$
}
disposeOldImages();
localResourceManager = m;
       }
       //////END CHANGES
}
Previous Topic:Rename Java Package programmatically
Next Topic:Refresh Workspace
Goto Forum:
  


Current Time: Fri Apr 19 18:39:38 GMT 2024

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

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

Back to the top