Java Code Examples for org.eclipse.swt.widgets.Widget#addDisposeListener()

The following examples show how to use org.eclipse.swt.widgets.Widget#addDisposeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.StructuredViewer#mapElement(java.lang.Object, org.eclipse.swt.widgets.Widget)
 */
protected void mapElement(Object element, final Widget item) {
	super.mapElement(element, item);
	// make sure to unmap elements if the tree is virtual
	if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
		// only add a dispose listener if item hasn't already on assigned
		// because it is reused
		if (item.getData(VIRTUAL_DISPOSE_KEY) == null) {
			item.setData(VIRTUAL_DISPOSE_KEY, Boolean.TRUE);
			item.addDisposeListener(new DisposeListener() {
				public void widgetDisposed(DisposeEvent e) {
					if (!treeIsDisposed) {
						Object data = item.getData();
						if (usingElementMap() && data != null) {
							unmapElement(data, item);
						}
					}
				}
			});
		}
	}
}
 
Example 2
Source File: SWTResourceManager.java    From ProtocolAnalyzer with GNU General Public License v3.0 3 votes vote down vote up
/**
 * This method should be called by *all* Widgets which use resources
 * provided by this SWTResourceManager. When widgets are disposed,
 * they are removed from the "users" Vector, and when no more
 * registered Widgets are left, all resources are disposed.
 * <P>
 * If this method is not called for all Widgets then it should not be called
 * at all, and the "dispose" method should be explicitly called after all
 * resources are no longer being used.
 */
public static void registerResourceUser(Widget widget) {
	if (users.contains(widget))
		return;
	users.add(widget);
	widget.addDisposeListener(disposeListener);
}
 
Example 3
Source File: AbstractExampleTab.java    From nebula with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Adds the given widget to the list of which will participate in the event
 * listening mechanism of the example tab. In other words, if a user has chosen
 * to listen for a specific event, and that event is fired on the given widget,
 * the event's details will print in the event text area in the example.
 *
 * This method is primarily used to include a widget's <code>Item</code>
 * children in the event listening mechanism.
 *
 * @param widget
 */
protected void addEventParticipant(final Widget widget) {
	additionalEventParticipants.add(widget);
	widget.addDisposeListener(e -> additionalEventParticipants.remove(widget));
}
 
Example 4
Source File: SWTGraphicUtil.java    From nebula with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Dispose safely any SWT resource when a widget is disposed
 *
 * @param widget widget attached to the resource
 * @param resource the resource to dispose
 */
public static void addDisposer(final Widget widget, final Resource resource) {
	widget.addDisposeListener(e -> {
		safeDispose(resource);
	});
}