11package de .vogella .databinding .personpojo ;
22
33import org .eclipse .core .databinding .DataBindingContext ;
4- import org .eclipse .core .databinding .beans .PojoObservables ;
5- import org .eclipse .jface .databinding .swt .SWTObservables ;
4+ import org .eclipse .core .databinding .beans .PojoProperties ;
5+ import org .eclipse .core .databinding .observable .value .IObservableValue ;
6+ import org .eclipse .jface .databinding .swt .WidgetProperties ;
67import org .eclipse .swt .SWT ;
78import org .eclipse .swt .events .SelectionAdapter ;
89import org .eclipse .swt .events .SelectionEvent ;
10+ import org .eclipse .swt .layout .GridData ;
911import org .eclipse .swt .layout .GridLayout ;
1012import org .eclipse .swt .widgets .Button ;
1113import org .eclipse .swt .widgets .Composite ;
1618
1719import de .vogella .databinding .personpojo .model .PersonPojo ;
1820
19- public class MyView extends ViewPart {
20- public static final String ID = "de.vogella.databinding.personpojo.myview" ;
21-
21+ public class View extends ViewPart {
22+ public static String ID = "de.vogella.databinding.personpojo.view" ;
2223 private PersonPojo person ;
2324 private Text firstName ;
2425 private Button married ;
2526
26- public MyView () {
27+ public View () {
2728 person = new PersonPojo ();
2829 person .setFirstName ("Joe" );
2930 person .setLastName ("Jim" );
31+ person .setMarried (true );
3032 }
3133
3234 @ Override
@@ -36,6 +38,7 @@ public void createPartControl(Composite parent) {
3638 Label label = new Label (parent , SWT .NONE );
3739 label .setText ("FirstName" );
3840 firstName = new Text (parent , SWT .BORDER );
41+ firstName .setLayoutData (new GridData (SWT .FILL , SWT .TOP , true , false ));
3942 Label marriedLabel = new Label (parent , SWT .NONE );
4043 marriedLabel .setText ("Maried" );
4144 married = new Button (parent , SWT .CHECK );
@@ -44,7 +47,6 @@ public void createPartControl(Composite parent) {
4447 Button button1 = new Button (parent , SWT .PUSH );
4548 button1 .setText ("Write model" );
4649 button1 .addSelectionListener (new SelectionAdapter () {
47-
4850 @ Override
4951 public void widgetSelected (SelectionEvent e ) {
5052 System .out .println (person .getFirstName ());
@@ -56,12 +58,17 @@ public void widgetSelected(SelectionEvent e) {
5658
5759 private void bindValues () {
5860 DataBindingContext bindingContext = new DataBindingContext ();
59- bindingContext .bindValue (SWTObservables .observeText (firstName ,
60- SWT .Modify ), PojoObservables .observeValue (person , "firstName" ),
61- null , null );
62-
63- bindingContext .bindValue (SWTObservables .observeSelection (married ),
64- PojoObservables .observeValue (person , "married" ), null , null );
61+ IObservableValue myModel = PojoProperties .value (PersonPojo .class ,
62+ "firstName" ).observe (person );
63+ IObservableValue myWidget = WidgetProperties .text (SWT .Modify ).observe (
64+ firstName );
65+ bindingContext .bindValue (myWidget , myModel );
66+ myModel = PojoProperties .value (PersonPojo .class , "married" ).observe (
67+ person );
68+ myWidget = WidgetProperties .selection ().observe (married );
69+ bindingContext .bindValue (myWidget , myModel );
70+ // ControlDecorationSupport.create(bindingContext, SWT.TOP | SWT.RIGHT, null,
71+ // null);
6572 }
6673
6774 @ Override
0 commit comments