Difference between revisions of "JFace Data Binding/Rhino"

From Eclipsepedia

Jump to: navigation, search
m (Why JFace Rhino Databinding?)
m (Why JFace Rhino Databinding?)
Line 59: Line 59:
 
== Why JFace Rhino Databinding? ==
 
== Why JFace Rhino Databinding? ==
  
 +
You can
 +
 +
=== Eclipse E4/Declarative UI ===
 +
 
One [http://www.eclipse.org/e4/ Eclipse E4] target is to have declarative UI capability.  
 
One [http://www.eclipse.org/e4/ Eclipse E4] target is to have declarative UI capability.  
 
[http://wiki.eclipse.org/E4/DeclarativeUI/XWT XWT] is a proposition about declarative UI. If you want display SWT Text, you can write this XML content :  
 
[http://wiki.eclipse.org/E4/DeclarativeUI/XWT XWT] is a proposition about declarative UI. If you want display SWT Text, you can write this XML content :  
Line 72: Line 76:
 
</source>
 
</source>
  
It support [http://wiki.eclipse.org/E4/DeclarativeUI/XWT#5._Data_Binding Beans bindind] with declarative mean. For instance if we bind the text attribute of Text to a property “Name” of a Bean Person, here is the data binding expression:  
+
=== XWT/Bean binding ===
 +
 
 +
XWT support [http://wiki.eclipse.org/E4/DeclarativeUI/XWT#5._Data_Binding Beans bindind] with declarative mean. For instance if we bind the text attribute of Text to a property “Name” of a Bean Person, here is the data binding expression:  
  
 
<source lang="xml">
 
<source lang="xml">
Line 79: Line 85:
 
...
 
...
 
</source>
 
</source>
 +
 +
 +
=== XWT/Javascript ===
  
 
XWT has intention to support Javascript (see bug).
 
XWT has intention to support Javascript (see bug).

Revision as of 10:40, 18 March 2009

Contents

Target

The goal of JFace Data Binding/Rhino is to support bindings to Rhino Javascript Scriptable Object. See (for the moment) TK-UI SVN but we are discussing with the Eclipse Team on where it can be made available.

JFace Data Binding/Rhino need Rhino 1.6.6, because to detect the change of the property of Javascript Object (thank's to Simon Kaegi), the Rhino observable value use getter/setter ScriptableObject#setGetterOrSetter(....) to fire JFace Databinding event.

Use-case

Take a simple example. Imagine you have this script :

function Person(name) {
  this.name = name
};

var person = new Person('Simon')

And you wish bind the property 'name' of the scriptable object person with SWT Text.

Jface-db-rhino-person.png

On load form page, SWT Text has 'Simon' value. When user type 'Boris' into SWT Text, it update property 'name' of the scriptable object person with 'Boris' value.

RhinoObservables

Like another JFace Databinding implementations (SWT, Beans, Pojo...), Rhino bindings project give you several JFace IObservableValue and IObservableList Rhino implementations accessible via the IObservable factory org.eclipse.core.databinding.rhino.RhinoObservables.

Here the code of the scriptable object Person binding wich use RhinoObservables :

// 1. Prepare script to excecute
String script = "function Person(name) {this.name = name}; " +
		" var person = new Person('Simon')";
		
// 2. Load Rhino script by using ImporterTopLevel  
ScriptableObject global = null;
try {
  Context cx = ContextFactory.getGlobal().enterContext();
  global = new ImporterTopLevel(cx);
  cx.evaluateString(global, script, null, 0, null);
} finally {
  Context.exit();
}

		
// 3. Get UI observable 
IObservableValue uiObservable = SWTObservables.observeText(textWidget, SWT.Modify);
				
// 4. Get Rhino observable
IObservableValue rhinoObservable = RhinoObservables.observeValue(global, "person", "name");
			
// 5. Bind JS Person#name with SWT Text
DataBindingContext bindingContext = new DataBindingContext();
bindingContext.bindValue(uiObservable, rhinoObservable, null, null);

Why JFace Rhino Databinding?

You can

Eclipse E4/Declarative UI

One Eclipse E4 target is to have declarative UI capability. XWT is a proposition about declarative UI. If you want display SWT Text, you can write this XML content :

<Shell xmlns="http://www.eclipse.org/xwt/presentation"
    xmlns:x="http://www.eclipse.org/xwt">
    <Shell.layout>
       <FillLayout/>
    </Shell.layout>
    <Text />
</Shell>

XWT/Bean binding

XWT support Beans bindind with declarative mean. For instance if we bind the text attribute of Text to a property “Name” of a Bean Person, here is the data binding expression:

...
<Text text="{binding path=Name}"/>
...


XWT/Javascript

XWT has intention to support Javascript (see bug).