Java Code Examples for org.eclipse.swt.SWT#FocusOut

The following examples show how to use org.eclipse.swt.SWT#FocusOut . These examples are extracted from open source projects. 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
protected Control createControl(Composite parent) {
	combo = new DateChooserCombo(parent, getStyle());
	combo.setFont(parent.getFont());

	Listener listener = new Listener() {
		public void handleEvent(Event event) {
			switch ( event.type ) {
				case SWT.Traverse :
					if ( event.detail == SWT.TRAVERSE_ESCAPE
							 || event.detail == SWT.TRAVERSE_RETURN ) {
						event.doit = false;
					}
					break;

				case SWT.FocusOut :
					DateChooserComboCellEditor.this.focusLost();
					break;
			}				
		}
	};
	combo.addListener(SWT.Traverse, listener);
	combo.addListener(SWT.FocusOut, listener);

	return combo;
}
 
Example 2
Source Project: nebula   File: CTree.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public void handleEvent(Event event) {
	switch (event.type) {
	case SWT.FocusIn:
	case SWT.FocusOut:
		handleFocus(event.type);
		break;
	case SWT.MouseDoubleClick:
	case SWT.MouseDown:
	case SWT.MouseMove:
	case SWT.MouseUp:
		handleMouseEvents(event);
		break;
	case SWT.Traverse:
		handleTraverse(event);
		break;
	}
}
 
Example 3
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.KeyDown :
			if ( event.keyCode == SWT.CR
					|| event.keyCode == SWT.KEYPAD_CR )
			{
				onChange( );
			}
			break;
		case SWT.FocusOut :
		case SWT.Selection :
			onChange( );
			break;
	}
}
 
Example 4
@Override
public void handleEvent(final Event e) {
    if (e.type == SWT.FocusOut) {
        tableItem.setText(text.getText());
        text.dispose();
        table.setFocus();
    } else if (e.type == SWT.Traverse) {
        if (e.detail == SWT.TRAVERSE_RETURN) {
            tableItem.setText(text.getText());
            e.doit = true;
        }
        if (e.detail == SWT.TRAVERSE_RETURN || e.detail == SWT.TRAVERSE_ESCAPE) {
            text.dispose();
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                e.doit = false;
            }
        }
    }
}
 
Example 5
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusOut :
			focusLost( new FocusEvent( event ) );
			break;

		case SWT.Traverse :
			switch ( event.detail )
			{
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
					// Indicates getting focus control rather than
					// cursor control
					event.doit = true;
					isPressingKey = true;
			}
			break;

	}
}
 
Example 6
/**
 * {@inheritDoc}
 */
@Override
public void handleEvent(Event event) {
	if (!onHandleEvent) {
		onHandleEvent = true;
		if (event.type == SWT.FocusOut || (event.type == SWT.Traverse && event.detail == SWT.TRAVERSE_RETURN)) {
			changeTargetBranch(view);
		}
		onHandleEvent = false;
	}
}
 
Example 7
Source Project: nebula   File: DateChooser.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles the focus.
 *
 * @param mode SWT.FocusIn or SWT.FocusOut
 */
private void handleFocus(int mode) {
	switch (mode) {
		case SWT.FocusIn: {
			if (hasFocus) {
				return;
			}
			hasFocus = true;
			final Display display = getDisplay();
			display.removeFilter(SWT.KeyDown, filter);
			display.removeFilter(SWT.FocusIn, filter);
			if (focusIndex < 0) {
				setFocus(NOFOCUS);
			}
			notifyListeners(SWT.FocusIn, new Event());
			display.addFilter(SWT.FocusIn, filter);
			display.addFilter(SWT.KeyDown, filter);
			break;
		}

		case SWT.FocusOut: {
			if (!hasFocus) {
				return;
			}
			final Control focusControl = getDisplay().getFocusControl();
			if (focusControl == DateChooser.this || focusControl == nextMonth || focusControl == prevMonth) {
				return;
			}
			hasFocus = false;
			getDisplay().removeFilter(SWT.KeyDown, filter);
			getDisplay().removeFilter(SWT.FocusIn, filter);
			notifyListeners(SWT.FocusOut, new Event());
			break;
		}
	}
	gridRedraw();
}
 
Example 8
/**
 * 
 */
private void placeComponents( )
{
	// THE LAYOUT OF THIS COMPOSITE (FILLS EVERYTHING INSIDE IT)
	FillLayout flMain = new FillLayout( );
	flMain.marginHeight = 0;
	flMain.marginWidth = 0;
	setLayout( flMain );

	// THE LAYOUT OF THE OUTER COMPOSITE (THAT GROWS VERTICALLY BUT ANCHORS
	// ITS CONTENT NORTH)
	cmpContentOuter = new Composite( this, SWT.NONE );
	GridLayout glContentOuter = new GridLayout( );
	glContentOuter.verticalSpacing = 0;
	glContentOuter.horizontalSpacing = 0;
	glContentOuter.marginHeight = 0;
	glContentOuter.marginWidth = 0;
	glContentOuter.numColumns = 1;
	cmpContentOuter.setLayout( glContentOuter );

	// THE LAYOUT OF THE INNER COMPOSITE (ANCHORED NORTH AND ENCAPSULATES
	// THE CANVAS + BUTTON)
	cmpContentInner = new Composite( cmpContentOuter, SWT.BORDER );
	GridLayout glContentInner = new GridLayout( );
	glContentInner.verticalSpacing = 0;
	glContentInner.horizontalSpacing = 0;
	glContentInner.marginHeight = 0;
	glContentInner.marginWidth = 0;
	glContentInner.numColumns = 2;
	cmpContentInner.setLayout( glContentInner );
	GridData gdContentInner = new GridData( GridData.FILL_HORIZONTAL );
	cmpContentInner.setLayoutData( gdContentInner );

	// THE CANVAS
	cnvSelection = new FillCanvas( cmpContentInner,
			SWT.NONE,
			this.bAutoEnabled,
			wizardContext == null ? null
					: wizardContext.getImageServiceProvider( ) );
	cnvSelection.setTextIndent( 8 );
	GridData gdCNVSelection = new GridData( GridData.FILL_BOTH );
	gdCNVSelection.heightHint = iSize;
	cnvSelection.setLayoutData( gdCNVSelection );

	initFill( );

	// THE BUTTON
	btnDown = new Button( cmpContentInner, SWT.ARROW | SWT.DOWN );
	GridData gdBDown = new GridData( GridData.FILL );
	gdBDown.verticalAlignment = GridData.BEGINNING;
	gdBDown.widthHint = iSize - 2;
	gdBDown.heightHint = iSize;
	btnDown.setLayoutData( gdBDown );
	btnDown.addSelectionListener( this );

	addDisposeListener( this );

	Listener listener = new Listener( ) {

		public void handleEvent( Event event )
		{
			handleEventCanvas( event );
		}
	};

	int[] textEvents = {
			SWT.KeyDown,
			SWT.MouseDown,
			SWT.Traverse,
			SWT.FocusIn,
			SWT.FocusOut
	};
	for ( int i = 0; i < textEvents.length; i++ )
	{
		cnvSelection.addListener( textEvents[i], listener );
	}

}
 
Example 9
/**
 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
 */
public void handleEvent(Event event) {
	switch (event.type) {
	case SWT.KeyDown:
		textModified = true;
		if (event.character == SWT.CR)
			textChanged((Control) event.widget);
		break;
	case SWT.FocusOut:
		textChanged((Control) event.widget);
		break;
	}
}
 
Example 10
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusOut :
			onDropDonwFocusOut( );
			break;
		case ToggleDropDown :
			toggleDropDown( );
			break;
	}

}
 
Example 11
@Override
public void handleEvent(Event event) {
    switch (event.type) {
        case SWT.Activate:
        case SWT.MouseVerticalWheel:
        case SWT.MouseUp:
        case SWT.MouseDown:
        case SWT.FocusOut:
            IInformationControl iControl = fInformationControl;
            if (iControl != null && !iControl.isFocusControl()) {
                hideInformationControl();
            }
            break;

        case SWT.MouseMove:
        case SWT.MouseEnter:
        case SWT.MouseExit:
            handleMouseMove(event);
            break;

        case SWT.KeyDown:
            if (event.keyCode == SWT.ESC) {
                hideInformationControl();

            } else if (fActivateEditorBinding != null
                    && KeyBindingHelper.matchesKeybinding(event.keyCode, event.stateMask,
                            fActivateEditorBinding)) {
                hideInformationControl(true, true);
            }
            break;
    }
}
 
Example 12
Source Project: birt   File: StyleCombo.java    License: Eclipse Public License 1.0 5 votes vote down vote up
void createPopup( Object[] items, int selectionIndex )
{
	// create shell and list
	popup = new Shell( getShell( ), SWT.NO_TRIM | SWT.ON_TOP );

	table = new Table( popup, SWT.SINGLE
			| SWT.V_SCROLL
			| SWT.FULL_SELECTION );
	new TableColumn( table, SWT.LEFT );
	if ( font != null )
		table.setFont( font );
	if ( foreground != null )
		table.setForeground( foreground );
	if ( background != null )
		table.setBackground( background );

	label.setBackground( table.getBackground( ) );
	label.setForeground( table.getForeground( ) );
	label.setFont( table.getFont( ) );

	int[] popupEvents = {
			SWT.Close, SWT.Paint, SWT.Deactivate
	};
	for ( int i = 0; i < popupEvents.length; i++ )
		popup.addListener( popupEvents[i], listener );
	int[] tableEvents = {
			SWT.MouseUp,
			SWT.Selection,
			SWT.Traverse,
			SWT.KeyDown,
			SWT.KeyUp,
			SWT.FocusIn,
			SWT.FocusOut,
			SWT.Dispose
	};
	for ( int i = 0; i < tableEvents.length; i++ )
		table.addListener( tableEvents[i], listener );
}
 
Example 13
void handleEventCmpDropDown( Event event )
{
	switch ( event.type )
	{
		case SWT.KeyDown :
		{
			keyPressed( new KeyEvent( event ) );
			break;
		}
		case SWT.FocusOut :
		{
			Control cTmp = Display.getCurrent( ).getCursorControl( );

			if ( cTmp != null )
			{
				if ( cTmp.equals( cnvSelection ) || cTmp.equals( btnDown ) )
				{
					bJustFocusLost = true;
				}
			}
			if ( !isPopupControl( cTmp ) )
			{
				cmpDropDown.getShell( ).close( );
			}

			break;
		}
	}
}
 
Example 14
Source Project: nebula   File: TextAssist.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Constructs a new instance of this class given its parent and a style
 * value describing its behavior and appearance.
 * <p>
 * The style value is either one of the style constants defined in class
 * <code>SWT</code> which is applicable to instances of this class, or must
 * be built by <em>bitwise OR</em>'ing together (that is, using the
 * <code>int</code> "|" operator) two or more of those <code>SWT</code>
 * style constants. The class description lists the style constants that are
 * applicable to the class. Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a composite control which will be the parent of the new
 *            instance (cannot be null)
 * @param style the style of control to construct
 * @param contentProvider the content provider
 *
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the parent</li>
 *                <li>ERROR_INVALID_SUBCLASS - if this class is not an
 *                allowed subclass</li>
 *                </ul>
 *
 * @see SWT#SINGLE
 * @see SWT#MULTI
 * @see SWT#READ_ONLY
 * @see SWT#WRAP
 * @see SWT#LEFT
 * @see SWT#RIGHT
 * @see SWT#CENTER
 * @see SWT#PASSWORD
 * @see SWT#SEARCH
 * @see SWT#ICON_SEARCH
 * @see SWT#ICON_CANCEL
 * @see Widget#checkSubclass
 * @see Widget#getStyle
 */
public TextAssist(final Composite parent, final int style, final TextAssistContentProvider contentProvider) {
	super(parent, SWT.NONE);
	this.contentProvider = contentProvider;
	this.contentProvider.setTextAssist(this);

	setLayout(new FillLayout());
	numberOfLines = 10;
	text = new Text(this, style);
	popup = new Shell(getDisplay(), SWT.ON_TOP);
	popup.setLayout(new FillLayout());
	table = new Table(popup, SWT.SINGLE);

	addTextListener();
	addTableListener();

	final int[] events = new int[] { SWT.Move, SWT.FocusOut };
	for (final int event : events) {
		getShell().addListener(event, e -> {
			popup.setVisible(false);
		});
	}

}
 
Example 15
boolean handleEditEvent(Event event) {
   if (klickedColumn == null || klickedCell == null) {
      return false;
   }

   final Control c;
   try {
      XViewerColumn xColumn =
         xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
      if (xColumn instanceof ExtendedViewerColumn) {
         ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn;
         CellEditDescriptor ced = extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass());
         if (ced != null) {
            if (ced.getControl() == null) {
               return false;
            }
            if (ced.getAction() != null && !ced.getAction().isEnabled()) {
               return false;
            }
            if (!converter.isValid(ced, klickedCell.getElement())) {
               return false;
            }
            c = factory.createControl(ced, xv);
            if (c == null) {
               return false;
            }
         } else {
            return false;
         }
      } else {
         return false;
      }

      if (((TreeItem) event.item) != null) {
         Listener myListener = e-> {
               switch (e.type) {
                  case SWT.FocusOut:
                     // set new value
                     getInput(c);
                     c.dispose();
                     break;
                  case SWT.Verify:
                     c.setBounds(klickedCell.getBounds());
                     break;
                  case SWT.Traverse:
                     boolean neighbor = false;
                     switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                           // set new value
                           getInput(c);
                           //$FALL-THROUGH$
                        case SWT.TRAVERSE_ESCAPE:
                           c.dispose();
                           e.doit = false;
                           break;
                        case SWT.TRAVERSE_TAB_NEXT:
                           getInput(c);
                           neighbor = getNeighbor(ViewerCell.RIGHT, true);
                           e.doit = false;
                           c.dispose();
                           Event eN = new Event();
                           eN.type = SWT.Selection;
                           eN.widget = xv.getTree();
                           if (neighbor) {
                              eN.item = klickedCell.getItem();
                           }
                           doHandleEvent(eN);
                           break;
                        case SWT.TRAVERSE_TAB_PREVIOUS:
                           getInput(c);
                           neighbor = getNeighbor(ViewerCell.LEFT, true);
                           e.doit = false;
                           c.dispose();
                           Event eP = new Event();
                           eP.type = SWT.Selection;
                           eP.widget = xv.getTree();
                           if (neighbor) {
                              eP.item = klickedCell.getItem();
                           }
                           doHandleEvent(eP);
                           break;
                     }
               }
         };
         c.addListener(SWT.FocusOut, myListener);
         c.addListener(SWT.Traverse, myListener);
         c.addListener(SWT.Verify, myListener);
         // set old value
         setInput(c);
         c.setFocus();
         return true;
      }
   } catch (Exception ex) {
      return false;
   }
   return false;
}
 
Example 16
void handleEventCanvas( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusIn :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.FocusOut :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.KeyDown :
		{
			if ( event.keyCode == SWT.KEYPAD_CR
					|| event.keyCode == SWT.CR
					|| event.keyCode == ' ' )
			{
				event.doit = true;
				toggleDropDown( );
			}
			break;
		}
		case SWT.MouseDown :
			if ( !bEnabled )
			{
				return;
			}
			// fireHandleEvent( MOUSE_CLICKED_EVENT );
			toggleDropDown( );
			break;
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_ESCAPE :
					getShell( ).close( );
					break;
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvSelection.redraw( );
			}
			break;
		}
	}
}
 
Example 17
void handleEventCanvasSelection( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusIn :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.FocusOut :
		{
			cnvSelection.redraw( );
			break;
		}
		case SWT.KeyDown :
		{
			// At this point the widget may have been disposed.
			// If so, do not continue.
			if ( isDisposed( ) )
				break;

			if ( event.keyCode == SWT.ARROW_UP
					|| event.keyCode == SWT.ARROW_DOWN )
			{
				toggleDropDown( );
			}
			break;
		}
		case SWT.Traverse :
		{
			switch ( event.detail )
			{
				case SWT.TRAVERSE_ESCAPE :
					getShell( ).close( );
					break;
				case SWT.TRAVERSE_RETURN :
				case SWT.TRAVERSE_TAB_NEXT :
				case SWT.TRAVERSE_TAB_PREVIOUS :
				case SWT.TRAVERSE_ARROW_PREVIOUS :
				case SWT.TRAVERSE_ARROW_NEXT :
					event.doit = true;
					cnvSelection.redraw( );
			}
			break;
		}
		case SWT.MouseDown :
			toggleDropDown( );
			break;
	}
}
 
Example 18
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.FocusOut :
			focusLost( new FocusEvent( event ) );
			break;

		case SWT.FocusIn:
			focusedComposite = event.widget;
			break;
			
		case SWT.MouseDown :
			mouseDown( new MouseEvent( event ) );
			break;

		case SWT.Selection :
			widgetSelected( new SelectionEvent( event ) );
			break;

		case SWT.KeyDown :
			if ( event.keyCode == SWT.ESC )
			{
				getShell( ).close( );
			}
			else if ( event.widget == cmpType )
			{
				int newIndex;
				if ( event.keyCode == SWT.ARROW_LEFT )
				{
					if ( markerTypeIndex - 1 >= 0 )
					{
						newIndex = markerTypeIndex - 1;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
				else if ( event.keyCode == SWT.ARROW_RIGHT )
				{
					if ( markerTypeIndex + 1 < typeNameSet.length )
					{
						newIndex = markerTypeIndex + 1;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
				else if ( event.keyCode == SWT.ARROW_UP )
				{
					if ( markerTypeIndex - MARKER_ROW_MAX_NUMBER >= 0 )
					{
						newIndex = markerTypeIndex
								- MARKER_ROW_MAX_NUMBER;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
				else if ( event.keyCode == SWT.ARROW_DOWN )
				{
					if ( markerTypeIndex + MARKER_ROW_MAX_NUMBER < typeNameSet.length )
					{
						newIndex = markerTypeIndex
								+ MARKER_ROW_MAX_NUMBER;
						switchMarkerType( newIndex );
						redrawMarkers( newIndex );
					}
				}
			}
			break;

		case SWT.Traverse :
			// Indicates getting focus control rather than
			// cursor control
			if ( event.detail == SWT.TRAVERSE_TAB_NEXT
					|| event.detail == SWT.TRAVERSE_TAB_PREVIOUS )
			{
				event.doit = true;
				isPressingKey = true;
			}
			else if ( event.keyCode == getMnemonicByText( grpSize.getText( ) ) )
			{
				updateIsPressingKey( iscMarkerSize );
			}
			else if ( event.keyCode == getMnemonicByText( btnOutline.getButton( )
					.getText( ) ) )
			{
				updateIsPressingKey( btnOutline );
			}
			else if ( event.keyCode == getMnemonicByText( btnMarkerVisible.getButton( )
					.getText( ) ) )
			{
				updateIsPressingKey( btnMarkerVisible );
			}
	}
}
 
Example 19
Source Project: birt   File: CCombo.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructs a new instance of this class given its parent
 * and a style value describing its behavior and appearance.
 * <p>
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together 
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a widget which will be the parent of the new instance (cannot be null)
 * @param style the style of widget to construct
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 * </ul>
 *
 * @see SWT#BORDER
 * @see SWT#READ_ONLY
 * @see SWT#FLAT
 * @see Widget#getStyle()
 */
public CCombo (Composite parent, int style) {
	super (parent, style = checkStyle (style));
	
	int textStyle = SWT.SINGLE;
	if ((style & SWT.READ_ONLY) != 0) textStyle |= SWT.READ_ONLY;
	if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT;
	text = new Text (this, textStyle);
	int arrowStyle = SWT.ARROW | SWT.DOWN;
	if ((style & SWT.FLAT) != 0) arrowStyle |= SWT.FLAT;
	arrow = new Button (this, arrowStyle);

	listener = new Listener () {
		public void handleEvent (Event event) {
			if (popup == event.widget) {
				popupEvent (event);
				return;
			}
			if (text == event.widget) {
				textEvent (event);
				return;
			}
			if (list == event.widget) {
				listEvent (event);
				return;
			}
			if (arrow == event.widget) {
				arrowEvent (event);
				return;
			}
			if (CCombo.this == event.widget) {
				comboEvent (event);
				return;
			}

		}
	};
	
	
	int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize};
	for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
	
	int [] textEvents = {SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn, SWT.FocusOut};
	for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
	
	int [] arrowEvents = {SWT.Selection, SWT.FocusIn, SWT.FocusOut};
	for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
	
	createPopup(null, -1);
	initAccessible();
	
}
 
Example 20
Source Project: nebula   File: BaseCombo.java    License: Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Set the visibility style of the drop button.
 * <p>
 * The style will be forced to NEVER if the contents are null
 * </p>
 * <dl>
 * <dt><b>Styles:</b></dt>
 * <dd>BUTTON_ALWAYS, BUTTON_AUTO, BUTTON_MANUAL, BUTTON_NEVER</dd>
 * </dl>
 * <dl>
 * <dt><b>Style BUTTON_ALWAYS:</b></dt>
 * <dd>Button will always be shown - standard SWT.DROP_DOWN behaviour. The
 * method setButtonVisible(boolean) has no affect with this style set</dd>
 * <dt><b>Style BUTTON_AUTO:</b></dt>
 * <dd>Button visibility will be handled automatically through focus events,
 * popup events, as well as programmatically</dd>
 * <dt><b>Style BUTTON_MANUAL:</b></dt>
 * <dd>Button visibility will only be handled programmatically</dd>
 * <dt><b>Style BUTTON_NEVER:</b></dt>
 * <dd>Button will never be shown - standard SWT.SIMPLE behaviour. The
 * method setButtonVisible(boolean) has no affect with this style set</dd>
 * </dl>
 * 
 * @param visibility
 *            the visibility style constant
 * @see #setButtonVisible(boolean)
 */
protected void setButtonVisibility(int visibility) {
	buttonVisibility = visibility;
	setButtonVisible(false);
	if (buttonVisibility == BUTTON_AUTO) {
		buttonVisibilityListener = new Listener() {
			public void handleEvent(Event event) {
				switch (event.type) {
				case SWT.FocusIn:
					setButtonVisible(true);
					break;
				case SWT.FocusOut:
					setButtonVisible(false);
					break;
				}
			}
		};
		addListener(SWT.FocusIn, buttonVisibilityListener);
		addListener(SWT.FocusOut, buttonVisibilityListener);
	} else {
		if (buttonVisibilityListener != null) {
			removeListener(SWT.FocusIn, buttonVisibilityListener);
			removeListener(SWT.FocusOut, buttonVisibilityListener);
			buttonVisibilityListener = null;
		}
	}
}