public void invoke(Widget toCall, DeviceResourceDescriptor newDescriptor) {
if (newDescriptor == oldDescriptor) {
return;
}
ResourceManager mgr = JFaceResources.getResources(toCall.getDisplay());
Object newResource;
try {
newResource = newDescriptor == null? null : mgr.create(newDescriptor);
} catch (DeviceResourceException e1) {
WorkbenchPlugin.log(e1);
return;
}
try {
method.invoke(toCall, new Object[] {newResource});
} catch (IllegalArgumentException e) {
throw e;
} catch (IllegalAccessException e) {
WorkbenchPlugin.log(e);
return;
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof RuntimeException) {
throw (RuntimeException)e.getTargetException();
}
WorkbenchPlugin.log(e);
return;
}
// Deallocate the old image
if (oldDescriptor != null) {
// Dispose the image
mgr.destroy(oldDescriptor);
}
// Remember the new image for next time
oldDescriptor = newDescriptor;