Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JFace Data Binding/PojoBindable"

(New page: {{JFace Data Binding}} == Target == Work is underway to support binding with Pojo by using BeansObservable WITHOUT coding firePropertyChange (into setter method)/addPropertyChangeListene...)
 
(Bindable Java Agent)
Line 74: Line 74:
 
  *  
 
  *  
 
  */
 
  */
public class PojoPerson {
+
public class PojoPerson implements org.eclipse.core.databinding.pojo.bindable.BindableAware {
  
private PropertyChangeSupport _bindable_propertyChangeSupport = null;
+
private transient PropertyChangeSupport _bindable_propertyChangeSupport = null;
  
 
String name = "HelloWorld";
 
String name = "HelloWorld";

Revision as of 13:29, 29 March 2010

JFace Data Binding
Home
How to Contribute
FAQ
Snippets
Concepts
Binding
Converter
Observable
Realm

Target

Work is underway to support binding with Pojo by using BeansObservable WITHOUT coding firePropertyChange (into setter method)/addPropertyChangeListener/removePropertyChangeListener. See (for the moment) Bug 307417- you can find 4 plug-in projects that provide Pojo Bindable :

  • org.eclipse.core.databinding.pojo.bindable : Pojo Bindable source.
  • org.eclipse.core.examples.databinding.pojo.bindable : Pojo Bindable samples.
  • org.eclipse.core.tests.databinding.beans.bindable : Pojo Bindable tests.
  • com.springsource.org.objectweb.asm : ASM bundle "org.objectweb.asm" version of 3.2.0 getted from SpringSource Enterprise Bundle Repository.

Sample

You can find this sample on org.eclipse.core.examples.databinding.pojo.bindable project.

PojoPerson

package org.eclipse.core.examples.databinding.pojo.bindable.model;
 
/**
 * POJO model Person.
 *
 */
public class PojoPerson {
 
	String name = "HelloWorld";
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		this.name = name;
	}
}

HelloWorldWithBeansObservablesWithBindableAgent

PojoPerson person = new PojoPerson();
...
bindingContext.bindValue(SWTObservables.observeText(name,
SWT.Modify), BeansObservables.observeValue(person, "name"));

Use BeansObservables althought it's a Pojo.


Bindable Java Agent

Lanch the program with Bindable JavaAgent filled into JVM Parameters :

-javaagent:lib/org.eclipse.core.databinding.pojo.bindable_1.0.0.jar -Dbindable.packages=org.eclipse.core.examples.databinding.pojo.bindable.model

The Bindable Java Agent transform the PojoPerson class with this code :


package org.eclipse.core.examples.databinding.pojo.bindable.model;
 
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
 
/**
 * POJO model Person.
 * 
 */
public class PojoPerson implements org.eclipse.core.databinding.pojo.bindable.BindableAware {
 
	private transient PropertyChangeSupport _bindable_propertyChangeSupport = null;
 
	String name = "HelloWorld";
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		Object oldValue = this.name;
		Object newValue = name;
		this.name = name;
		_bindable_getPropertyChangeSupport().firePropertyChange("name ",
				oldValue, newValue);
 
	}
 
	private PropertyChangeSupport _bindable_getPropertyChangeSupport() {
		if (_bindable_propertyChangeSupport == null) {
			this._bindable_propertyChangeSupport = new PropertyChangeSupport(
					this);
		}
		return _bindable_propertyChangeSupport;
	}
 
	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		_bindable_getPropertyChangeSupport().addPropertyChangeListener(
				propertyName, listener);
	}
 
	public void removePropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		_bindable_getPropertyChangeSupport().removePropertyChangeListener(
				propertyName, listener);
	}
}

Back to the top