Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » ComboViewer Add SelectionChangedListener does not work
ComboViewer Add SelectionChangedListener does not work [message #329374] Sat, 21 June 2008 21:42 Go to next message
Hao Missing name is currently offline Hao Missing name
Messages: 115
Registered: July 2009
Senior Member
I use the following code to add SelectionChangedListener. It does not
work. It always returns selection is empty when I do select some item in
the combo. Could you please tell me what's wrong with the code?
acctNumberCombo = new ComboViewer(parent, SWT.SINGLE|SWT.DROP_DOWN);
acctNumberCombo.setContentProvider(new ArrayContentProvider());

acctNumberCombo.addSelectionChangedListener(new
ISelectionChangedListener(){
StructuredSelection selected;
public void selectionChanged(SelectionChangedEvent event) {
selected = (StructuredSelection)event.getSelection();
System.out.println(selected.getClass().getName());
if( (selected!=null)&&(!selected.isEmpty()) ){
System.out.println(selected.getFirstElement());
}else{
System.out.println("Selection is empty!");
}
}
});
Re: ComboViewer Add SelectionChangedListener does not work [message #329378 is a reply to message #329374] Sun, 22 June 2008 05:08 Go to previous message
Eclipse User
Originally posted by: malloovidio.bluewin.ch

Hao,

your code seems to work fine for me in Eclipse 3.4 RC1. How are you trying
to select an item from the combo (drop-down-list/cursor/free-text+ENTER)?

Regards,
Ovidio


hao wrote:
> I use the following code to add SelectionChangedListener. It does not
> work. It always returns selection is empty when I do select some item in
> the combo. Could you please tell me what's wrong with the code?
> acctNumberCombo = new ComboViewer(parent,
> SWT.SINGLE|SWT.DROP_DOWN);
> acctNumberCombo.setContentProvider(new ArrayContentProvider());
>
> acctNumberCombo.addSelectionChangedListener(new
> ISelectionChangedListener(){
> StructuredSelection selected;
> public void selectionChanged(SelectionChangedEvent event) {
> selected = (StructuredSelection)event.getSelection();
> System.out.println(selected.getClass().getName());
> if( (selected!=null)&&(!selected.isEmpty()) ){
> System.out.println(selected.getFirstElement());
> }else{
> System.out.println("Selection is empty!");
> }
> }
> });
>
Previous Topic:How to set Default "Rus As" > launchShortcut to F11 or Ctrl+F11 selection
Next Topic:dealing with multi-byte characters in editor
Goto Forum:
  


Current Time: Tue Jul 29 17:07:42 EDT 2014

Powered by FUDForum. Page generated in 0.01427 seconds