Small CommandContributionItem improvement [message #668336] |
Thu, 05 May 2011 05:22  |
Eclipse User |
|
|
|
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 #668383 is a reply to message #668380] |
Thu, 05 May 2011 09:54  |
Eclipse User |
|
|
|
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
}
|
|
|
Powered by
FUDForum. Page generated in 0.17991 seconds