Programatically Fire a Selection Event [message #328232] |
Mon, 19 May 2008 12:05  |
Eclipse User |
|
|
|
Hi there,
I have a bunch of ViewParts created, all implementing the
ISelectionListener interface and registered as selectionListeners. I would
like to programatically fire a selection event from one ViewPart to update
the others, based on a value selected in a ListViewer.
From reading around it appears there are two schools of thought on this -
1. Call Widget.notifyListeners() with an Event as a parameter
or
2. Call Display.post() with an Event as a parameter
I've tried both of these, but my ISelectionListeners are not registering
the selection event. Here is the code I'm currently using:
// Trying to fire a selection event
listViewer.getList().setSelection(0);
Event event = new Event();
event.type = SWT.Selection;
event.widget = listViewer.getList();
listViewer.getList().notifyListeners(SWT.Selection, event);
Has anyone got any idea how to get this working correctly?
I understand I can call setSelection on the listViewer itself, but I don't
have the list of objects at hand to create a meaningful selection here. I
just want to ensure the first item is selected, hence the use of getList().
Thanks!
Maurice
|
|
|
|
Re: Programatically Fire a Selection Event [message #328240 is a reply to message #328232] |
Mon, 19 May 2008 14:02   |
Eclipse User |
|
|
|
Tell the view's site to setSelectionProvider to your ListViewer.
Something like:
getSite().setSelectionProvider(myListViewer);
You follow up post cites an message that suggests this already. In what
way is setSelectionProvider *not* doing what you need?
You might also consider setting the selection provider to another
implementation of ISelectionProvider. Say, a custom one that suits your
purposes...
Wayne
On Mon, 2008-05-19 at 16:05 +0000, Maurice O\'Connor wrote:
> Hi there,
>
> I have a bunch of ViewParts created, all implementing the
> ISelectionListener interface and registered as selectionListeners. I would
> like to programatically fire a selection event from one ViewPart to update
> the others, based on a value selected in a ListViewer.
>
> From reading around it appears there are two schools of thought on this -
>
> 1. Call Widget.notifyListeners() with an Event as a parameter
>
> or
>
> 2. Call Display.post() with an Event as a parameter
>
> I've tried both of these, but my ISelectionListeners are not registering
> the selection event. Here is the code I'm currently using:
>
> // Trying to fire a selection event
> listViewer.getList().setSelection(0);
> Event event = new Event();
> event.type = SWT.Selection;
> event.widget = listViewer.getList();
> listViewer.getList().notifyListeners(SWT.Selection, event);
>
> Has anyone got any idea how to get this working correctly?
>
> I understand I can call setSelection on the listViewer itself, but I don't
> have the list of objects at hand to create a meaningful selection here. I
> just want to ensure the first item is selected, hence the use of getList().
>
> Thanks!
>
> Maurice
>
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08976 seconds