Java Code Examples for org.eclipse.swt.widgets.MenuItem#getParent()

The following examples show how to use org.eclipse.swt.widgets.MenuItem#getParent() . 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: MenuItemProviders.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Walk up the MenuItems (in case they are nested) and find the parent {@link Menu}
 *
 * @param selectionEvent
 *            on the {@link MenuItem}
 * @return data associated with the parent {@link Menu}
 */
public static NatEventData getNatEventData(SelectionEvent selectionEvent) {
	Widget widget = selectionEvent.widget;
	if (widget == null || !(widget instanceof MenuItem)) {
		return null;
	}

	MenuItem menuItem = (MenuItem) widget;
	Menu parentMenu = menuItem.getParent();
	Object data = null;
	while (parentMenu != null) {
		if (parentMenu.getData() == null) {
			parentMenu = parentMenu.getParentMenu();
		} else {
			data = parentMenu.getData();
			break;
		}
	}

	return data != null ? (NatEventData) data : null;
}
 
Example 2
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Walk up the MenuItems (in case they are nested) and find the parent {@link Menu}
 *
 * @param selectionEvent
 *            on the {@link MenuItem}
 * @return data associated with the parent {@link Menu}
 */
public static NatEventData getNatEventData(SelectionEvent selectionEvent) {
	Widget widget = selectionEvent.widget;
	if (widget == null || !(widget instanceof MenuItem)) {
		return null;
	}

	MenuItem menuItem = (MenuItem) widget;
	Menu parentMenu = menuItem.getParent();
	Object data = null;
	while (parentMenu != null) {
		if (parentMenu.getData() == null) {
			parentMenu = parentMenu.getParentMenu();
		} else {
			data = parentMenu.getData();
			break;
		}
	}

	return data != null ? (NatEventData) data : null;
}