Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » CCombo and Databinding
CCombo and Databinding [message #330213] Mon, 21 July 2008 14:28 Go to next message
Matthias Schoettle is currently offline Matthias SchoettleFriend
Messages: 44
Registered: July 2009
Member
Hello,

I have a list of objects and a CCombo which shows the name attribute of
these objects. I want to bind the objects that when an item is
added/removed from the CCombo the model gets updated (i.e. I want to
create/delete objects from the list). Is this possible?

Thanks
Matthias
Re: CCombo and Databinding [message #330214 is a reply to message #330213] Mon, 21 July 2008 15:43 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Matthias Schoettle wrote:
> I have a list of objects and a CCombo which shows the name attribute of
> these objects. I want to bind the objects that when an item is
> added/removed from the CCombo the model gets updated (i.e. I want to
> create/delete objects from the list). Is this possible?

This is easier to do if you use a combo viewer:

ComboViewer viewer = new ComboViewer(ccombo);
ObservableListContentProvider cp = new ObservableListContentProvider();
viewer.setContentProvider(cp);
// (Substitute the actual class and property names in your code)
IObservableMap itemNames = BeansObservables.observeMap(
cp.getKnownElements(), YourModelClass.class, "name");
viewer.setLabelProvider(new ObservableMapLabelProvider(itemNames));

IObservableList list = BeansObservables.observeList(
yourModelContainer, "modelList"); // (substitute real property name)
viewer.setInput(list);

In this setup, any additions or removals to the observable list will be
automatically forwarded to the viewer. This is because
ObservableListContentProvider monitors the input observable list for
changes and updates the viewer accordingly.

As for copying changes back to the model, there are a few different ways
I've seen folks do this:

1) Add and remove elements on the input observable list. Because this
list is backed by your model, changes to the list will be propagated
back to the model.

2) Add and remove elements directly on the model. As long as your model
objects fire property change events for each change, the changes will
show up immediately in the combo.

Hope this helps,

Matthew
Re: CCombo and Databinding [message #330251 is a reply to message #330214] Wed, 23 July 2008 06:31 Go to previous message
Matthias Schoettle is currently offline Matthias SchoettleFriend
Messages: 44
Registered: July 2009
Member
Matthew Hall wrote:
> Matthias Schoettle wrote:
>> I have a list of objects and a CCombo which shows the name attribute
>> of these objects. I want to bind the objects that when an item is
>> added/removed from the CCombo the model gets updated (i.e. I want to
>> create/delete objects from the list). Is this possible?
>
> This is easier to do if you use a combo viewer:
>
> ComboViewer viewer = new ComboViewer(ccombo);
> ObservableListContentProvider cp = new ObservableListContentProvider();
> viewer.setContentProvider(cp);
> // (Substitute the actual class and property names in your code)
> IObservableMap itemNames = BeansObservables.observeMap(
> cp.getKnownElements(), YourModelClass.class, "name");
> viewer.setLabelProvider(new ObservableMapLabelProvider(itemNames));
>
> IObservableList list = BeansObservables.observeList(
> yourModelContainer, "modelList"); // (substitute real property name)
> viewer.setInput(list);
>
> In this setup, any additions or removals to the observable list will be
> automatically forwarded to the viewer. This is because
> ObservableListContentProvider monitors the input observable list for
> changes and updates the viewer accordingly.
>
> As for copying changes back to the model, there are a few different ways
> I've seen folks do this:
>
> 1) Add and remove elements on the input observable list. Because this
> list is backed by your model, changes to the list will be propagated
> back to the model.
>
> 2) Add and remove elements directly on the model. As long as your model
> objects fire property change events for each change, the changes will
> show up immediately in the combo.
>
> Hope this helps,
>
> Matthew

Thanks Matthew, works great. I only need to refresh the ComboViewer when
removing the current selected object as the selection doesn't change.

Matthias
Previous Topic:customizing finish button on org.eclipse.jface.wizard.Wizard
Next Topic:Plugins with different versions, one as project, one as jar
Goto Forum:
  


Current Time: Thu Dec 26 15:03:39 GMT 2024

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

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

Back to the top