how to use databinding to bind dynamic data [message #328356] |
Thu, 22 May 2008 22:44  |
Eclipse User |
|
|
|
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 01:11   |
Eclipse User |
|
|
|
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 06:19   |
Eclipse User |
|
|
|
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 06:35   |
Eclipse User |
|
|
|
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 #328372 is a reply to message #328370] |
Fri, 23 May 2008 09:16  |
Eclipse User |
|
|
|
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
------------------------------------------------------------ --------
|
|
|
Powered by
FUDForum. Page generated in 0.02554 seconds