|
Re: How to solve the setSelection problem? [message #459352 is a reply to message #459351] |
Sun, 07 August 2005 13:14 |
Eclipse User |
|
|
|
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 #459379 is a reply to message #459378] |
Mon, 08 August 2005 13:47 |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.02858 seconds