Jump to: navigation, search

Difference between revisions of "JFace Data Binding/Rhino"

m (RhinoObservables)
m (RhinoObservables)
Line 26: Line 26:
 
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.<b>RhinoObservables</b>.
 
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.<b>RhinoObservables</b>.
  
 +
Here the code of the scriptable object Person binding wich use RhinoObservables :
  
 
<pre>
 
<pre>
Line 43: Line 44:
  
 
 
// Get UI observable  
+
// 3. Get UI observable  
 
IObservableValue uiObservable = SWTObservables.observeText(textWidget, SWT.Modify);
 
IObservableValue uiObservable = SWTObservables.observeText(textWidget, SWT.Modify);
 
 
// Get Rhino observable
+
// 4. Get Rhino observable
 
IObservableValue rhinoObservable = RhinoObservables.observeValue(global, "person", "name");
 
IObservableValue rhinoObservable = RhinoObservables.observeValue(global, "person", "name");
 
 
// Bind JS Person#name with SWT Text
+
// 5. Bind JS Person#name with SWT Text
 
DataBindingContext bindingContext = new DataBindingContext();
 
DataBindingContext bindingContext = new DataBindingContext();
 
bindingContext.bindValue(uiObservable, rhinoObservable, null, null);
 
bindingContext.bindValue(uiObservable, rhinoObservable, null, null);

Revision as of 10:01, 18 March 2009

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.

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?

E4 project

XWT