|
|
Re: Programatically Fire a Selection Event [message #328240 is a reply to message #328232] |
Mon, 19 May 2008 18:02 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Wayne Beaton![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=wayne.beaton%40eclipse-foundation.org) Messages: 554 Registered: December 2017 |
Senior Member |
|
|
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
>
|
|
|
|
Re: Programatically Fire a Selection Event [message #328256 is a reply to message #328252] |
Tue, 20 May 2008 12:04 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: merks.ca.ibm.com
Maurice,
I think you'd have to create your own SelectionEvent and call
notifyListeners with it.
Maurice O'Connor wrote:
> Wayne Beaton wrote:
>> 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...
>
>
> Heya, thanks for the help!
>
> setSelectionProvider works for me. I add the listViewer as a provider,
> then the user clicks the items in the list to update other ViewParts,
> each of those implementing ISelectionListener and registered using the
> Selection Service. eg.
>
> In one ViewPart:
>
> getSite().setSelectionProvider(listViewer);
>
> In the others:
>
> getSite().getPage().addSelectionListener(new
> ListISelectionListener());
>
> The ISelectionListeners update correctly except when an item is
> selected on the list programmatically. Eg.
>
> listViewer.getList().setSelection(0);
>
> In that case I need to fire my own event to trigger the
> selectionChanged method in the ISelectionListeners - my problem is
> figuring out how to do this.
>
> Maurice
>
|
|
|
|
|
Re: Programatically Fire a Selection Event [message #328283 is a reply to message #328280] |
Tue, 20 May 2008 16:50 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: merks.ca.ibm.com
Maurice,
I think maybe it needs to be a SelectionEvent. You should also have to
look closely at all the fields that are normally populated and populate
them properly.
Wayne,
Programmatically changing the selection of a widget (or anything else
you do with it) doesn't fire the same events as when the user does that
same thing. This is by design.
Maurice O'Connor wrote:
> Wayne Beaton wrote:
>> What are you really trying to do?
>>
>> Do listeners get properly notified when you go through the ListViewer's
>> API:
>>
>> listViewer.setSelection(StructuredSelection.EMPTY);
>>
>> Wayne
>
> This will notify ISelectionChangedListeners of the above change.
> However, my listeners implement ISelectionListener. I need to notify
> the ISelectionListeners by firing a new selection event through the
> workbench selection service.
>
> The listViewer is already registered as a SelectionProvider:
>
> getSite().setSelectionProvider(listViewer);
>
> Now I must create my own Event and notify its listeners:
>
> listViewer.getList().notifyListeners(SWT.Selection, new Event());
>
> That doesn't work though. There's a nice tutorial here:
>
> http://www.eclipse.org/articles/Article-WorkbenchSelections/ article.html
>
> It says:
> "Each workbench window has its own selection service instance. The
> service keeps track of the selection in the currently active part and
> propagates selection changes to all registered listeners. Such
> selection events occur when the selection in the current part is
> changed or when a different part is activated. Both can be triggered
> by user interaction or programmatically."
>
> I'm trying to work out how to do this programmatically, with little
> success so far ;)
>
> Maurice
>
|
|
|
|
Re: Programatically Fire a Selection Event [message #328326 is a reply to message #328319] |
Wed, 21 May 2008 16:00 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: merks.ca.ibm.com
Maurice,
I've never done it so tracing through the calls in each case with the
debugger would be my approach...
Maurice O'Connor wrote:
> Ed Merks wrote:
>
>> I think maybe it needs to be a SelectionEvent. You should also have
>> to look closely at all the fields that are normally populated and
>> populate them properly.
>
> notifyListeners(Event event) & getDisplay().post(Event event)
>
> These take only a plain Event as a parameter. So I tried both of
> these. A comparison of both a generated event and one of my own
> creation is below:
>
> Event {type=13 List {} time=32740484 data=null x=0 y=0 width=0
> height=0 detail=0}
> Event {type=13 List {} time=29613453 data=null x=0 y=0 width=0
> height=0 detail=0}
>
> Still not getting through to the SelectionListeners with this. Perhaps
> I have registered the listeners incorrectly?
>
> getSite().getPage().addSelectionListener(new ChangeListener(listViewer));
>
> The listViewer is registered in the ViewPart like so:
>
> getSite().setSelectionProvider(listViewer);
>
> Maurice
> Maurice
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04946 seconds