|
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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Matthew Hall![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=qualidafial%40gmail.com) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Hao Missing name![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=d95776%40yahoo.com) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Thomas Schindl![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=tom.schindl%40bestsolution.at) 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
------------------------------------------------------------ --------
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03839 seconds