Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » why ComboViewer starts with blank selection?
why ComboViewer starts with blank selection? [message #558054] Fri, 10 September 2010 03:16 Go to next message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
I constructed a ComboViewer by giving it both content provider and label provider, it works ok, but it is annoying that the combo viewer always start with a blank selection, even though I declared this:

comboViewer.getCombo().select( 0 );


or this:

comboViewer.setSelection( new StructuredSelection(list[0]) );


How can I avoid that blank selection?

[Updated on: Fri, 10 September 2010 03:18]

Report message to a moderator

Re: why ComboViewer starts with blank selection? [message #558109 is a reply to message #558054] Fri, 10 September 2010 08:09 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
When are you doing this call. It has to be after the setInput() call.

Tom

Am 10.09.10 05:16, schrieb Frank:
> I constructed a ComboViewer by giving it both content provider and label
> provider, it works ok, but it is annoying that the combo viewer start
> with a blank selectio always, even though I declared this:
>
> comboViewer.getCombo().select( 0 );
>
> or this:
>
> comboViewer.setSelection( new StructuredSelection(list[0]) );
>
> How can I avoid that blank selection?
>
>
Re: why ComboViewer starts with blank selection? [message #558123 is a reply to message #558109] Fri, 10 September 2010 09:17 Go to previous messageGo to next message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
Here is my code snippet
    comboViewer = new ComboViewer( this, SWT.READ_ONLY );
    comboViewer.getCombo().setLayoutData( gridData1 );

    IStructuredContentProvider contentProvider = ArrayContentProvider.getInstance();
    comboViewer.setContentProvider( contentProvider );

    ILabelProvider labelProvider = new LabelProvider()
      {
        @Override
        public String getText( Object element )
        {
          MyExtension extension = (MyExtension) element;
          return extension.getDisplayText();
        }
      };
    comboViewer.setLabelProvider( labelProvider );

    MyExtension[] extensions = MyExtensions.getExtensions();
    comboViewer.setInput(extensions);
    // TODO avoid blank selection
    comboViewer.getCombo().select( 0 );
Re: why ComboViewer starts with blank selection? [message #558127 is a reply to message #558123] Fri, 10 September 2010 09:32 Go to previous messageGo to next message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
I feel that I have found the reason, but I don't know how to resolve it.

All those control settings are contained in a Dialog, the setSelection method doesn't work, of course, before the Dialog opens.

I want the selection be set when the Dialog opens.
Re: why ComboViewer starts with blank selection? [message #558129 is a reply to message #558123] Fri, 10 September 2010 09:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
What is this - a composite?

Tom

Am 10.09.10 11:17, schrieb Frank:
> Here is my code snippet
>
> comboViewer = new ComboViewer( this, SWT.READ_ONLY );
> comboViewer.getCombo().setLayoutData( gridData1 );
>
> IStructuredContentProvider contentProvider =
> ArrayContentProvider.getInstance();
> comboViewer.setContentProvider( contentProvider );
>
> ILabelProvider labelProvider = new LabelProvider()
> {
> @Override
> public String getText( Object element )
> {
> MyExtension extension = (MyExtension) element;
> return extension.getDisplayText();
> }
> };
> comboViewer.setLabelProvider( labelProvider );
>
> MyExtension[] extensions = MyExtensions.getExtensions();
> comboViewer.setInput(extensions);
> // TODO avoid blank selection
> comboViewer.getCombo().select( 0 );
Re: why ComboViewer starts with blank selection? [message #558135 is a reply to message #558127] Fri, 10 September 2010 09:49 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
So you are saying that the call has no effect when done before the shell
is shown?

Can you give use more details about your Eclipse version, OS, ... and
some snippet we can run to reproduce the problem?

Tom

Am 10.09.10 11:32, schrieb Frank:
> I feel that I have found the reason, but I don't know how to resolve it.
>
> All those control settings are contained in a Dialog, the setSelection
> method doesn't work, of course, before the Dialog opens.
>
> I want the selection be set when the Dialog opens.
Re: why ComboViewer starts with blank selection? [message #558324 is a reply to message #558135] Sat, 11 September 2010 09:20 Go to previous message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
Thank you very much Tom.
I'm sorry that it turns out to be my fault. I introduced a bug to the data-binding part of my code.
Sorry.
Previous Topic:showView fails to show the view from preShutdown()
Next Topic:How to propagate element changes to WritableList's listener?
Goto Forum:
  


Current Time: Fri Dec 13 16:40:39 GMT 2024

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

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

Back to the top