Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Data binding issue
Data binding issue [message #528010] Sun, 18 April 2010 13:35 Go to next message
Tamas Gyorfi is currently offline Tamas Gyorfi
Messages: 1
Registered: April 2010
Junior Member
Hi all,

I have the following problem. There's an XML file presented to the user in a graphic format: text fields, check boxes, radio buttons etc. The whole stuff is put onto a tab page. There is another tab, where the user can edit the XML source itself. All the controls are bound to model elements. However, when I edit information in one tab, the model gets updated, but the info on the other tab does not. Isn't data binding supposed to be bidirectional? Is there any way I can tell the binding context that I want a two way binding.

Thank you in advance,
--Chaster
Re: Data binding issue [message #528229 is a reply to message #528010] Mon, 19 April 2010 14:34 Go to previous message
Wim Jongman is currently offline Wim Jongman
Messages: 418
Registered: July 2009
Senior Member
Hi Tamas,

Yes you can. The strategies decide how the data flows. See this snippet for
an example.

Copy it and paste it in a project.

package perspectivetest;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableVal ue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class DBTest extends Shell {
private DataBindingContext m_bindingContext;
private Text view;
private Text model;

/**
* Launch the application.
* @param args
*/
public static void main(String args[]) {
Display display = Display.getDefault();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
Display display = Display.getDefault();
DBTest shell = new DBTest(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the shell.
* @param display
*/
public DBTest(Display display) {
super(display, SWT.SHELL_TRIM);

view = new Text(this, SWT.BORDER);
view.setBounds(10, 10, 144, 46);

model = new Text(this, SWT.BORDER);
model.setBounds(203, 10, 149, 46);
createContents();
m_bindingContext = initDataBindings();
}

/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(450, 300);

}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue viewObserveTextObserveWidget =
SWTObservables.observeText(view, SWT.Modify);
IObservableValue modelTextObserveValue = SWTObservables.observeText(model,
SWT.Modify);
bindingContext.bindValue(viewObserveTextObserveWidget,
modelTextObserveValue); //, new
UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE), new
UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
//
return bindingContext;
}
}


--

Best Regards,
Wim Jongman
-- Smash forehead on keyboard to continue.....
(Eclipse Old Skool Quote Service)

> Hi all,
>
> I have the following problem. There's an XML file presented to the user in
a graphic format: text fields, check boxes, radio buttons etc. The whole
stuff is put onto a tab page. There is another tab, where the user can edit
the XML source itself. All the controls are bound to model elements. However,
when I edit information in one tab, the model gets updated, but the info on
the other tab does not. Isn't data binding supposed to be bidirectional? Is
there any way I can tell the binding context that I want a two way binding.
>
> Thank you in advance,
> --Chaster
Previous Topic:My 'Problems' view is not working
Next Topic:Best way to add printing support to an RCP app?
Goto Forum:
  


Current Time: Sat Apr 19 12:02:22 EDT 2014

Powered by FUDForum. Page generated in 0.01880 seconds