Target of <b>JFace Data Binding/SSE</b> is to support bindings with SSE nodes (DOM, CSS...). Today sources of this project are not available because we are discussing with Eclipse Team to see where we can put this project. This project can be used for instance when you wish manage XML content with an UI editor like :

+

The goal of <b>JFace Data Binding/SSE</b> is to support bindings to SSE nodes (DOM, CSS...). See (for the moment) [http://tk-ui.svn.sourceforge.net/svnroot/tk-ui/jface-databinding-sse/ TK-UI SVN] but we are discussing with the Eclipse Team on where it can be made available.

+

+

This project can be used for instance when you wish to edit an XML content with an UI editor like :

<ul>

<ul>

<li>[http://www.eclipse.org/pde/ PDE] which manage plugin.xml with an UI (Extensions page).</li>

<li>[http://www.eclipse.org/pde/ PDE] which manage plugin.xml with an UI (Extensions page).</li>

Line 9:

Line 11:

</ul>

</ul>

−

+

In the JFace Data Binding/SSE sample, you can find a Shapes Editor which manages some XML content. Here you can see that SWT Text title UI is bound to the title attribute of the diagram element :

−

Into JFace Data Binding/SSE sample you can find a Shapes Editor which manage XML content. Here you can see that SWT Text title UI is bounded with title attribute of diagram element :

+

[[Image:ShapesDOMSSEEditor.png]]

[[Image:ShapesDOMSSEEditor.png]]

Line 16:

Line 17:

== JFace DOM-SSE Databinding ==

== JFace DOM-SSE Databinding ==

−

Before explaining features of <b>JFace DOM-SSE Databinding</b>, if you don't know DOM-SSE, I adwice you to read the section [[#What is DOM-SSE?]]

+

Before explaining <b>JFace DOM-SSE Databinding</b>, if you don't know DOM-SSE, I advice you to read the section [[#What is DOM-SSE?]]

=== Features/Node instances observed ===

=== Features/Node instances observed ===

−

To explain JFace DOM-SSE Databinding features, take the sample Shapes DOM-SSE Editor, which bind attribute title of root element of the DOM Document with SWT Text title. The observed Node is root element :

+

To explain JFace DOM-SSE Databinding features, take the sample Shapes DOM-SSE Editor, which binds the attribute title of the root element of the DOM Document with an SWT Text widget (title). The observed Node is the root element :

<pre>

<pre>

Line 26:

Line 27:

</pre>

</pre>

−

This node change each time, as soon as user change content of XML editor (remove the diagram element, recreate it...).

+

This node instance may changes at any time, when removing the diagram element and then recreating it while directly editing the XML source.

−

We start with the XML content

+

We start with the XML content

−

<pre>

+

<source lang="xml">

−

<diagram title="My shapes diagram"

+

<diagram title="My shapes diagram"

−

</pre>

+

</source>

−

You can see, that XML is not well formatted because diagram element is not closed.

+

You can see, that XML is not well formed because diagram element is not closed.

−

WST is enable to built W3c DOM Document even if XML content is not well formatted.

+

WST is able to build a W3C DOM Document even if XML content is not well formed.

−

==== Bind with existing observed Node ====

+

==== Bind with an existing observed Node ====

−

When you open the XML shape file into Shapes DOM-SSE Editor, you can see XML editor is filled with XML content and SWT Text UI has "My shapes diagram" value :

+

When you open the XML shape file into Shapes DOM-SSE Editor, you can see XML editor is filled with XML content and SWT Text UI has "My shapes diagram" value :

[[Image:Jface-db-sse-shapes-editor_1.png]]

[[Image:Jface-db-sse-shapes-editor_1.png]]

Line 47:

Line 48:

Observed Node = instance1.

Observed Node = instance1.

−

==== Bind with null observed Node ====

+

==== Bind with null observed Node ====

Remove the XML content of the XML editor, the XML editor is blank and SWT Text UI has blank value :

Remove the XML content of the XML editor, the XML editor is blank and SWT Text UI has blank value :

Line 61:

Line 62:

Re-type the XML content into XML editor :

Re-type the XML content into XML editor :

−

<pre>

+

<source lang="xml">

−

<diagram title="My shapes diagram"

+

<diagram title="My shapes diagram"

−

</pre>

+

</source>

−

Diagram element is created and append it to the DOM. SWT Text UI has again "My shapes diagram" value.

+

Diagram element is created and append it to the DOM. SWT Text UI has again "My shapes diagram" value.

Observed Node = instance3.

Observed Node = instance3.

Line 71:

Line 72:

==== Lazy observed Node====

==== Lazy observed Node====

−

Imagine you have blank XML content into XML editor and that user type "M", into SWT Text title. With standard databinding, XML editor will not updated because observed Node doesn't exist. With JFace DOM-SSE Databinding you can manage that.

+

Imagine you have blank XML content into XML editor and that user type "M", into SWT Text title. With standard databinding, XML editor will not updated because observed Node doesn't exist. With JFace DOM-SSE Databinding you can manage that.

DOM Node change somewhere int he code, what is it? If DOM Document implements DOM level2, you can observe the change of DOM by adding DOM EventListener and rebind person element observed, if Node instance has changed :

+

DOM Node change somewhere in the code, what is it? If DOM Document implements DOM level2, you can observe the change of DOM by adding DOM EventListener and rebind person element observed, if Node instance has changed :

<pre>((EventTarget) document).addEventListener(

<pre>((EventTarget) document).addEventListener(

Line 295:

Line 297:

<ul>

<ul>

−

<li>An writable value which observe Node instance which can be change. This is managed with [#ObservedValue/LazyObservedValue]</li>

+

<li>An writable value which observe Node instance which can be change. This is managed with [[#ObservedValue/LazyObservedValue]]</li>

−

<li>A listener which re-attach binding by updating new instance Node by calling IObservableValue#setValue(Object value) of the writable value. This is managed with [#IInstanceObservedContainer].</li>

+

<li>A listener which re-attach binding by updating new instance Node by calling IObservableValue#setValue(Object value) of the writable value. This is managed with [[#IInstanceObservedContainer]].</li>

</ul>

</ul>

Line 303:

Line 305:

<ul>

<ul>

−

<li>Manage a list of observed instance Node. Into JFace DOM-SSE Databinding it is </li>

In the JFace Data Binding/SSE sample, you can find a Shapes Editor which manages some XML content. Here you can see that SWT Text title UI is bound to the title attribute of the diagram element :

JFace DOM-SSE Databinding

Before explaining JFace DOM-SSE Databinding, if you don't know DOM-SSE, I advice you to read the section #What is DOM-SSE?

Features/Node instances observed

To explain JFace DOM-SSE Databinding features, take the sample Shapes DOM-SSE Editor, which binds the attribute title of the root element of the DOM Document with an SWT Text widget (title). The observed Node is the root element :

Element diagram = document.getDocumentElement();

This node instance may changes at any time, when removing the diagram element and then recreating it while directly editing the XML source.

We start with the XML content

<diagramtitle="My shapes diagram"

You can see, that XML is not well formed because diagram element is not closed.
WST is able to build a W3C DOM Document even if XML content is not well formed.

Bind with an existing observed Node

When you open the XML shape file into Shapes DOM-SSE Editor, you can see XML editor is filled with XML content and SWT Text UI has "My shapes diagram" value :

In this case, diagram element instance is observed.

Observed Node = instance1.

Bind with null observed Node

Remove the XML content of the XML editor, the XML editor is blank and SWT Text UI has blank value :

In this case, root element is null and it's this null value wich is observed.

Observed Node = instance2.

Re-bind observed Node

Re-type the XML content into XML editor :

<diagramtitle="My shapes diagram"

Diagram element is created and append it to the DOM. SWT Text UI has again "My shapes diagram" value.

Observed Node = instance3.

Lazy observed Node

Imagine you have blank XML content into XML editor and that user type "M", into SWT Text title. With standard databinding, XML editor will not updated because observed Node doesn't exist. With JFace DOM-SSE Databinding you can manage that.
It's called Lazy Observed Node.

Master detail/ObservableValue

Beans context

I re-explain the problematic with Bean context which is the same for DOM Node.
We wish bind "name" property of Person Bean instance with SWT Text title.
How manage the re-binding when person instance change? Here Matthew Hall answer :

DOM context

We can translate this problematic with DOM Node which observe attribute name of person element with JFace DOM Databinding:

<people><personname="Matthew"/></people>

DOM context/Simple IObservableValue

But before translating the problem of Node instance change, take a sample with DOM binding. Imagine you want display into Textarea area the XML content and you want bind the attribute name with an SWT Text :

When you change SWT Text, it update attribute value, and when you update attribute value into Textarea which display XML content, it update SWt Text. Binding works well.

BUT, if you remove person element :

And you re-type person element into Textarea, attribute binding is broken. Why?
Because person observed Node personElement instance has changed. The following section explain how manage this problem with master detail concept.

DOM context/Master detail

Matthew solution can be translated with DOM context by using master detail :

DOM Node change somewhere in the code, what is it? If DOM Document implements DOM level2, you can observe the change of DOM by adding DOM EventListener and rebind person element observed, if Node instance has changed :

A listener which re-attach binding by updating new instance Node by calling IObservableValue#setValue(Object value) of the writable value. This is managed with #IInstanceObservedContainer.

More we have seen sample with DOM which implements DOM level2 (EventTarget), but DOM-SSE doesn't implements DOM level2, so
to JFace DOM-SSE Databinding provides a container instance concept to manage any container (DOM level2, DOM-SSE, EMF...).

Manage a list of observed instance Node.

IObserving/ILazyObserving

Observed Node instance change every time and can be null. So when IObservableValue must be created to observe the Node, Node cannot be use directly because it can be null on start and instance change evry time. The first concept is to use org.eclipse.core.databinding.IObserving interface to observe Node :

IInstanceObservedContainer

JFace DOM-SSE Databinding manage the rebinding of observed Node instance if need.
To manage that, the first concept is to have a container of observed instance which is enable to manage the problematic of change observed instance. JFace DOM-SSE Databinding provides the org.eclipse.ufacekit.core.databinding.instance.IInstanceObservedContainer interface :

observeInstances : this method loop for each #IObserving/ILazyObserving which was registered and check if instance observed Node IObserving#getObserved() has change. If it has change, it call list of #IInstanceObservedChanged linked to the IObserving. Into DOM-SSE context, this method is called as soon as DOM change.

dispose : this method unregister the observing registered and remove listener if need. Into DOM-SSE context, it's very IMPORTANT to call it when EditorPart is closed, to remove listener.

IInstanceObservedChanged

IInstanceObservedChanged is event listener which is called by a IInstanceObservedContainer implementation, as soon as Node instance change.

AbstractInstanceObservedContainer

IInstanceObservedContainer can be implemented with several way to manage Bean, EMF, DOM instance. The class base is org.eclipse.ufacekit.core.databinding.instance.AbstractInstanceObservedContainer which implements the 3 #IInstanceObservedContainer methods.

StructuredModelInstanceObservedContainer

StructuredModelInstanceObservedContainer is abstract class container for SSE model. It extends AbstractInstanceObservedContainer and manage SSE Model. The constrctor of this class wait org.eclipse.wst.sse.core.internal.provisional.IStructuredModel instance. Into this constructor a org.eclipse.wst.sse.core.internal.provisional.IModelStateListener is added to the SSE model to call IInstanceObservedContainer#observeInstances() each time SSE model change :

Why JFace DOM-SSE Databinding?

This project provides the capability to manage binding with DOM-SSE nodes (IDOMNode).
It is based on JFace DOM Databinding. Why having JFace DOM-SSE Databinding although JFace DOM Databinding manage DOM bindings.? The answer is :

Instance nodes problem. JFace DOM Databinding provides several observable to observe a Node instance. If Node instance change, binding is broken. Into XML editor context, the XML is typed by user, DOM is every time broken. Node instances change every time, so it's difficult to observe a Node instance, because instance change every time. Goal of JFace DOM-SSE Databinding is enable to observe Nodes. If Node is removed (user remove the XML content) and recreated (user retype XML content), JFace DOM-SSE Databinding is enable to recreate observable to observe the new Node instance.

What is DOM-SSE?

DOM-SSE is W3c DOM Document comming from IFile or TextEditor. XML Editor from WTP which is based on StructuredTextEditor manage internally DOM-SSE. The DOM-SSE is updated as soon as user type XML content. DOM-SSE is getted from WST IDOMModel like this :

IDOMModel#addModelStateListener(IModelStateListener listener) : as soon as DOM-SSE is updated (add/remove/update any Nodes), you can use IModelStateListener#modelChanged(IStructuredModel model) to detect that :