Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to solve the setSelection problem?
How to solve the setSelection problem? [message #459351] Sun, 07 August 2005 10:44 Go to next message
jfeid is currently offline jfeidFriend
Messages: 21
Registered: July 2009
Junior Member
Hi all,

Is there a simple technique to set the initial selection on a TreeViewer
or a TableViewer? I use a data model which is shared by a view in the main
perspective and some of the File->New... wizards. It would be nice to set
the initial selection on the viewer controls in the wizards to the same
selection set by the user in the main view (as this works in Eclipse's
wizards). For example, i create a TableViewer on the wizard's
createControl and set the initial selection as follows:

viewer = new TableViewer( comp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
viewer.setContentProvider( new MyContentProvider() );
viewer.setLabelProvider( new MyLabelProvider() );
viewer.setInput( myRootModelObject );
ISelection selection = getUserSelection();
viewer.setSelection(selection, true);

This does not work, simply because the viewer is not yet populated with
elements at the time the setSelection method is called. How can be certain
that the viewer has complete population and then call setSelection?

Any help would be appreciated.
Thanx a lot.
Re: How to solve the setSelection problem? [message #459352 is a reply to message #459351] Sun, 07 August 2005 13:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Yannis Feidaros" <jfeid@mycosmos.gr> wrote in message
news:e9cbc73182c92ac42f095d15747098ca$1@www.eclipse.org...
> Hi all,
>
> Is there a simple technique to set the initial selection on a TreeViewer
> or a TableViewer? I use a data model which is shared by a view in the main
> perspective and some of the File->New... wizards. It would be nice to set
> the initial selection on the viewer controls in the wizards to the same
> selection set by the user in the main view (as this works in Eclipse's
> wizards). For example, i create a TableViewer on the wizard's
> createControl and set the initial selection as follows:
>
> viewer = new TableViewer( comp, SWT.H_SCROLL | SWT.V_SCROLL |
> SWT.BORDER );
> viewer.setContentProvider( new MyContentProvider() );
> viewer.setLabelProvider( new MyLabelProvider() );
> viewer.setInput( myRootModelObject );
> ISelection selection = getUserSelection();
> viewer.setSelection(selection, true);
>
> This does not work, simply because the viewer is not yet populated with
> elements at the time the setSelection method is called. How can be certain
> that the viewer has complete population and then call setSelection?

The viewer should get populated when the setInput call is complete.
So setSelection should work.
I use a similar technique all the time.
Only reason it would not work is if the user selection elements are not
present in the viewer input.
---
Sunil
Re: How to solve the setSelection problem? [message #459378 is a reply to message #459352] Mon, 08 August 2005 10:49 Go to previous messageGo to next message
jfeid is currently offline jfeidFriend
Messages: 21
Registered: July 2009
Junior Member
Sunil Kamath wrote:

> The viewer should get populated when the setInput call is complete.
> So setSelection should work.
> I use a similar technique all the time.
> Only reason it would not work is if the user selection elements are not
> present in the viewer input.
> ---
> Sunil

Ok.
The object instances between the ones requested by setSelection and the
ones that exist in the viewer must be the same instances? For example, the
following should not work, is that right?

Object object1 = new Object();
Object object2 = new Object();
StructuredSelection selection = new StructuredSelection(object1);
viewer.add(object2);
viewer.setSelection(selection, true);

Yannis
Re: How to solve the setSelection problem? [message #459379 is a reply to message #459378] Mon, 08 August 2005 13:47 Go to previous message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Yannis Feidaros" <jfeid@mycosmos.gr> wrote in message
news:3bae7b83f857337067d024dafc0329eb$1@www.eclipse.org...
> Sunil Kamath wrote:
>
>> The viewer should get populated when the setInput call is complete.
>> So setSelection should work.
>> I use a similar technique all the time.
>> Only reason it would not work is if the user selection elements are not
>> present in the viewer input.
>> ---
>> Sunil
>
> Ok.
> The object instances between the ones requested by setSelection and the
> ones that exist in the viewer must be the same instances? For example, the
> following should not work, is that right?
>
> Object object1 = new Object();
> Object object2 = new Object();
> StructuredSelection selection = new StructuredSelection(object1);
> viewer.add(object2);
> viewer.setSelection(selection, true);
>
The equals() method for the object1 should return true for object2 (which
will not happen in this case).
However, it would work for the following:
String string1 = "foo";
String string2 = "foo";

---
Sunil
Previous Topic:How could I draw connection lines between two TreeItems
Next Topic:[ANN] Novocode Application Framework 0.2 released
Goto Forum:
  


Current Time: Fri Apr 26 19:03:01 GMT 2024

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

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

Back to the top