Skip to main content


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] Sun, 22 June 2008 01:42 Go to next message
Hao Missing name is currently offline Hao Missing nameFriend
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 09:08 Go to previous message
Eclipse UserFriend
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: Fri Apr 26 21:35:24 GMT 2024

Powered by FUDForum. Page generated in 0.01982 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top