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

The following examples show how to use org.eclipse.swt.SWT#Selection . 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: ProjectFolderSelectionGroup.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The container selection has changed in the tree view. Update the container name field value and notify all listeners.
 */
public void containerSelectionChanged(IContainer container) {
    selectedContainer = container;

    if (allowNewContainerName) {
        if (container == null)
            containerNameField.setText("");//$NON-NLS-1$
        else
            containerNameField.setText(container.getFullPath().makeRelative().toString());
    }

    // fire an event so the parent can update its controls
    if (listener != null) {
        Event changeEvent = new Event();
        changeEvent.type = SWT.Selection;
        changeEvent.widget = this;
        listener.handleEvent(changeEvent);
    }
}
 
Example 2
Source File: AbstractCombo.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Manages popup content events. SelectionEvent are notified to all
 * registered SelectionListeners of the combo.
 * 
 * @param event event
 */
protected void contentEvent(Event event) {
	switch (event.type) {
		case SWT.FocusIn:
			handleFocus(SWT.FocusIn);
			break;
		case SWT.Selection: {
			if (doSelection()) {
				dropDown(false);
				Event e = new Event();
				e.time = event.time;
				e.stateMask = event.stateMask;
				e.doit = event.doit;
				e.data = event.data;
				notifyListeners(SWT.Selection, e);
				event.doit = e.doit;
			}
			break;
		}
	}
}
 
Example 3
Source File: RoundedToolItem.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @see org.eclipse.swt.widgets.Widget#addListener(int, org.eclipse.swt.widgets.Listener)
 */
@Override
public void addListener(int eventType, Listener listener) {
	checkWidget();
	if (listener == null) {
		SWT.error(SWT.ERROR_NULL_ARGUMENT);
	}
	if (eventType == SWT.Selection) {
		addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				final Event event = new Event();
				event.widget = RoundedToolItem.this;
				event.display = getDisplay();
				event.item = RoundedToolItem.this;
				event.type = SWT.Selection;
				listener.handleEvent(event);
			}

		});
		return;
	}
	super.addListener(eventType, listener);
}
 
Example 4
Source File: PulldownHandler.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
  // open the button's dropdown menu
  Object trigger = event.getTrigger();
  if (trigger instanceof Event) {
    Widget widget = ((Event) trigger).widget;
    if (widget instanceof ToolItem) {
      ToolItem toolItem = (ToolItem) widget;
      Listener[] listeners = toolItem.getListeners(SWT.Selection);
      if (listeners.length > 0) {
        Listener listener = listeners[0]; // should be only one listener
        // send an event to the widget to open the menu
        // see CommandContributionItem.openDropDownMenu(Event)
        Event e = new Event();
        e.type = SWT.Selection;
        e.widget = widget;
        e.detail = 4; // dropdown detail
        e.y = toolItem.getBounds().height; // position menu
        listener.handleEvent(e);
      }
    }
  }
  return null;
}
 
Example 5
Source File: ChartExpressionButton.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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 6
Source File: CustomPreviewTable.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.Selection :
			// SELECT COLUMN IN TABLE
			cnvCells.selectColumn( btnHeaders.indexOf( event.widget ) );
			break;

		case SWT.FocusIn :
			// Maintain the index correct after focus in
			iColumnIndex = btnHeaders.indexOf( event.widget );

			Event newEvent = new Event( );
			newEvent.widget = event.widget;
			newEvent.type = FOCUS_IN;
			newEvent.data = Integer.valueOf( iColumnIndex );
			fireEvent( newEvent );
			break;
	}
}
 
Example 7
Source File: MultiChoice.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void addListeners() {

		final int[] multiChoiceEvent = { SWT.Dispose, SWT.Move, SWT.Resize };
		for (final int element : multiChoiceEvent) {
			addListener(element, this.listener);
		}

		if ((getStyle() & SWT.READ_ONLY) == 0) {
			final Listener validationListener = new Listener() {

				@Override
				public void handleEvent(final Event event) {
					if (!MultiChoice.this.popup.isDisposed() && !MultiChoice.this.popup.isVisible()) {
						validateEntry();
					}
				}
			};
			this.text.addListener(SWT.FocusOut, validationListener);
		}

		final int[] buttonEvents = { SWT.Selection, SWT.FocusIn };
		for (final int buttonEvent : buttonEvents) {
			this.arrow.addListener(buttonEvent, this.listener);
		}
	}
 
Example 8
Source File: SpecConfigAdocPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void selectDocRoot(Event e) {
	switch (e.type) {
	case SWT.Selection:
		DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell(), SWT.OPEN | SWT.MULTI);
		dialog.setText("Select the documentation root directory");
		String result = dialog.open();
		if (result != null && !result.isEmpty()) {
			txtDocRootDirName.setText(result);
			saveProperty(result);
			checkPageComplete();
		}
		break;
	}
}
 
Example 9
Source File: CustomCombo.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void createPopup(String[] items, int selectionIndex) {
	// create shell and list
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	int style = getStyle();
	int listStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		listStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		listStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		listStyle |= SWT.LEFT_TO_RIGHT;
	list = new List(popup, listStyle);
	if (font != null)
		list.setFont(font);
	if (foreground != null)
		list.setForeground(foreground);
	if (background != null)
		list.setBackground(background);

	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
	for (int i = 0; i < popupEvents.length; i++)
		popup.addListener(popupEvents[i], listener);
	int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < listEvents.length; i++)
		list.addListener(listEvents[i], listener);

	if (items != null)
		list.setItems(items);
	if (selectionIndex != -1)
		list.setSelection(selectionIndex);
}
 
Example 10
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void handleEvent( Event event )
{
	switch ( event.type )
	{
		case SWT.MouseDown :
		case SWT.Selection :
			doToggleDropDown( );
			break;
		case SWT.KeyDown :
			processKeyDown( event.keyCode );
			break;
		case SWT.Traverse :
			if ( event.detail == SWT.TRAVERSE_TAB_NEXT
					|| event.detail == SWT.TRAVERSE_TAB_PREVIOUS )
			{
				event.doit = true;
			}
			break;
		case SWT.FocusIn :
			view.redraw( );
			break;
		case SWT.FocusOut :
			view.redraw( );
			break;
	}

}
 
Example 11
Source File: FormatSpecifierComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void handleEvent( Event event )
{
	if ( event.type == SWT.Selection )
	{
		widgetSelected( new SelectionEvent( event ) );
	}
	else if ( event.type == SWT.Modify )
	{
		modifyText( new ModifyEvent( event ) );
	}
	updatePreview( );
}
 
Example 12
Source File: TableCombo.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
    // create shell and table
    popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

    // create table
    table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

    if (font != null)
        table.setFont(font);
    if (foreground != null)
        table.setForeground(foreground);
    if (background != null)
        table.setBackground(background);

    // Add popup listeners
    int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
    for (int i = 0; i < popupEvents.length; i++) {
        popup.addListener(popupEvents[i], listener);
    }

    // add table listeners
    int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
            SWT.Dispose };
    for (int i = 0; i < tableEvents.length; i++) {
        table.addListener(tableEvents[i], listener);
    }

    // set the selection
    if (selectionIndex != -1) {
        table.setSelection(selectionIndex);
    }
}
 
Example 13
Source File: ContextForPartDialog.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
  super.handleEvent(event);
  
  if (event.widget == resourcesUI && event.type == SWT.Selection) {
    if (null != pickedResource) { 
      IFile f = (IFile)getResult()[0];
      contextPathGUI.setText(f.getLocation().toOSString());
    }   
  }
}
 
Example 14
Source File: StyleCombo.java    From birt with 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 15
Source File: TableCombo.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 16
Source File: BalloonWindow.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
public void addListener(int type, Listener l) {
  if (type == SWT.Selection) selectionListeners.add(l);
}
 
Example 17
Source File: CDateTimeValueProperty.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * 
 */
public CDateTimeValueProperty() {
	super(new int[] { SWT.Selection, SWT.Modify });
}
 
Example 18
Source File: RadioItem.java    From nebula with 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,
 * and the index at which to place it in the items maintained
 * by its parent.
 * <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 item to construct
 * @param index the zero-relative index at which to store the receiver in its parent
 *
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 *                <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 *                </ul>
 *
 * @see SWT
 * @see Widget#getStyle
 */
public RadioItem(final RadioGroup parent, int style, int index) {
	super(parent, checkStyle(style), checkIndex(parent, index));
	this.parent = parent;
	button = parent.createButton(getStyle(), index);

	final Listener listener = event -> {
		if (event.type == SWT.Selection) {
			handleSelection(event);
		} else if (event.type == SWT.Dispose) {
			handleDispose(event);
		}
	};
	button.addListener(SWT.Selection, listener);
	addListener(SWT.Dispose, listener);

	parent.addItem(this, index);
}
 
Example 19
Source File: MenuStylesDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void handleEvent( Event event )
{
	Object source = event.widget;
	if ( source == fComboStyle )
	{
		updateProperties( fCurrentStyleKeyType );
		switchProperties( MenuStylesKeyType.get( fComboStyle.getSelectionIndex( ) ) );
	}
	else if ( source == fBtnAdd )
	{
		doAdd( );
	}
	else if ( source == fBtnRemove )
	{
		doRemove( );
	}
	else if ( source == fTable )
	{
		if ( event.type == SWT.Resize )
		{
			int totalWidth = 0;
			int valuewidth = 0;
			int i = 0;
			for ( TableColumn tc : fTable.getColumns( ) )
			{
				totalWidth += tc.getWidth( );
				if ( i == 1 )
				{
					valuewidth = tc.getWidth( );
				}
				i++;
			}
			valuewidth += ( fTable.getClientArea( ).width - totalWidth );
			fTable.getColumn( 1 ).setWidth( valuewidth );
		}
		else if ( event.type == SWT.Selection )
		{
			updateButtonStatus( );
		}
		else if ( event.type == SWT.KeyDown )
		{
			if ( event.character == ' ' )
			{
				fTableViewer.editElement( fTableViewer.getElementAt( fTable.getSelectionIndex( ) ),
						0 );
			}
		}
	}
}
 
Example 20
Source File: GridItem.java    From tmxeditor8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Fires the appropriate events in response to a user checking/unchecking an
 * item. Checking an item fires both a selection event (with event.detail of
 * SWT.CHECK) if the checkbox is in the first column and the seperate check
 * listener (all columns). This method manages that behavior. This method
 * should only be called from within a cell renderer. Any other use is not
 * intended.
 *
 * @param column
 *            the column where the checkbox resides
 * @throws SWTException
 *             <ul>
 *             <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
 *             </li>
 *             <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *             thread that created the receiver</li>
 *             </ul>
 */
public void fireCheckEvent(int column) {
	checkWidget();

	Event selectionEvent = new Event();
	selectionEvent.display = getDisplay();
	selectionEvent.widget = this;
	selectionEvent.item = this;
	selectionEvent.type = SWT.Selection;
	selectionEvent.detail = SWT.CHECK;
	selectionEvent.index = column;

	getParent().notifyListeners(SWT.Selection, selectionEvent);
}