Java Code Examples for org.eclipse.swt.events.SelectionListener

The following examples show how to use org.eclipse.swt.events.SelectionListener. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: gama   Source File: GamaToolbar2.java    License: GNU General Public License v3.0 6 votes vote down vote up
private ToolItem create(final String image, final String text, final String tip, final SelectionListener listener,
		final int style, final boolean forceText, final Control control,
		final int side /* SWT.LEFT or SWT.RIGHT */) {
	final GamaToolbarSimple tb = getToolbar(side);
	final ToolItem button = new ToolItem(tb, style);
	if (text != null && forceText) {
		button.setText(text);
	}
	if (tip != null) {
		button.setToolTipText(tip);
	}
	if (image != null) {
		final Image im = GamaIcons.create(image).image();
		button.setImage(im);
	}
	if (listener != null) {
		button.addSelectionListener(listener);
	}
	if (control != null) {
		button.setControl(control);
	}
	normalizeToolbars();

	return button;
}
 
Example 2
Source Project: nebula   Source File: HorizontalSpinner.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Sets the <em>selection</em>, which is the receiver's position, to the
 * argument. If the argument is not within the range specified by minimum
 * and maximum, it will be adjusted to fall within this range.
 *
 * @param value the new selection (must be zero or greater)
 *
 * @exception 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 setSelection(int selection) {
	checkWidget();
	if (selection < minimum) {
		selection = minimum;
	} else if (selection > maximum) {
		selection = maximum;
	}

	storedValue = selection;
	text.setText(convertSelectionToStringValue());

	for (final SelectionListener s : selectionListeners) {
		s.widgetSelected(null);
	}

}
 
Example 3
Source Project: Pydev   Source File: PyConfigureExceptionDialog.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param composite
 *
 *            Create a new text box and a button, which allows user to add
 *            custom exception. Attach a listener to the AddException Button
 */
private void createCustomExceptionUI(Composite composite) {
    addNewExceptionField = new Text(composite, SWT.BORDER);
    addNewExceptionField.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));

    Button buttonAdd = new Button(composite, SWT.PUSH);
    buttonAdd.setLayoutData(new GridData(GridData.END, GridData.END, true, false));
    buttonAdd.setText("Add Exception");

    SelectionListener listener = new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            addCustomException();
        }
    };
    buttonAdd.addSelectionListener(listener);

}
 
Example 4
Source Project: nebula   Source File: SwitchButton.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Fire the selection listeners
 *
 * @param e mouse event
 * @return true if the selection could be changed, false otherwise
 */
private boolean fireSelectionListeners(final Event e) {
	for (final SelectionListener listener : listOfSelectionListeners) {
		final Event event = new Event();

		event.button = e.button;
		event.display = getDisplay();
		event.item = null;
		event.widget = this;
		event.data = null;
		event.time = e.time;
		event.x = e.x;
		event.y = e.y;

		final SelectionEvent selEvent = new SelectionEvent(event);
		listener.widgetSelected(selEvent);
		if (!selEvent.doit) {
			return false;
		}
	}
	return true;
}
 
Example 5
Source Project: xtext-eclipse   Source File: ListDialogField.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected Button createButton(Composite parent, String label,
		SelectionListener listener) {
	Button button = new Button(parent, SWT.PUSH);
	button.setFont(parent.getFont());
	button.setText(label);
	button.addSelectionListener(listener);
	GridData gd = new GridData();
	gd.horizontalAlignment = GridData.FILL;
	gd.grabExcessHorizontalSpace = true;
	gd.verticalAlignment = GridData.BEGINNING;
	gd.widthHint = SWTUtil.getButtonWidthHint(button);

	button.setLayoutData(gd);

	return button;
}
 
Example 6
Source Project: corrosion   Source File: DebugPreferencePage.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Control createContents(Composite parent) {
	parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	Composite container = new Composite(parent, SWT.NONE);
	container.setLayout(new GridLayout(4, false));
	container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));

	gdbInput = new InputComponent(container, Messages.DebugPreferencePage_defaultGDB, e -> isPageValid());
	gdbInput.createComponent();
	gdbInput.createFileSelection();
	gdbInput.setValue(store.getString(CorrosionPreferenceInitializer.DEFAULT_GDB_PREFERENCE));

	Link gdbLink = new Link(container, SWT.NONE);
	gdbLink.setText(Messages.DebugPreferencePage_seeGDBPage);
	gdbLink.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
		IPreferencePageContainer prefContainer = getContainer();
		if (prefContainer instanceof IWorkbenchPreferenceContainer) {
			((IWorkbenchPreferenceContainer) prefContainer).openPage("org.eclipse.cdt.dsf.gdb.ui.preferences", //$NON-NLS-1$
					null);
		}
	}));
	gdbLink.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
	return parent;
}
 
Example 7
Source Project: nebula   Source File: DualList.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Call all selection listeners
 *
 * @param item selected item
 */
private void fireSelectionEvent(final DLItem item) {
	if (selectionListeners == null) {
		return;
	}

	final Event event = new Event();
	event.button = 1;
	event.display = getDisplay();
	event.item = null;
	event.widget = this;
	event.data = item;
	final SelectionEvent selectionEvent = new SelectionEvent(event);

	for (final SelectionListener listener : selectionListeners) {
		listener.widgetSelected(selectionEvent);
	}
}
 
Example 8
private SelectionListener templateListener() {
  return new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent event) {
      targetCreator.setTemplate(DataflowProjectArchetype.values()[templateDropdown.getSelectionIndex()]);
      updateAvailableVersions();
    }
  };
}
 
Example 9
Source Project: birt   Source File: CComboPropertyDescriptor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void addComboSelectionListener( SelectionListener listener )
{
	if ( !comboSelectList.contains( listener ) )
	{
		if ( !comboSelectList.isEmpty( ) )
			removeComboSelectionListener( (SelectionListener) comboSelectList.get( 0 ) );
		comboSelectList.add( listener );
		if ( combo != null )
			combo.addSelectionListener( listener );
	}
}
 
Example 10
Source Project: gama   Source File: AgentsMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static MenuItem actionAgentMenuItem(final Menu parent, final IAgent agent, final SelectionListener listener,
		final Image image, final String prefix) {
	final MenuItem result = new MenuItem(parent, SWT.PUSH);
	result.setText(prefix /* + " " + agent.getName() */);
	result.addSelectionListener(listener);
	result.setImage(image);
	result.setData("agent", agent);
	return result;
}
 
Example 11
Source Project: birt   Source File: ComboAndButtonSection.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * if use this method , you couldn't use the onClickButton method.
 */
public void addButtonSelectionListener( SelectionListener listener )
{
	if ( !buttonSelectList.contains( listener ) )
	{
		if ( !buttonSelectList.isEmpty( ) )
			removeButtonSelectionListener( (SelectionListener) buttonSelectList.get( 0 ) );
		buttonSelectList.add( listener );
		if ( button != null )
			button.addSelectionListener( listener );
	}
}
 
Example 12
Source Project: XPagesExtensionLibrary   Source File: WizardUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Combo createEditCombo(Composite parent, int span, SelectionListener listener) {
    Combo combo = new Combo(parent, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = span;
    combo.setLayoutData(gd);
    combo.setVisibleItemCount(10);
    if (listener != null) {
        combo.addSelectionListener(listener);            
    }        
    return combo;
}
 
Example 13
Source Project: birt   Source File: MenuButton.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void removeSelectionListener( SelectionListener listener )
{
	if ( listeners != null )
	{
		listeners.remove( listener );
		if ( listeners.size( ) == 0 )
			listeners = null;
	}
}
 
Example 14
Source Project: XPagesExtensionLibrary   Source File: WizardUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Button createButton(Composite parent, String text, SelectionListener listener, int layout) {
    Button btn = new Button(parent, SWT.NONE);
    GridData gd = new GridData(layout);
    btn.setLayoutData(gd);
    btn.setText(text);
    if (listener != null) {
        btn.addSelectionListener(listener);            
    }
    return btn;
}
 
Example 15
Source Project: birt   Source File: ComboAndButtonSection.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void addComboSelectionListener( SelectionListener listener )
{
	if ( !comboSelectList.contains( listener ) )
	{
		if ( !comboSelectList.isEmpty( ) )
			removeComboSelectionListener( (SelectionListener) comboSelectList.get( 0 ) );
		comboSelectList.add( listener );
		if ( combo != null )
			combo.addComboSelectionListener( listener );
	}
}
 
Example 16
Source Project: texlipse   Source File: BuilderChooser.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Forward the event forward.
 * @param event event
 */
private void fireSelectionEvent(SelectionEvent event) {
    for (int i = 0; i < selectionListeners.size(); i++) {
        SelectionListener lis = (SelectionListener) selectionListeners.get(i);
        lis.widgetSelected(event);
    }
}
 
Example 17
Source Project: pmTrans   Source File: MenuManager.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private MenuItem addMenuItem(Menu menu, String text,
		SelectionListener listener) {
	MenuItem item = new MenuItem(menu, SWT.NONE);
	item.setText(text);
	item.addSelectionListener(listener);
	return item;
}
 
Example 18
Source Project: tracecompass   Source File: TimeGraphControl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Default selection callback
 */
public void fireDefaultSelection() {
    if (null != fSelectionListeners) {
        Iterator<SelectionListener> it = fSelectionListeners.iterator();
        while (it.hasNext()) {
            SelectionListener listener = it.next();
            listener.widgetDefaultSelected(null);
        }
    }
}
 
Example 19
Source Project: nebula   Source File: CTree.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * An item may be considered visible, and will be returned with
 * {@link CTree#getVisibleItems()}, even though it will not be
 * painted on the screen. Paint status, on the other hand, refers to whether
 * or not an item will actually be painted when the
 * {@link CTree#paintBody(Event)} method is called.
 * 
 * @return an array of items that will be painted to the screen during paint
 *         events
 * @see #getVisibleItems()
 */
// public CTreeItem[] getPaintedItems() {
// return (CTreeItem[]) paintedItems.toArray(new
// CTreeItem[paintedItems.size()]);
// }
public void addSelectionListener(SelectionListener listener) {
	checkWidget();
	if (listener != null) {
		TypedListener typedListener = new TypedListener(listener);
		addListener(SWT.Selection, typedListener);
		addListener(SWT.DefaultSelection, typedListener);
	}
}
 
Example 20
Source Project: birt   Source File: OptionsConfigurationBlock.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void addSelectionListener( SelectionListener selectionListener )
{
	IniRadioButtons( );
	if ( radioBtns.size( ) <= 0 )
		return;
	for ( int i = 0; i < radioBtns.size( ); i++ )
	{
		radioBtns.get( i ).addSelectionListener( selectionListener );
	}

}
 
Example 21
Source Project: arx   Source File: ComponentTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Fires a new event.
 */
private void fireSelectionEvent(){
    Event event = new Event();
    event.display = table.getDisplay();
    event.item = table;
    event.widget = table;
    SelectionEvent sEvent = new SelectionEvent(event);
    for (SelectionListener listener : selectionListeners) {
        listener.widgetSelected(sEvent);
    }
}
 
Example 22
private Button createSelectionButton(int index, Composite group, SelectionListener listener) {
	Button button= new Button(group, fButtonsStyle | SWT.LEFT);
	button.setFont(group.getFont());
	button.setText(fButtonNames[index]);
	button.setEnabled(isEnabled() && fButtonsEnabled[index]);
	button.setSelection(fButtonsSelected[index]);
	button.addSelectionListener(listener);
	button.setLayoutData(new GridData());
	return button;
}
 
Example 23
Source Project: Pydev   Source File: AbstractInterpreterEditor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Helper method to create a push button.
 *
 * @param parent the parent control
 * @param key the resource name used to supply the button's label text
 * @param listenerToAdd
 * @return Button
 */
/*default*/public static Button createBt(Composite parent, String key, SelectionListener listenerToAdd) {
    Button button = new Button(parent, SWT.PUSH);
    button.setText(JFaceResources.getString(key));
    button.setFont(parent.getFont());
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    //        data.heightHint = convertVerticalDLUsToPixels(button, IDialogConstants.BUTTON_HEIGHT);
    int widthHint = convertHorizontalDLUsToPixelsStatic(button, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
    button.addSelectionListener(listenerToAdd);
    return button;
}
 
Example 24
@Override
public void createControl(Composite parent) {
	super.createControl(parent);
	reloadOnChange = new Button(resComposite, SWT.CHECK);
	reloadOnChange.setText(Messages.RunFirefoxDebugTab_ReloadOnChange); 
	reloadOnChange.addSelectionListener(SelectionListener.widgetSelectedAdapter((e) -> {
		setDirty(true);
		updateLaunchConfigurationDialog();
	}));
}
 
Example 25
private SelectionListener createItemSelectionListener(){
	return new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			showHideShell();
		}
	};
}
 
Example 26
Source Project: nebula   Source File: RoundedToolItem.java    License: Eclipse Public License 2.0 5 votes vote down vote up
void fireSelectionEvent() {
	final Event event = new Event();
	event.widget = parentToolbar;
	event.display = getDisplay();
	event.item = this;
	event.type = SWT.Selection;
	for (final SelectionListener selectionListener : selectionListeners) {
		selectionListener.widgetSelected(new SelectionEvent(event));
	}
}
 
Example 27
public void clear() {
  for (C item : items) {
    for (SelectionListener listener : item.getSelectionListeners()) {
      item.removeSelectionListener(listener);
    }
  }
  for (Control child : scrolledCanvas.getChildren()) {
    child.dispose();
  }
  items.clear();
  doUpdateContentSize();
}
 
Example 28
Source Project: Pydev   Source File: LinkFieldEditor.java    License: Eclipse Public License 1.0 4 votes vote down vote up
private SelectionListener getSelectionListener() {
    return selectionListener;
}
 
Example 29
Source Project: hop   Source File: ColumnInfo.java    License: Apache License 2.0 4 votes vote down vote up
public SelectionListener getTextVarButtonSelectionListener() {
  return textVarButtonSelectionListener;
}
 
Example 30
Source Project: hop   Source File: ColumnInfo.java    License: Apache License 2.0 4 votes vote down vote up
public void setTextVarButtonSelectionListener( SelectionListener textVarButtonSelectionListener ) {
  this.textVarButtonSelectionListener = textVarButtonSelectionListener;
}