Created
April 26, 2011 16:50
-
-
Save kevinsawicki/942643 to your computer and use it in GitHub Desktop.
SWT utility method for disposing of a resource when the disposal of a widget occurs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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