Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » SetSelection programmatically in TreeViewer causes no event?
SetSelection programmatically in TreeViewer causes no event? [message #466022] Thu, 12 April 2007 14:56 Go to next message
Eclipse UserFriend
Originally posted by: s_haeusler.web.de

Hello,

in an RCP Application i am using a view with a JFace tree viewer. Other
views should react on selection of an item in this tree

Therefore a set the tree viewer as a selection provider for the site as
follows:

getSite().setSelectionProvider(viewer);

The view that should listen to the selection implements ISelectionListener
and is registered as follows:

getViewSite().getPage().addSelectionListener(this);

When i set the selection with the mouse or keyboard all is correct, the view
that listens to the selection does the right thing.

But now my question: When i set the selection programmatically

this.viewer.setSelection(new StructuredSelection(...))

the selection is set to the tree, but it seems that there is no event
thrown, because nothing happens in the other view.
Am i doing something wrong? Does the programmatically called setSelection
does not throw a selection? How can i fire a selection event on myself, if
that is the case?


Greetings
Re: SetSelection programmatically in TreeViewer causes no event? [message #466038 is a reply to message #466022] Thu, 12 April 2007 17:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

This is by design. SWT and JFace are not fireing listeners when you set
something programmtically.

Tom

Stefan Häusler schrieb:
> Hello,
>
> in an RCP Application i am using a view with a JFace tree viewer. Other
> views should react on selection of an item in this tree
>
> Therefore a set the tree viewer as a selection provider for the site as
> follows:
>
> getSite().setSelectionProvider(viewer);
>
> The view that should listen to the selection implements ISelectionListener
> and is registered as follows:
>
> getViewSite().getPage().addSelectionListener(this);
>
> When i set the selection with the mouse or keyboard all is correct, the view
> that listens to the selection does the right thing.
>
> But now my question: When i set the selection programmatically
>
> this.viewer.setSelection(new StructuredSelection(...))
>
> the selection is set to the tree, but it seems that there is no event
> thrown, because nothing happens in the other view.
> Am i doing something wrong? Does the programmatically called setSelection
> does not throw a selection? How can i fire a selection event on myself, if
> that is the case?
>
>
> Greetings
>
>
Re: SetSelection programmatically in TreeViewer causes no event? [message #466050 is a reply to message #466038] Thu, 12 April 2007 19:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Sorry wrong I just tested and an event is fired by the Viewer. Does a
selection really occur? For SWT the statement is still right it doesn't
fire events when doing something programmatically.

Tom


Tom Schindl schrieb:
> Hi,
>
> This is by design. SWT and JFace are not fireing listeners when you set
> something programmtically.
>
> Tom
>
> Stefan Häusler schrieb:
>> Hello,
>>
>> in an RCP Application i am using a view with a JFace tree viewer.
>> Other views should react on selection of an item in this tree
>>
>> Therefore a set the tree viewer as a selection provider for the site
>> as follows:
>>
>> getSite().setSelectionProvider(viewer);
>>
>> The view that should listen to the selection implements
>> ISelectionListener and is registered as follows:
>>
>> getViewSite().getPage().addSelectionListener(this);
>>
>> When i set the selection with the mouse or keyboard all is correct,
>> the view that listens to the selection does the right thing.
>>
>> But now my question: When i set the selection programmatically
>>
>> this.viewer.setSelection(new StructuredSelection(...))
>>
>> the selection is set to the tree, but it seems that there is no event
>> thrown, because nothing happens in the other view.
>> Am i doing something wrong? Does the programmatically called
>> setSelection does not throw a selection? How can i fire a selection
>> event on myself, if that is the case?
>>
>>
>> Greetings
>>
Re: SetSelection programmatically in TreeViewer causes no event? [message #466077 is a reply to message #466050] Fri, 13 April 2007 09:00 Go to previous message
Eclipse UserFriend
Originally posted by: s_haeusler.web.de

Hello,

thanks for the answer.

Yes, the selection is set to the tree.

I looked a little bit deeper into the code that is executed when a
selection is programmatically set.

It seems that an event is fired and all registered
ISelectionChangedListener implementations (JFace API) are notified. As
said in the first posting, i registered an ISelectionListener
(org.eclipse.ui Plug-In).

So for me it seems, that an event is fired, but the an ISelectionListener
is not notified.

Instead i have to register an ISelectionChangedListener? Seems a little
bit odd to me that i need two different listener for (for me) the same
thing

Greetings
Previous Topic:universal intro labels
Next Topic:Opening views in tabs
Goto Forum:
  


Current Time: Thu Apr 25 17:24:19 GMT 2024

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

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

Back to the top