Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » how to use databinding to bind dynamic data
how to use databinding to bind dynamic data [message #328356] Fri, 23 May 2008 02:44 Go to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
I am using jface databinding feature to bind between GUI objects and model
objects. When the GUI is created, the DataBindingContext is used to bind
GUI objects and model. During the operation of the application, the model
data might be changed (model structure is not changed.). How could I use
DataBindingContext to re-bind the GUI objects to the changed model data.
Re: how to use databinding to bind dynamic data [message #328357 is a reply to message #328356] Fri, 23 May 2008 05:11 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
hao wrote:
> I am using jface databinding feature to bind between GUI objects and
> model objects. When the GUI is created, the DataBindingContext is used
> to bind GUI objects and model. During the operation of the application,
> the model data might be changed (model structure is not changed.). How
> could I use DataBindingContext to re-bind the GUI objects to the changed
> model data.

Your objects have expose an observer pattern in your model API, and use
an IObservable tailored to use that specific observer pattern.

Currently there are two options supported by Eclipse:
* Implement the official bean specification, and use BeansObservables to
observe bean properties.
* Implement model objects using EMF, and use EMFObservables to observe
EStructuralFeatures.

I'm not very familiar with EMF so I won't be much help there. However
with the bean spec there are just a few methods required:

public void addPropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)

public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)

This is commonly implemented using by extending a superclass such as
ModelObject as you have seen in the examples. The common pattern I use
in my setter methods is:

public void setName(String name) {
firePropertyChange("name", this.name, this.name = name);
}

Hope this helps,

Matthew
Re: how to use databinding to bind dynamic data [message #328363 is a reply to message #328357] Fri, 23 May 2008 10:19 Go to previous messageGo to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
Let me explain what I am trying to ask:

For example, I have a model called Contact which has a name attribute. The
name field of the Contact is binded to a GUI text field called nameText.
When the GUI class is constructed, the following is called:

private Contact contact;
private Text nameText;
private DataBindingContext bindingContext;

....
//In constructor

IObservableValue contactNameObserveValue =
BeansObservables.observeValue(contact, "name");
IObservableValue nameTextTextObserveWidget =
SWTObservables.observeText(nameText, SWT.Modify);
bindingContext.bindValue(nameTextTextObserveWidget,
contactNameObserveValue, null, null);


For some reason, during the operation of the application, the contact
object is replaced with a new contact object. (Not the property name of
the contact object is changed but contact object itself is changed.) How
could I rebind the newly created contact object to nameText object?

thanks!
Re: how to use databinding to bind dynamic data [message #328364 is a reply to message #328363] Fri, 23 May 2008 10:35 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
WritableValue v = new WritableValue(Contact.class);
BeansObservable.observeDetailValue(v,"name");

v.setValue(new Contact());

So in fact this is a master-detail problem :-)

Tom

hao schrieb:
> Let me explain what I am trying to ask:
>
> For example, I have a model called Contact which has a name attribute.
> The name field of the Contact is binded to a GUI text field called
> nameText. When the GUI class is constructed, the following is called:
>
> private Contact contact;
> private Text nameText;
> private DataBindingContext bindingContext;
>
> ...
> //In constructor
>
> IObservableValue contactNameObserveValue =
> BeansObservables.observeValue(contact, "name");
> IObservableValue nameTextTextObserveWidget =
> SWTObservables.observeText(nameText, SWT.Modify);
> bindingContext.bindValue(nameTextTextObserveWidget,
> contactNameObserveValue, null, null);
>
>
> For some reason, during the operation of the application, the contact
> object is replaced with a new contact object. (Not the property name of
> the contact object is changed but contact object itself is changed.) How
> could I rebind the newly created contact object to nameText object?
>
> thanks!
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: how to use databinding to bind dynamic data [message #328370 is a reply to message #328364] Fri, 23 May 2008 13:06 Go to previous messageGo to next message
Hao Missing name is currently offline Hao Missing nameFriend
Messages: 115
Registered: July 2009
Senior Member
Can I use bindingContext.updateTargets() method to realize it?
Re: how to use databinding to bind dynamic data [message #328372 is a reply to message #328370] Fri, 23 May 2008 13:16 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You don't use updateTargets().

wv = new WritableValue(Contact.class);


wv.setValue(new Contact());

// ..... work

wv.setValue(new Contact());

Tom


hao schrieb:
> Can I use bindingContext.updateTargets() method to realize it?
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Previous Topic:Problems building a plugin after changing to Eclipse SDK download
Next Topic:Problem while accessing db2 from plugin project
Goto Forum:
  


Current Time: Wed Jul 17 17:27:11 GMT 2024

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

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

Back to the top