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

The following examples show how to use org.eclipse.swt.widgets.ToolItem#getStyle() . 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: OpenDropDownMenuHandler.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure we're being executed as a command tool item with style {@code DROP_DOWN}.
 * 
 * @return the {@link ToolItem}
 */
private static ToolItem findToolItem(ExecutionEvent event) throws ExecutionException {
  if (event.getTrigger() instanceof Event) {
    Event swtEvent = (Event) event.getTrigger();
    if (swtEvent.widget instanceof ToolItem) {
      ToolItem toolItem = (ToolItem) swtEvent.widget;
      int style = toolItem.getStyle();
      if ((style & SWT.DROP_DOWN) != 0) {
        return toolItem;
      }
    }
  }
  throw new ExecutionException("Invalid tool item");
}
 
Example 2
Source File: SWTEnvironment.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int getToolItemWidth(ToolItem control) {
	int style = control.getStyle();
	if((style & SWT.SEPARATOR) == 0 && PLATFORM_COCOA.equals(SWT.getPlatform())) {
		return ((style & SWT.HORIZONTAL) != 0 ? control.getBounds().width : control.getBounds().height);
	}
	return control.getWidth();
}
 
Example 3
Source File: TabbedPropertyTitle.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void handleWidgetSelection( Event e, ToolItem item )
{

	boolean selection = item.getSelection( );

	int style = item.getStyle( );
	IAction action = (IAction) actionMap.get( item );

	if ( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 )
	{
		if ( action.getStyle( ) == IAction.AS_CHECK_BOX )
		{
			action.setChecked( selection );
		}
	}
	else if ( ( style & SWT.RADIO ) != 0 )
	{
		if ( action.getStyle( ) == IAction.AS_RADIO_BUTTON )
		{
			action.setChecked( selection );
		}
	}
	else if ( ( style & SWT.DROP_DOWN ) != 0 )
	{
		if ( e.detail == 4 )
		{ // on drop-down button
			if ( action.getStyle( ) == IAction.AS_DROP_DOWN_MENU )
			{
				IMenuCreator mc = action.getMenuCreator( );
				ToolItem ti = (ToolItem) item;
				if ( mc != null )
				{
					Menu m = mc.getMenu( ti.getParent( ) );
					if ( m != null )
					{
						Point point = ti.getParent( )
								.toDisplay( new Point( e.x, e.y ) );
						m.setLocation( point.x, point.y ); // waiting
						m.setVisible( true );
						return; // we don't fire the action
					}
				}
			}
		}
	}

	action.runWithEvent( e );
}