Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] How to enforce the selection after an update/recalculation of a ComputedList?
[DataBinding] How to enforce the selection after an update/recalculation of a ComputedList? [message #489740] Mon, 05 October 2009 17:42 Go to next message
Eclipse UserFriend
Originally posted by: am.andreasmeissner.de

Hi,

I have the following problem. I'm using a ComboViewer with an
ObservableListContentProvider and a ComputedList as input.

The update of the ComboViewer's input works fine (based on another
ComboViewer's selection). However, I have problems to enforce a default
selection of the updated ComboViewer after the ComputedList was newly
calculated. In my case I would like to simply pre-select the first
element in the ComboViewer afterwards.

What's the best approach to do so?

Thanks!

Cheers,
Andreas
Re: [DataBinding] How to enforce the selection after an update/recalculation of a ComputedList? [message #490505 is a reply to message #489740] Thu, 08 October 2009 20:36 Go to previous messageGo to next message
Ovidio Mallo is currently offline Ovidio MalloFriend
Messages: 35
Registered: July 2009
Member
Hi Andreas,

if you always have the same ComputeList as viewer input and you
want to set the viewer's selection to the first element whenever
the ComputedList changes, you might do so using the ControlUpdater
class (note that this is provisional API but it's been around for
quite some while). You would then do something like the following:

final ComboViewer viewer = ...;
final ComputedList inputList = ...;
viewer.setContentProvider(new ObservableListContentProvider());
viewer.setInput(inputList);

new ControlUpdater(viewer.getControl()) {
protected void updateControl() {
if (!inputList.isEmpty()) {
viewer.setSelection(new StructuredSelection(inputList.get(0)));
}
}
};

I hope this helps.

Regards,
Ovidio


Andreas Meißner wrote:
> Hi,
>
> I have the following problem. I'm using a ComboViewer with an
> ObservableListContentProvider and a ComputedList as input.
>
> The update of the ComboViewer's input works fine (based on another
> ComboViewer's selection). However, I have problems to enforce a default
> selection of the updated ComboViewer after the ComputedList was newly
> calculated. In my case I would like to simply pre-select the first
> element in the ComboViewer afterwards.
>
> What's the best approach to do so?
>
> Thanks!
>
> Cheers,
> Andreas
Re: [DataBinding] How to enforce the selection after an update/recalculation of a ComputedList? [message #490535 is a reply to message #490505] Fri, 09 October 2009 04:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: am.andreasmeissner.de

Thanks, for the hint! Unfortunately we're not allowed to use internal
code in our project.

However, I will keep an eye on this class .. maybe it's becoming public
API in the future and I can use it in other projects.

BTW, right now I'm using a little ugly hack to solve my problem by
starting a delayed UIJob inside the ComputedList that updates the
control afterwards if necessary. Not nice but it works.

Thanks again.
Andreas


Ovidio Mallo schrieb:
> Hi Andreas,
>
> if you always have the same ComputeList as viewer input and you
> want to set the viewer's selection to the first element whenever
> the ComputedList changes, you might do so using the ControlUpdater
> class (note that this is provisional API but it's been around for
> quite some while). You would then do something like the following:
>
> final ComboViewer viewer = ...;
> final ComputedList inputList = ...;
> viewer.setContentProvider(new ObservableListContentProvider());
> viewer.setInput(inputList);
>
> new ControlUpdater(viewer.getControl()) {
> protected void updateControl() {
> if (!inputList.isEmpty()) {
> viewer.setSelection(new StructuredSelection(inputList.get(0)));
> }
> }
> };
>
> I hope this helps.
>
> Regards,
> Ovidio
>
>
> Andreas Meißner wrote:
>> Hi,
>>
>> I have the following problem. I'm using a ComboViewer with an
>> ObservableListContentProvider and a ComputedList as input.
>>
>> The update of the ComboViewer's input works fine (based on another
>> ComboViewer's selection). However, I have problems to enforce a
>> default selection of the updated ComboViewer after the ComputedList
>> was newly calculated. In my case I would like to simply pre-select the
>> first element in the ComboViewer afterwards.
>>
>> What's the best approach to do so?
>>
>> Thanks!
>>
>> Cheers,
>> Andreas
Re: [DataBinding] How to enforce the selection after an update/recalculation of a ComputedList? [message #490705 is a reply to message #490535] Fri, 09 October 2009 18:31 Go to previous message
Ovidio Mallo is currently offline Ovidio MalloFriend
Messages: 35
Registered: July 2009
Member
Andreas,

note that the ControlUpdater class is not internal but simply
provisional.

Anyhow, in your case, a simple change listener on the ComputedList would
essentially do the same like what the ControlUpdater class does.
Maybe something like the following would already be enough?

inputList.addListChangeListener(new IListChangeListener() {
public void handleListChange(ListChangeEvent event) {
if (!viewer.getControl().isDisposed() && !inputList.isEmpty()) {
// React on changes.
viewer.setSelection(new StructuredSelection(inputList.get(0)));
}
}
});
// Initialize the selection once.
viewer.setSelection(new StructuredSelection(inputList.get(0)));

I think that this code is pretty equivalent to the previous one using
the ControlUpdater class. Maybe this would already work for you. You
might also want to detach the listener when disposing your UI.

Regards,
Ovidio


Andreas Meißner wrote:
> Thanks, for the hint! Unfortunately we're not allowed to use internal
> code in our project.
>
> However, I will keep an eye on this class .. maybe it's becoming public
> API in the future and I can use it in other projects.
>
> BTW, right now I'm using a little ugly hack to solve my problem by
> starting a delayed UIJob inside the ComputedList that updates the
> control afterwards if necessary. Not nice but it works.
>
> Thanks again.
> Andreas
>
>
> Ovidio Mallo schrieb:
>> Hi Andreas,
>>
>> if you always have the same ComputeList as viewer input and you
>> want to set the viewer's selection to the first element whenever
>> the ComputedList changes, you might do so using the ControlUpdater
>> class (note that this is provisional API but it's been around for
>> quite some while). You would then do something like the following:
>>
>> final ComboViewer viewer = ...;
>> final ComputedList inputList = ...;
>> viewer.setContentProvider(new ObservableListContentProvider());
>> viewer.setInput(inputList);
>>
>> new ControlUpdater(viewer.getControl()) {
>> protected void updateControl() {
>> if (!inputList.isEmpty()) {
>> viewer.setSelection(new StructuredSelection(inputList.get(0)));
>> }
>> }
>> };
>>
>> I hope this helps.
>>
>> Regards,
>> Ovidio
>>
>>
>> Andreas Meißner wrote:
>>> Hi,
>>>
>>> I have the following problem. I'm using a ComboViewer with an
>>> ObservableListContentProvider and a ComputedList as input.
>>>
>>> The update of the ComboViewer's input works fine (based on another
>>> ComboViewer's selection). However, I have problems to enforce a
>>> default selection of the updated ComboViewer after the ComputedList
>>> was newly calculated. In my case I would like to simply pre-select
>>> the first element in the ComboViewer afterwards.
>>>
>>> What's the best approach to do so?
>>>
>>> Thanks!
>>>
>>> Cheers,
>>> Andreas
Previous Topic:How to make Browser.setText to show the XHTML?
Next Topic:Installed Features Versions
Goto Forum:
  


Current Time: Tue Mar 19 02:09:09 GMT 2024

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

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

Back to the top