Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SWT utility method for disposing of a resource when the disposal of a widget occurs.
/**
* SWT Utilities.
*
* @author Kevin Sawicki (kevin@github.com)
*/
public abstract class SwtUtils {
/**
* Dispose of resource when widget is disposed.
*
* This method immediately disposes of the resource if the widget is already
* disposed.
*
* @param resource
* @param widget
*/
public static void hookDispose(final Resource resource, Widget widget) {
if (widget == null || resource == null)
return;
if (!widget.isDisposed())
widget.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
resource.dispose();
}
});
else
resource.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment