Home » Eclipse Projects » Eclipse Platform » [DataBinding] Best pratice to observe instance model (Bean, EMF..) which change
[DataBinding] Best pratice to observe instance model (Bean, EMF..) which change [message #334695] |
Wed, 25 February 2009 09:03 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Angelo ZERR![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=azerr%40redhat.com) Messages: 122 Registered: July 2009 |
Senior Member |
|
|
Hi,
I'm working on JFace DOM-SSE Databinding which is implementation of JFace
Databinding to bind DOM-SSE (IDocument, IDOMNode...). DOM-SSE is w3c DOM
which can be getted from a WST StructuredTextEditor (ex : Editor XML from
WST manage DOM-SSE).
So with this implementation we could bind DOM Node comming from the XML
content of the editor with SWT UI widgets. Today I can bind attribute
title
<diagram title="bla bla bla" >
with SWT Text widget.
To manage that we must observe the change of the IDOMElement diagram and
add INodeAdapter to the IDOMElement diagram
IDOMNode#addAdapter(INodeAdapter adapter).
XML content can be typed into the text editor, so we have 2 problems to
bind attribute title with SWT Text :
1. diagram element (IDOMElement) can be NOT existed. (the user type the
XML <dia )
2. instance of diagram element (IDOMElement) change every time (ex : you
type element diagram, it create IDOMElement, you remove it and you re-type
it, it create new instance of IDOMElement).
So my question is which is best pratice to manage this case? Because with
another JFace Databinding we have the same problematic. For instance it
exist EMF2DOMSSERenderer which is enable to bind DOM-SSE with EMF
instance. I think it should be very cool to use EMF Databinding to bind
instance EMF which is populated with DOM-SSE. But the problem is the same,
because EMF instance can change.
To manage this case, I observe not directly the IDOMNode (because he can
be not existed and the instance can be changed) but I observe an
implementation of of org.eclipse.core.databinding.observable.IObserving
wich returns the diagram element :
DOMSSEObservables.observeAttrValue(realm, modelNotifier,
new IObserving() {
public Object getObserved() {
return document.getDocumentElement();
}
}, "title");
So with that I can manage change of instance diagram element and the none
existing of diagram element.
DOMSSEObservables#observeAttrValue wait IDOMModelNotifier modelNotifier
(this name is poor) which is kind of container which is enable to
re-attach the Adapter of old IDOMElement to the new IDOMElement created.
What do you think about this idea?
Perhaps JFace Core Databinding provide something (Realm?) to do that.
Perhaps all JFace Databinding implementation should manage the idea with
IObserving?
Regards Angelo
|
|
|
Re: [DataBinding] Best pratice to observe instance model (Bean, EMF..) which change [message #334740 is a reply to message #334695] |
Wed, 25 February 2009 19:25 ![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 |
|
|
Angelo,
I'm having a hard time understanding your question. Could you provide a
snippet to demonstrate what you're trying to do?
Matthew
Angelo wrote:
> Hi,
>
> I'm working on JFace DOM-SSE Databinding which is implementation of
> JFace Databinding to bind DOM-SSE (IDocument, IDOMNode...). DOM-SSE is
> w3c DOM which can be getted from a WST StructuredTextEditor (ex : Editor
> XML from WST manage DOM-SSE).
>
> So with this implementation we could bind DOM Node comming from the XML
> content of the editor with SWT UI widgets. Today I can bind attribute title
> <diagram title="bla bla bla" >
>
> with SWT Text widget.
>
> To manage that we must observe the change of the IDOMElement diagram and
> add INodeAdapter to the IDOMElement diagram
> IDOMNode#addAdapter(INodeAdapter adapter).
>
> XML content can be typed into the text editor, so we have 2 problems to
> bind attribute title with SWT Text :
> 1. diagram element (IDOMElement) can be NOT existed. (the user type the
> XML <dia )
>
> 2. instance of diagram element (IDOMElement) change every time (ex : you
> type element diagram, it create IDOMElement, you remove it and you
> re-type it, it create new instance of IDOMElement).
>
> So my question is which is best pratice to manage this case? Because
> with another JFace Databinding we have the same problematic. For
> instance it exist EMF2DOMSSERenderer which is enable to bind DOM-SSE
> with EMF instance. I think it should be very cool to use EMF Databinding
> to bind instance EMF which is populated with DOM-SSE. But the problem is
> the same, because EMF instance can change.
>
> To manage this case, I observe not directly the IDOMNode (because he can
> be not existed and the instance can be changed) but I observe an
> implementation of of org.eclipse.core.databinding.observable.IObserving
> wich returns the diagram element :
> DOMSSEObservables.observeAttrValue(realm, modelNotifier, new
> IObserving() {
> public Object getObserved() {
> return document.getDocumentElement();
> }
> }, "title");
>
> So with that I can manage change of instance diagram element and the
> none existing of diagram element.
>
> DOMSSEObservables#observeAttrValue wait IDOMModelNotifier modelNotifier
> (this name is poor) which is kind of container which is enable to
> re-attach the Adapter of old IDOMElement to the new IDOMElement created.
>
> What do you think about this idea?
> Perhaps JFace Core Databinding provide something (Realm?) to do that.
>
> Perhaps all JFace Databinding implementation should manage the idea with
> IObserving?
> Regards Angelo
|
|
|
Re: [DataBinding] Best pratice to observe instance model (Bean, EMF..) which change [message #334752 is a reply to message #334740] |
Thu, 26 February 2009 07:00 ![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) |
Angelo ZERR![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=azerr%40redhat.com) Messages: 122 Registered: July 2009 |
Senior Member |
|
|
Hi Matthew,
I have a sample with multi page editor called Shapes Editor - DOM SSE
which is composed by 2 pages :
* page 1 =>
http://blog.developpez.com/media/domsseshape_diagram_sourcep age.png
this page contains WST StructuredTextEditor which display the XML
content
<diagram title="My Shape Diagram" ...
* page 2 =>
http://blog.developpez.com/media/domsseshape_diagram_overvie wpage.png
this page display SWT UI which manage the XML content.
The page 2 contains SWT Text which is bounded to attribute title of root
(diagram) of the DOM. It's the snippet. Here the code to manage this
binding :
/----------------------------------------------------------- ------/
Text titleText = ....
Realm realm = SWTObservables.getRealm(titleText.getDisplay());
// SWT
IObservableValue observableValue1 = SWTObservables.observeText(titleText,
SWT.Modify)
// DOM-SSE
IDOMModel model = ...// SSE DOM Model getted from the IFile (XML diagram)
org.w3c.dom.Document document = model.getDocument(); // DOM-SSE managed by
DOM model SSE.
IModelNotifier modelNotifier = new DOMModelNotifier(model);
IObservableValue observableValue2 =
DOMSSEObservables.observeAttrValue(realm, modelNotifier, new
IObserving() {
public Object getObserved() {
return document.getDocumentElement();
}
}, "title");
// Binding
DataBindingContext bindingContext = new DataBindingContext(realm);
bindingContext.bindValue(observableValue1 , observableValue2 , null, null);
/----------------------------------------------------------- ------/
My first idea was to use JFace DOM Databinding
(http://wiki.eclipse.org/JFace_Data_Binding/DOM) to bind SWT Text with
attribute value like this :
Element diagram = document.getDocumentElement();
IObservableValue observableValue2 = DOMObservables.observeAttrValue(realm,
diagram, "title");
The problem is that :
* XML root element cannot be exist (diagram is null).
* the binding works the first thing (when you change attribute title into
the XML editor, the instance IDOMElement of diagram fire event (SWT UI is
updated)) because we have add it an INodeAdapter (which fire JFace DB
event) to this instance. But if you remove the XML element diagram and you
re-type it, it create new instance of IDOMElement. So the new instance is
not observed and the old instance is always observed. My works is to
re-attach old instance with new instance.
Matthew, do you understood the problem? If you wish, I could send you my
work to see it in action?
An example with Beans Binding is :
/----------------------------------------------------------- ------/
Text titleText = ....
Realm realm = SWTObservables.getRealm(titleText.getDisplay());
// SWT
IObservableValue observableValue1 = SWTObservables.observeText(titleText,
SWT.Modify)
// Beans
Person person = new Person();
IObservableValue observableValue2 = BeansObservable(realm, person,
"name");
// Binding
DataBindingContext bindingContext = new DataBindingContext(realm);
bindingContext.bindValue(observableValue1 , observableValue2 , null, null);
// Here binding works.
person = new Person();
// Here binding is broken, because instance has changed
/----------------------------------------------------------- ------/
Thank's for your help.
Regards Angelo
|
|
|
Re: [DataBinding] Best pratice to observe instance model (Bean, EMF..) which change [message #334766 is a reply to message #334752] |
Thu, 26 February 2009 16:08 ![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 |
|
|
I'm very unfamiliar with DOM-SSE as you describe it but your beans
example is helpful. If your model can be completely swapped out then
you need to put your model in a WritableValue and all the observables
that you bind should be detail observables of that WritableValue.
Taking your beans binding example:
Text titleText = ....
Realm realm = SWTObservables.getRealm(titleText.getDisplay());
// SWT
IObservableValue observableValue1 =
SWTObservables.observeText(titleText, SWT.Modify);
// Beans
IObservableValue person =
new WritableValue(realm, new Person(), Person.class);
IObservableValue observableValue2 =
BeansObservables.observeDetailValue(person, "name");
// Binding
DataBindingContext bindingContext = new DataBindingContext(realm);
bindingContext.bindValue(observableValue1 , observableValue2 , null, null);
// Here binding works.
person.setValue(new Person());
// Here binding has switched over to the new Person instance
To transfer this over to your DOM observables, I think you need to have
a core WritableValue that contains the core document or element that as
you said may be null. From there you can observe everthing as detail
values of the WritableValue, and changes to that core model should be
reflected properly in your bindings.
Hope this helps,
Matthew
Angelo wrote:
> Hi Matthew,
>
> I have a sample with multi page editor called Shapes Editor - DOM SSE
> which is composed by 2 pages :
> * page 1 =>
> http://blog.developpez.com/media/domsseshape_diagram_sourcep age.png
> this page contains WST StructuredTextEditor which display the XML
> content <diagram title="My Shape Diagram" ...
>
> * page 2 =>
> http://blog.developpez.com/media/domsseshape_diagram_overvie wpage.png
> this page display SWT UI which manage the XML content.
> The page 2 contains SWT Text which is bounded to attribute title of root
> (diagram) of the DOM. It's the snippet. Here the code to manage this
> binding :
> /----------------------------------------------------------- ------/
> Text titleText = ....
>
> Realm realm = SWTObservables.getRealm(titleText.getDisplay());
>
> // SWT
> IObservableValue observableValue1 =
> SWTObservables.observeText(titleText, SWT.Modify)
>
> // DOM-SSE
> IDOMModel model = ...// SSE DOM Model getted from the IFile (XML diagram)
> org.w3c.dom.Document document = model.getDocument(); // DOM-SSE managed
> by DOM model SSE.
>
> IModelNotifier modelNotifier = new DOMModelNotifier(model);
>
> IObservableValue observableValue2 =
> DOMSSEObservables.observeAttrValue(realm, modelNotifier, new
> IObserving() {
> public Object getObserved() {
> return document.getDocumentElement();
> }
> }, "title");
>
> // Binding
> DataBindingContext bindingContext = new DataBindingContext(realm);
> bindingContext.bindValue(observableValue1 , observableValue2 , null, null);
> /----------------------------------------------------------- ------/
>
> My first idea was to use JFace DOM Databinding
> (http://wiki.eclipse.org/JFace_Data_Binding/DOM) to bind SWT Text with
> attribute value like this :
> Element diagram = document.getDocumentElement();
> IObservableValue observableValue2 =
> DOMObservables.observeAttrValue(realm, diagram, "title");
>
> The problem is that :
> * XML root element cannot be exist (diagram is null).
> * the binding works the first thing (when you change attribute title
> into the XML editor, the instance IDOMElement of diagram fire event (SWT
> UI is updated)) because we have add it an INodeAdapter (which fire JFace
> DB event) to this instance. But if you remove the XML element diagram
> and you re-type it, it create new instance of IDOMElement. So the new
> instance is not observed and the old instance is always observed. My
> works is to re-attach old instance with new instance.
>
> Matthew, do you understood the problem? If you wish, I could send you my
> work to see it in action?
>
> An example with Beans Binding is :
> /----------------------------------------------------------- ------/
> Text titleText = ....
>
> Realm realm = SWTObservables.getRealm(titleText.getDisplay());
>
> // SWT
> IObservableValue observableValue1 =
> SWTObservables.observeText(titleText, SWT.Modify)
>
> // Beans
> Person person = new Person();
> IObservableValue observableValue2 = BeansObservable(realm, person,
> "name");
>
> // Binding
> DataBindingContext bindingContext = new DataBindingContext(realm);
> bindingContext.bindValue(observableValue1 , observableValue2 , null, null);
>
> // Here binding works.
> person = new Person();
> // Here binding is broken, because instance has changed
>
> /----------------------------------------------------------- ------/
>
> Thank's for your help.
>
> Regards Angelo
>
|
|
| |
Goto Forum:
Current Time: Fri Aug 16 18:28:04 GMT 2024
Powered by FUDForum. Page generated in 0.03404 seconds
|