Skip to content

Commit 726182d

Browse files
committed
started to change JFace Databinding Tutorial
1 parent 39e605f commit 726182d

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

de.vogella.databinding.person.swt/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<extension
2323
point="org.eclipse.ui.views">
2424
<view
25-
class="de.vogella.databinding.person.swt.PersonView"
25+
class="de.vogella.databinding.person.swt.View"
2626
id="de.vogella.databinding.person.swt.View"
2727
name="name"
2828
restorable="true">

de.vogella.databinding.person.swt/src/de/vogella/databinding/person/swt/Perspective.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class Perspective implements IPerspectiveFactory {
77

88
public void createInitialLayout(IPageLayout layout) {
9-
layout.addView(PersonView.ID, IPageLayout.TOP, IPageLayout.RATIO_MAX,
9+
layout.addView(View.ID, IPageLayout.TOP, IPageLayout.RATIO_MAX,
1010
IPageLayout.ID_EDITOR_AREA);
1111
layout.setEditorAreaVisible(false);
1212
}

de.vogella.databinding.person.swt/src/de/vogella/databinding/person/swt/PersonView.java renamed to de.vogella.databinding.person.swt/src/de/vogella/databinding/person/swt/View.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import org.eclipse.core.databinding.beans.BeanProperties;
55
import org.eclipse.core.databinding.beans.BeansObservables;
66
import org.eclipse.core.databinding.observable.value.IObservableValue;
7+
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
78
import org.eclipse.jface.databinding.swt.SWTObservables;
9+
import org.eclipse.jface.databinding.swt.WidgetProperties;
810
import org.eclipse.swt.SWT;
911
import org.eclipse.swt.events.SelectionAdapter;
1012
import org.eclipse.swt.events.SelectionEvent;
@@ -21,7 +23,7 @@
2123
import de.vogella.databinding.person.model.Address;
2224
import de.vogella.databinding.person.model.Person;
2325

24-
public class PersonView extends ViewPart {
26+
public class View extends ViewPart {
2527
public static final String ID = "de.vogella.databinding.person.swt.View";
2628
private Person person;
2729

@@ -31,9 +33,6 @@ public class PersonView extends ViewPart {
3133
private Combo genderCombo;
3234
private Text countryText;
3335

34-
public PersonView() {
35-
}
36-
3736
@Override
3837
public void createPartControl(Composite parent) {
3938

@@ -132,21 +131,23 @@ private void bindValues() {
132131
IObservableValue uiElement;
133132
IObservableValue modelElement;
134133
// Lets bind it
135-
uiElement = SWTObservables.observeText(firstName, SWT.Modify);
136-
modelElement = BeansObservables.observeValue(person, "firstName");
137-
// The bindValue method call binds the text element with the model
138-
bindingContext.bindValue(uiElement, modelElement, null, null);
139-
140-
uiElement = SWTObservables.observeText(ageText, SWT.Modify);
141-
modelElement = BeansObservables.observeValue(person, "age");
142-
// Remember the binding so that we can listen to validator problems
143-
// See below for usage
144-
bindingContext.bindValue(uiElement, modelElement, null, null);
145-
146-
uiElement = SWTObservables.observeSelection(marriedButton);
147-
modelElement = BeansObservables.observeValue(person, "married");
148-
149-
bindingContext.bindValue(uiElement, modelElement, null, null);
134+
ISWTObservableValue widgetValue = WidgetProperties.text(SWT.Modify)
135+
.observe(firstName);
136+
IObservableValue modelValue = BeanProperties.value(Person.class,
137+
"firstName").observe(person);
138+
// The above factories are similar to the following statements
139+
// uiElement = SWTObservables.observeText(firstName, SWT.Modify);
140+
// modelElement = BeansObservables.observeValue(person, "firstName");
141+
// // The bindValue method call binds the text element with the model
142+
bindingContext.bindValue(widgetValue, modelValue);
143+
144+
widgetValue = WidgetProperties.text(SWT.Modify).observe(ageText);
145+
modelValue = BeanProperties.value(Person.class, "age").observe(person);
146+
bindingContext.bindValue(widgetValue, modelValue);
147+
widgetValue = WidgetProperties.selection().observe(marriedButton);
148+
modelValue = BeanProperties.value(Person.class, "married").observe(
149+
person);
150+
bindingContext.bindValue(widgetValue, modelValue);
150151

151152
uiElement = SWTObservables.observeSelection(genderCombo);
152153
modelElement = BeansObservables.observeValue(person, "gender");
@@ -159,5 +160,4 @@ private void bindValues() {
159160
bindingContext.bindValue(uiElement, modelElement, null, null);
160161

161162
}
162-
163163
}

0 commit comments

Comments
 (0)