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

The following examples show how to use org.eclipse.swt.widgets.ToolItem#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: DropDownAction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void runWithEvent(final Event event) {
	if (event.widget instanceof ToolItem) {
		final ToolItem toolItem = (ToolItem) event.widget;
		final Control control = toolItem.getParent();
		@SuppressWarnings("hiding")
		final Menu menu = getMenu(control);
		final Rectangle bounds = toolItem.getBounds();
		final Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
		menu.setLocation(control.toDisplay(topLeft));
		menu.setVisible(true);
	}
}
 
Example 2
Source File: ShowHistoryAction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void runWithEvent(Event event) {
	if (event.widget instanceof ToolItem) {
		final ToolItem toolItem = (ToolItem) event.widget;
		final Control control = toolItem.getParent();
		final Menu menu = getMenuCreator().getMenu(control);

		final Rectangle bounds = toolItem.getBounds();
		final Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
		menu.setLocation(control.toDisplay(topLeft));
		menu.setVisible(true);
	}
}
 
Example 3
Source File: DropDownSelectionListener.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle selection events.
 */	
public void widgetSelected(SelectionEvent event) {
	/**
	 * A selection event will be fired when a drop down tool
	 * item is selected in the main area and in the drop
	 * down arrow.  Examine the event detail to determine
	 * where the widget was selected.
	 */		
	if (event.detail == SWT.ARROW) {
		/*
		 * The drop down arrow was selected.
		 */
		if (visible) {
			// Hide the menu to give the Arrow the appearance of being a toggle button.
			setMenuVisible(false);
		} else {	
			// Position the menu below and vertically aligned with the the drop down tool button.
			final ToolItem toolItem = (ToolItem) event.widget;
			final ToolBar  toolBar = toolItem.getParent();
			
			Rectangle toolItemBounds = toolItem.getBounds();
			Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y));
			menu.setLocation(point.x, point.y + toolItemBounds.height);
			setMenuVisible(true);
		}
	} else {
		/*
		 * Main area of drop down tool item selected.
		 * An application would invoke the code to perform the action for the tool item.
		 */
	}
}
 
Example 4
Source File: ColorReferenceMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void open(final Decorations parent, final SelectionEvent trigger) {
	if (colorMenu == null) {
		colorMenu = new GamaColorMenu(mainMenu);
	}
	final ToolItem target = (ToolItem) trigger.widget;
	final ToolBar toolBar = target.getParent();
	colorMenu.open(toolBar, trigger, colorInserter, runnable);
}