Home » Eclipse Projects » Eclipse Platform » [DataBinding] Tracking dirty model on DataBindingContext
[DataBinding] Tracking dirty model on DataBindingContext [message #327988] |
Mon, 12 May 2008 09:04 |
Eclipse User |
|
|
|
Originally posted by: malloovidio.bluewin.ch
Hi all,
I'm implementing an editor for which I'm using databinding. In the
actual editor, I'm creating a DataBindingContext which I then pass to
several classes which create portions of the editor's UI, along with
the corresponding bindings to the model.
In the editor, I wanted to track the dirty state of the model where
my first thought was to simply attach value change listeners to all
model observables of all the bindings of the DataBindingContext.
However, in my editor, I'm using several master/detail constructs
which means that some of my model observables are DetailObservableValues
whose value not only changes when the model indeed changes but also
when a different master is selected.
Therefore, my approach described above seems inappropriate as I should
not be listening on changes on the DetailObservableValues but on the
model observables they contain.
Since tracking the dirty state of a model being edited should be a
fairly standard thing, I was just wondering whether anyone else has
implemented something similar using databinding which solves the
above problem.
Thanks in advance for any feedback!
Best regards,
Ovidio
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #327990 is a reply to message #327988] |
Mon, 12 May 2008 09:26 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Well IMHO the best way is to record all changes happening to the model.
Databinding doesn't provide such a thing, having said that the only
thing that always comes to my my mind is EMF which provides a class
called ChangeRecorder and attaching it to your master model object(s)
would record all changes happening below :-) This provides another cool
thing to you because you can rollback changes. If you would use an
EditingDomain you'll even get undo/redo, great isn't it?
Tom
Ovidio Mallo schrieb:
> Hi all,
>
> I'm implementing an editor for which I'm using databinding. In the
> actual editor, I'm creating a DataBindingContext which I then pass to
> several classes which create portions of the editor's UI, along with
> the corresponding bindings to the model.
> In the editor, I wanted to track the dirty state of the model where
> my first thought was to simply attach value change listeners to all
> model observables of all the bindings of the DataBindingContext.
> However, in my editor, I'm using several master/detail constructs
> which means that some of my model observables are DetailObservableValues
> whose value not only changes when the model indeed changes but also
> when a different master is selected.
> Therefore, my approach described above seems inappropriate as I should
> not be listening on changes on the DetailObservableValues but on the
> model observables they contain.
>
> Since tracking the dirty state of a model being edited should be a
> fairly standard thing, I was just wondering whether anyone else has
> implemented something similar using databinding which solves the
> above problem.
>
> Thanks in advance for any feedback!
>
> Best regards,
> Ovidio
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #327992 is a reply to message #327990] |
Mon, 12 May 2008 10:28 |
Eclipse User |
|
|
|
Originally posted by: malloovidio.bluewin.ch
Hi Tom,
first of all, thanks a lot for the immediate response and the good
hints!
Indeed, EMF seems to have some great features which work out of the box.
Unfortunately, the editor I'm implementing is part of a large project
which can hardly be adapted with hindsight to use EMF.
However, based on your hint about the EditingDomain below, I had just a
look at the EditingDomainEObjectObservableValue class of EMF which seems
to nicely integrate the dirty/undo/redo features into the databinding
world. Seems as if this could be a promising solution to our problem,
especially due to the undo/redo support which we might want to have in
a future version of our editor, too.
Thanks again for your help!
Best regards,
Ovidio
Tom Schindl wrote:
> Well IMHO the best way is to record all changes happening to the model.
>
> Databinding doesn't provide such a thing, having said that the only
> thing that always comes to my my mind is EMF which provides a class
> called ChangeRecorder and attaching it to your master model object(s)
> would record all changes happening below :-) This provides another cool
> thing to you because you can rollback changes. If you would use an
> EditingDomain you'll even get undo/redo, great isn't it?
>
> Tom
>
> Ovidio Mallo schrieb:
>> Hi all,
>>
>> I'm implementing an editor for which I'm using databinding. In the
>> actual editor, I'm creating a DataBindingContext which I then pass to
>> several classes which create portions of the editor's UI, along with
>> the corresponding bindings to the model.
>> In the editor, I wanted to track the dirty state of the model where
>> my first thought was to simply attach value change listeners to all
>> model observables of all the bindings of the DataBindingContext.
>> However, in my editor, I'm using several master/detail constructs
>> which means that some of my model observables are DetailObservableValues
>> whose value not only changes when the model indeed changes but also
>> when a different master is selected.
>> Therefore, my approach described above seems inappropriate as I should
>> not be listening on changes on the DetailObservableValues but on the
>> model observables they contain.
>>
>> Since tracking the dirty state of a model being edited should be a
>> fairly standard thing, I was just wondering whether anyone else has
>> implemented something similar using databinding which solves the
>> above problem.
>>
>> Thanks in advance for any feedback!
>>
>> Best regards,
>> Ovidio
>
>
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #327994 is a reply to message #327992] |
Mon, 12 May 2008 10:31 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
Yes that's what I talked about. I'm still not sure why you can't use
ChangeRecorder it looks as if you are using EMF (just saw a posting on
the EMF-newsgroup from you) but using an EditingDomain is even better.
Tom
Ovidio Mallo schrieb:
> Hi Tom,
>
> first of all, thanks a lot for the immediate response and the good
> hints!
>
> Indeed, EMF seems to have some great features which work out of the box.
> Unfortunately, the editor I'm implementing is part of a large project
> which can hardly be adapted with hindsight to use EMF.
> However, based on your hint about the EditingDomain below, I had just a
> look at the EditingDomainEObjectObservableValue class of EMF which seems
> to nicely integrate the dirty/undo/redo features into the databinding
> world. Seems as if this could be a promising solution to our problem,
> especially due to the undo/redo support which we might want to have in
> a future version of our editor, too.
>
> Thanks again for your help!
>
> Best regards,
> Ovidio
>
> Tom Schindl wrote:
>> Well IMHO the best way is to record all changes happening to the model.
>>
>> Databinding doesn't provide such a thing, having said that the only
>> thing that always comes to my my mind is EMF which provides a class
>> called ChangeRecorder and attaching it to your master model object(s)
>> would record all changes happening below :-) This provides another
>> cool thing to you because you can rollback changes. If you would use
>> an EditingDomain you'll even get undo/redo, great isn't it?
>>
>> Tom
>>
>> Ovidio Mallo schrieb:
>>> Hi all,
>>>
>>> I'm implementing an editor for which I'm using databinding. In the
>>> actual editor, I'm creating a DataBindingContext which I then pass to
>>> several classes which create portions of the editor's UI, along with
>>> the corresponding bindings to the model.
>>> In the editor, I wanted to track the dirty state of the model where
>>> my first thought was to simply attach value change listeners to all
>>> model observables of all the bindings of the DataBindingContext.
>>> However, in my editor, I'm using several master/detail constructs
>>> which means that some of my model observables are DetailObservableValues
>>> whose value not only changes when the model indeed changes but also
>>> when a different master is selected.
>>> Therefore, my approach described above seems inappropriate as I should
>>> not be listening on changes on the DetailObservableValues but on the
>>> model observables they contain.
>>>
>>> Since tracking the dirty state of a model being edited should be a
>>> fairly standard thing, I was just wondering whether anyone else has
>>> implemented something similar using databinding which solves the
>>> above problem.
>>>
>>> Thanks in advance for any feedback!
>>>
>>> Best regards,
>>> Ovidio
>>
>>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #327998 is a reply to message #327994] |
Mon, 12 May 2008 11:39 |
Eclipse User |
|
|
|
Originally posted by: malloovidio.bluewin.ch
Hi again Tom,
actually, I have only started looking at EMF about two weeks ago, but
I'm very interested in it, especially in the databinding support
provided by EMF (hence the post on the EMF newsgroup).
However, right now, I'm merely using EMF for some toy project of mine,
just to get started and to learn how EMF works.
However, we are not using EMF for the project I was mentioning, so
I cannot use the ChangeRecorder. Of course, I can also not use the
EditingDomainEObjectObservableValue class as is but I think that the
conceptual idea behind that class could fit our purposes, so I will
probably try to go into that direction.
Kind regards,
Ovidio
Tom Schindl wrote:
> Hi,
>
> Yes that's what I talked about. I'm still not sure why you can't use
> ChangeRecorder it looks as if you are using EMF (just saw a posting on
> the EMF-newsgroup from you) but using an EditingDomain is even better.
>
> Tom
>
> Ovidio Mallo schrieb:
>> Hi Tom,
>>
>> first of all, thanks a lot for the immediate response and the good
>> hints!
>>
>> Indeed, EMF seems to have some great features which work out of the box.
>> Unfortunately, the editor I'm implementing is part of a large project
>> which can hardly be adapted with hindsight to use EMF.
>> However, based on your hint about the EditingDomain below, I had just
>> a look at the EditingDomainEObjectObservableValue class of EMF which
>> seems
>> to nicely integrate the dirty/undo/redo features into the databinding
>> world. Seems as if this could be a promising solution to our problem,
>> especially due to the undo/redo support which we might want to have in
>> a future version of our editor, too.
>>
>> Thanks again for your help!
>>
>> Best regards,
>> Ovidio
>>
>> Tom Schindl wrote:
>>> Well IMHO the best way is to record all changes happening to the model.
>>>
>>> Databinding doesn't provide such a thing, having said that the only
>>> thing that always comes to my my mind is EMF which provides a class
>>> called ChangeRecorder and attaching it to your master model object(s)
>>> would record all changes happening below :-) This provides another
>>> cool thing to you because you can rollback changes. If you would use
>>> an EditingDomain you'll even get undo/redo, great isn't it?
>>>
>>> Tom
>>>
>>> Ovidio Mallo schrieb:
>>>> Hi all,
>>>>
>>>> I'm implementing an editor for which I'm using databinding. In the
>>>> actual editor, I'm creating a DataBindingContext which I then pass to
>>>> several classes which create portions of the editor's UI, along with
>>>> the corresponding bindings to the model.
>>>> In the editor, I wanted to track the dirty state of the model where
>>>> my first thought was to simply attach value change listeners to all
>>>> model observables of all the bindings of the DataBindingContext.
>>>> However, in my editor, I'm using several master/detail constructs
>>>> which means that some of my model observables are
>>>> DetailObservableValues
>>>> whose value not only changes when the model indeed changes but also
>>>> when a different master is selected.
>>>> Therefore, my approach described above seems inappropriate as I should
>>>> not be listening on changes on the DetailObservableValues but on the
>>>> model observables they contain.
>>>>
>>>> Since tracking the dirty state of a model being edited should be a
>>>> fairly standard thing, I was just wondering whether anyone else has
>>>> implemented something similar using databinding which solves the
>>>> above problem.
>>>>
>>>> Thanks in advance for any feedback!
>>>>
>>>> Best regards,
>>>> Ovidio
>>>
>>>
>
>
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #328114 is a reply to message #327998] |
Wed, 14 May 2008 12:20 |
Eclipse User |
|
|
|
Originally posted by: tom.eiswind.de
Hi Ovidio,
I track changes with a global helper on the binding level.
public static void addDirtyListenersToContext(DataBindingContext
context, DirtyListener dirtyListener){
DirtyChangeListener listener = new DirtyChangeListener(dirtyListener);
IObservableList bindings = context.getBindings();
for (Object o : bindings) {
Binding b = (Binding) o;
b.getTarget().addChangeListener(listener);
}
}
If your bindings change you could listen to the bindings list and react.
Thomas
Ovidio Mallo schrieb:
> Hi again Tom,
>
> actually, I have only started looking at EMF about two weeks ago, but
> I'm very interested in it, especially in the databinding support
> provided by EMF (hence the post on the EMF newsgroup).
> However, right now, I'm merely using EMF for some toy project of mine,
> just to get started and to learn how EMF works.
> However, we are not using EMF for the project I was mentioning, so
> I cannot use the ChangeRecorder. Of course, I can also not use the
> EditingDomainEObjectObservableValue class as is but I think that the
> conceptual idea behind that class could fit our purposes, so I will
> probably try to go into that direction.
>
> Kind regards,
> Ovidio
>
> Tom Schindl wrote:
>> Hi,
>>
>> Yes that's what I talked about. I'm still not sure why you can't use
>> ChangeRecorder it looks as if you are using EMF (just saw a posting on
>> the EMF-newsgroup from you) but using an EditingDomain is even better.
>>
>> Tom
>>
>> Ovidio Mallo schrieb:
>>> Hi Tom,
>>>
>>> first of all, thanks a lot for the immediate response and the good
>>> hints!
>>>
>>> Indeed, EMF seems to have some great features which work out of the box.
>>> Unfortunately, the editor I'm implementing is part of a large project
>>> which can hardly be adapted with hindsight to use EMF.
>>> However, based on your hint about the EditingDomain below, I had just
>>> a look at the EditingDomainEObjectObservableValue class of EMF which
>>> seems
>>> to nicely integrate the dirty/undo/redo features into the databinding
>>> world. Seems as if this could be a promising solution to our problem,
>>> especially due to the undo/redo support which we might want to have in
>>> a future version of our editor, too.
>>>
>>> Thanks again for your help!
>>>
>>> Best regards,
>>> Ovidio
>>>
>>> Tom Schindl wrote:
>>>> Well IMHO the best way is to record all changes happening to the model.
>>>>
>>>> Databinding doesn't provide such a thing, having said that the only
>>>> thing that always comes to my my mind is EMF which provides a class
>>>> called ChangeRecorder and attaching it to your master model
>>>> object(s) would record all changes happening below :-) This provides
>>>> another cool thing to you because you can rollback changes. If you
>>>> would use an EditingDomain you'll even get undo/redo, great isn't it?
>>>>
>>>> Tom
>>>>
>>>> Ovidio Mallo schrieb:
>>>>> Hi all,
>>>>>
>>>>> I'm implementing an editor for which I'm using databinding. In the
>>>>> actual editor, I'm creating a DataBindingContext which I then pass to
>>>>> several classes which create portions of the editor's UI, along with
>>>>> the corresponding bindings to the model.
>>>>> In the editor, I wanted to track the dirty state of the model where
>>>>> my first thought was to simply attach value change listeners to all
>>>>> model observables of all the bindings of the DataBindingContext.
>>>>> However, in my editor, I'm using several master/detail constructs
>>>>> which means that some of my model observables are
>>>>> DetailObservableValues
>>>>> whose value not only changes when the model indeed changes but also
>>>>> when a different master is selected.
>>>>> Therefore, my approach described above seems inappropriate as I should
>>>>> not be listening on changes on the DetailObservableValues but on the
>>>>> model observables they contain.
>>>>>
>>>>> Since tracking the dirty state of a model being edited should be a
>>>>> fairly standard thing, I was just wondering whether anyone else has
>>>>> implemented something similar using databinding which solves the
>>>>> above problem.
>>>>>
>>>>> Thanks in advance for any feedback!
>>>>>
>>>>> Best regards,
>>>>> Ovidio
>>>>
>>>>
>>
>>
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #328122 is a reply to message #327988] |
Wed, 14 May 2008 15:24 |
Matthew Hall Messages: 368 Registered: July 2009 |
Senior Member |
|
|
Ovidio,
DetailObservableValue (and its List, Set and Map variants) works by
watching the master observable and replacing the detail observable each
time the master changes. That is, it disposes the old detail
observable, and requests a new detail observable from the
IObservableFactory passed to its constructor.
Thus, many of the observeDetailValue methods in BeansObservables,
PojoObservables, EMFObservables, etc are really just a convenient
shorthand for creating an observable factory, and passing it to
MasterDetailObservables.detailValue(). e.g.:
IObservableValue detailObservableValue = BeansObservables
.observeDetailValue(realm, masterObservable, "property",
propertyType);
is pretty much the same as:
IObservableFactory valueFactory = BeansObservables
.valueFactory(realm, "property");
IObservableValue detailObservableValue = MasterDetailObservables
.detailValue(masterObservable, valueFactory, propertyType);
You could observe changes to the detail observable while ignoring
changes to the master observable by wrapping valueFactory in a custom
factory:
class MyObservableFactory implements IObservableFactory {
IObservableFactory factory;
public MyObservableValueFactory(IObservableFactory factory) {
this.factory = factory;
}
public IObservable createObservable(final Object target) {
IObservable result = factory.createObservable(target);
result.addChangeListener(new IChangeListener() {
public void handleChange(ChangeEvent event) {
// Change occured in model -- mark editor as dirty
}
});
return result;
}
}
IObservableFactory valueFactory = BeansObservables
.valueFactory(realm, "property");
valueFactory = new MyObservableFactory(valueFactory);
IObservableValue detailObservableValue = MasterDetailObservables
.detailValue(masterObservable, valueFactory, propertyType);
Does this help?
Matthew
Ovidio Mallo wrote:
> Hi all,
>
> I'm implementing an editor for which I'm using databinding. In the
> actual editor, I'm creating a DataBindingContext which I then pass to
> several classes which create portions of the editor's UI, along with
> the corresponding bindings to the model.
> In the editor, I wanted to track the dirty state of the model where
> my first thought was to simply attach value change listeners to all
> model observables of all the bindings of the DataBindingContext.
> However, in my editor, I'm using several master/detail constructs
> which means that some of my model observables are DetailObservableValues
> whose value not only changes when the model indeed changes but also
> when a different master is selected.
> Therefore, my approach described above seems inappropriate as I should
> not be listening on changes on the DetailObservableValues but on the
> model observables they contain.
>
> Since tracking the dirty state of a model being edited should be a
> fairly standard thing, I was just wondering whether anyone else has
> implemented something similar using databinding which solves the
> above problem.
>
> Thanks in advance for any feedback!
>
> Best regards,
> Ovidio
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #328167 is a reply to message #328114] |
Fri, 16 May 2008 07:08 |
Eclipse User |
|
|
|
Originally posted by: malloovidio.bluewin.ch
Hi Thomas,
I think that the approach of simply listening to all target observables
of a DataBindingContext still has the problem that if you have
master/detail constructs in the GUI, the target observables will typically
change whenever you change your master even though your model has not
really changed. So, in those cases I think it is not OK to listen to the
target/model observables of the DataBindingContext as you would erroneously
mark your editor as being dirty even though nothing changed.
Regards,
Ovidio
Thomas wrote:
> Hi Ovidio,
>
> I track changes with a global helper on the binding level.
>
> public static void addDirtyListenersToContext(DataBindingContext
> context, DirtyListener dirtyListener){
> DirtyChangeListener listener = new
> DirtyChangeListener(dirtyListener);
> IObservableList bindings = context.getBindings();
> for (Object o : bindings) {
> Binding b = (Binding) o;
> b.getTarget().addChangeListener(listener);
> }
> }
>
> If your bindings change you could listen to the bindings list and react.
>
> Thomas
>
> Ovidio Mallo schrieb:
>> Hi again Tom,
>>
>> actually, I have only started looking at EMF about two weeks ago, but
>> I'm very interested in it, especially in the databinding support
>> provided by EMF (hence the post on the EMF newsgroup).
>> However, right now, I'm merely using EMF for some toy project of mine,
>> just to get started and to learn how EMF works.
>> However, we are not using EMF for the project I was mentioning, so
>> I cannot use the ChangeRecorder. Of course, I can also not use the
>> EditingDomainEObjectObservableValue class as is but I think that the
>> conceptual idea behind that class could fit our purposes, so I will
>> probably try to go into that direction.
>>
>> Kind regards,
>> Ovidio
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> Yes that's what I talked about. I'm still not sure why you can't use
>>> ChangeRecorder it looks as if you are using EMF (just saw a posting
>>> on the EMF-newsgroup from you) but using an EditingDomain is even
>>> better.
>>>
>>> Tom
>>>
>>> Ovidio Mallo schrieb:
>>>> Hi Tom,
>>>>
>>>> first of all, thanks a lot for the immediate response and the good
>>>> hints!
>>>>
>>>> Indeed, EMF seems to have some great features which work out of the
>>>> box.
>>>> Unfortunately, the editor I'm implementing is part of a large project
>>>> which can hardly be adapted with hindsight to use EMF.
>>>> However, based on your hint about the EditingDomain below, I had
>>>> just a look at the EditingDomainEObjectObservableValue class of EMF
>>>> which seems
>>>> to nicely integrate the dirty/undo/redo features into the databinding
>>>> world. Seems as if this could be a promising solution to our problem,
>>>> especially due to the undo/redo support which we might want to have in
>>>> a future version of our editor, too.
>>>>
>>>> Thanks again for your help!
>>>>
>>>> Best regards,
>>>> Ovidio
>>>>
>>>> Tom Schindl wrote:
>>>>> Well IMHO the best way is to record all changes happening to the
>>>>> model.
>>>>>
>>>>> Databinding doesn't provide such a thing, having said that the only
>>>>> thing that always comes to my my mind is EMF which provides a class
>>>>> called ChangeRecorder and attaching it to your master model
>>>>> object(s) would record all changes happening below :-) This
>>>>> provides another cool thing to you because you can rollback
>>>>> changes. If you would use an EditingDomain you'll even get
>>>>> undo/redo, great isn't it?
>>>>>
>>>>> Tom
>>>>>
>>>>> Ovidio Mallo schrieb:
>>>>>> Hi all,
>>>>>>
>>>>>> I'm implementing an editor for which I'm using databinding. In the
>>>>>> actual editor, I'm creating a DataBindingContext which I then pass to
>>>>>> several classes which create portions of the editor's UI, along with
>>>>>> the corresponding bindings to the model.
>>>>>> In the editor, I wanted to track the dirty state of the model where
>>>>>> my first thought was to simply attach value change listeners to all
>>>>>> model observables of all the bindings of the DataBindingContext.
>>>>>> However, in my editor, I'm using several master/detail constructs
>>>>>> which means that some of my model observables are
>>>>>> DetailObservableValues
>>>>>> whose value not only changes when the model indeed changes but also
>>>>>> when a different master is selected.
>>>>>> Therefore, my approach described above seems inappropriate as I
>>>>>> should
>>>>>> not be listening on changes on the DetailObservableValues but on the
>>>>>> model observables they contain.
>>>>>>
>>>>>> Since tracking the dirty state of a model being edited should be a
>>>>>> fairly standard thing, I was just wondering whether anyone else has
>>>>>> implemented something similar using databinding which solves the
>>>>>> above problem.
>>>>>>
>>>>>> Thanks in advance for any feedback!
>>>>>>
>>>>>> Best regards,
>>>>>> Ovidio
>>>>>
>>>>>
>>>
>>>
|
|
|
Re: [DataBinding] Tracking dirty model on DataBindingContext [message #328169 is a reply to message #328122] |
Fri, 16 May 2008 07:45 |
Eclipse User |
|
|
|
Originally posted by: malloovidio.bluewin.ch
Hi Matthew,
I think your idea is great. I have just implemented it for my
editor and it works like a charm :-).
Thanks a lot for your help and the clear explanation.
Regards,
Ovidio
Matthew Hall wrote:
> Ovidio,
>
> DetailObservableValue (and its List, Set and Map variants) works by
> watching the master observable and replacing the detail observable each
> time the master changes. That is, it disposes the old detail
> observable, and requests a new detail observable from the
> IObservableFactory passed to its constructor.
>
> Thus, many of the observeDetailValue methods in BeansObservables,
> PojoObservables, EMFObservables, etc are really just a convenient
> shorthand for creating an observable factory, and passing it to
> MasterDetailObservables.detailValue(). e.g.:
>
> IObservableValue detailObservableValue = BeansObservables
> .observeDetailValue(realm, masterObservable, "property",
> propertyType);
>
> is pretty much the same as:
>
> IObservableFactory valueFactory = BeansObservables
> .valueFactory(realm, "property");
> IObservableValue detailObservableValue = MasterDetailObservables
> .detailValue(masterObservable, valueFactory, propertyType);
>
> You could observe changes to the detail observable while ignoring
> changes to the master observable by wrapping valueFactory in a custom
> factory:
>
> class MyObservableFactory implements IObservableFactory {
> IObservableFactory factory;
> public MyObservableValueFactory(IObservableFactory factory) {
> this.factory = factory;
> }
> public IObservable createObservable(final Object target) {
> IObservable result = factory.createObservable(target);
> result.addChangeListener(new IChangeListener() {
> public void handleChange(ChangeEvent event) {
> // Change occured in model -- mark editor as dirty
> }
> });
> return result;
> }
> }
>
> IObservableFactory valueFactory = BeansObservables
> .valueFactory(realm, "property");
> valueFactory = new MyObservableFactory(valueFactory);
> IObservableValue detailObservableValue = MasterDetailObservables
> .detailValue(masterObservable, valueFactory, propertyType);
>
> Does this help?
>
> Matthew
>
> Ovidio Mallo wrote:
>> Hi all,
>>
>> I'm implementing an editor for which I'm using databinding. In the
>> actual editor, I'm creating a DataBindingContext which I then pass to
>> several classes which create portions of the editor's UI, along with
>> the corresponding bindings to the model.
>> In the editor, I wanted to track the dirty state of the model where
>> my first thought was to simply attach value change listeners to all
>> model observables of all the bindings of the DataBindingContext.
>> However, in my editor, I'm using several master/detail constructs
>> which means that some of my model observables are DetailObservableValues
>> whose value not only changes when the model indeed changes but also
>> when a different master is selected.
>> Therefore, my approach described above seems inappropriate as I should
>> not be listening on changes on the DetailObservableValues but on the
>> model observables they contain.
>>
>> Since tracking the dirty state of a model being edited should be a
>> fairly standard thing, I was just wondering whether anyone else has
>> implemented something similar using databinding which solves the
>> above problem.
>>
>> Thanks in advance for any feedback!
>>
>> Best regards,
>> Ovidio
|
|
|
Goto Forum:
Current Time: Sun Dec 22 06:11:44 GMT 2024
Powered by FUDForum. Page generated in 0.05770 seconds
|