Skip to content

Commit 27e425e

Browse files
committed
Update on examples
1 parent 2f7d023 commit 27e425e

89 files changed

Lines changed: 769 additions & 384 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎de.vogella.databinding.person.swt/src/de/vogella/databinding/person/swt/View.java‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package de.vogella.databinding.person.swt;
22

3+
import org.eclipse.core.databinding.Binding;
34
import org.eclipse.core.databinding.DataBindingContext;
5+
import org.eclipse.core.databinding.UpdateValueStrategy;
46
import org.eclipse.core.databinding.beans.BeanProperties;
57
import org.eclipse.core.databinding.beans.BeansObservables;
68
import org.eclipse.core.databinding.observable.value.IObservableValue;
9+
import org.eclipse.core.databinding.validation.IValidator;
10+
import org.eclipse.core.databinding.validation.ValidationStatus;
11+
import org.eclipse.core.runtime.IStatus;
12+
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
713
import org.eclipse.jface.databinding.swt.WidgetProperties;
814
import org.eclipse.swt.SWT;
915
import org.eclipse.swt.events.SelectionAdapter;
@@ -125,21 +131,35 @@ public void setFocus() {
125131

126132
private void bindValues() {
127133
// The DataBindingContext object will manage the databindings
128-
DataBindingContext bindingContext = new DataBindingContext();
129134
// Lets bind it
135+
DataBindingContext bindingContext = new DataBindingContext();
130136
IObservableValue widgetValue = WidgetProperties.text(SWT.Modify)
131137
.observe(firstName);
132138
IObservableValue modelValue = BeanProperties.value(Person.class,
133139
"firstName").observe(person);
134-
// The above factories are similar to the following statements
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
138140
bindingContext.bindValue(widgetValue, modelValue);
139141

140142
widgetValue = WidgetProperties.text(SWT.Modify).observe(ageText);
141143
modelValue = BeanProperties.value(Person.class, "age").observe(person);
144+
145+
// We want that age is a number
146+
IValidator numberValidator = new IValidator() {
147+
148+
@Override
149+
public IStatus validate(Object value) {
150+
String s = String.valueOf(value);
151+
boolean matches = s.matches("\\d*");
152+
if (matches) {
153+
return ValidationStatus.ok();
154+
}
155+
return ValidationStatus.error("Only Number permitted");
156+
}
157+
};
158+
UpdateValueStrategy targetToModel = new UpdateValueStrategy();
159+
targetToModel.setAfterConvertValidator(numberValidator);
160+
142161
bindingContext.bindValue(widgetValue, modelValue);
162+
143163
widgetValue = WidgetProperties.selection().observe(marriedButton);
144164
modelValue = BeanProperties.value(Person.class, "married").observe(
145165
person);
@@ -151,10 +171,12 @@ private void bindValues() {
151171
bindingContext.bindValue(widgetValue, modelValue);
152172

153173
// Address field is bound to the Ui
154-
widgetValue = WidgetProperties.text(SWT.Modify).observe(ageText);
174+
widgetValue = WidgetProperties.text(SWT.Modify).observe(countryText);
175+
155176
modelValue = BeanProperties.value(Person.class, "address.country")
156177
.observe(person);
157-
bindingContext.bindValue(widgetValue, modelValue);
158-
178+
// Remember the bindingContext to allow control decoration
179+
Binding bindValue = bindingContext.bindValue(widgetValue, modelValue, targetToModel, null);
180+
ControlDecorationSupport.create(bindValue, SWT.TOP | SWT.RIGHT);
159181
}
160182
}

‎de.vogella.databinding.personpojo/META-INF/MANIFEST.MF‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Require-Bundle: org.eclipse.ui,
88
org.eclipse.core.runtime,
99
org.eclipse.core.databinding;bundle-version="1.1.1",
1010
org.eclipse.jface.databinding;bundle-version="1.2.1",
11-
org.eclipse.core.databinding.beans;bundle-version="1.1.1"
11+
org.eclipse.core.databinding.beans;bundle-version="1.1.1",
12+
org.eclipse.core.databinding.property;bundle-version="1.3.0"
1213
Bundle-ActivationPolicy: lazy
1314
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

‎de.vogella.databinding.personpojo/plugin.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<extension
2323
point="org.eclipse.ui.views">
2424
<view
25-
class="de.vogella.databinding.personpojo.MyView"
26-
id="de.vogella.databinding.personpojo.myview"
25+
class="de.vogella.databinding.personpojo.View"
26+
id="de.vogella.databinding.personpojo.view"
2727
name="name"
2828
restorable="true">
2929
</view>

‎de.vogella.databinding.personpojo/src/de/vogella/databinding/personpojo/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(MyView.ID, IPageLayout.TOP, IPageLayout.RATIO_MAX,
9+
layout.addView(View.ID, IPageLayout.TOP, IPageLayout.RATIO_MAX,
1010
IPageLayout.ID_EDITOR_AREA);
1111
}
1212
}

de.vogella.databinding.personpojo/src/de/vogella/databinding/personpojo/MyView.java renamed to de.vogella.databinding.personpojo/src/de/vogella/databinding/personpojo/View.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package de.vogella.databinding.personpojo;
22

33
import 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;
67
import org.eclipse.swt.SWT;
78
import org.eclipse.swt.events.SelectionAdapter;
89
import org.eclipse.swt.events.SelectionEvent;
10+
import org.eclipse.swt.layout.GridData;
911
import org.eclipse.swt.layout.GridLayout;
1012
import org.eclipse.swt.widgets.Button;
1113
import org.eclipse.swt.widgets.Composite;
@@ -16,17 +18,17 @@
1618

1719
import 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

‎de.vogella.databinding.validation/src/de/vogella/databinding/validation/validators/StringLongerThenTwo.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.eclipse.core.databinding.validation.IValidator;
44
import org.eclipse.core.databinding.validation.ValidationStatus;
55
import org.eclipse.core.runtime.IStatus;
6-
import org.eclipse.core.runtime.Status;
76
import org.eclipse.jface.fieldassist.ControlDecoration;
87

98
public class StringLongerThenTwo implements IValidator {
@@ -25,7 +24,7 @@ public IStatus validate(Object value) {
2524
// We check if the string is longer then 2 signs
2625
if (s.length() > 2) {
2726
controlDecoration.hide();
28-
return Status.OK_STATUS;
27+
return ValidationStatus.ok();
2928
} else {
3029
controlDecoration.show();
3130
return ValidationStatus.error(message);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>de.vogella.swtbrowser</name>
3+
<name>de.vogella.plugin.selection</name>
44
<comment></comment>
55
<projects>
66
</projects>

de.vogella.swtbrowser/.settings/org.eclipse.jdt.core.prefs renamed to de.vogella.plugin.selection/.settings/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Thu Oct 29 12:04:22 CET 2009
1+
#Mon Sep 20 09:45:03 CEST 2010
22
eclipse.preferences.version=1
33
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
44
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6

de.vogella.swtbrowser/META-INF/MANIFEST.MF renamed to de.vogella.plugin.selection/META-INF/MANIFEST.MF

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
3-
Bundle-Name: Swtbrowser
4-
Bundle-SymbolicName: de.vogella.swtbrowser; singleton:=true
3+
Bundle-Name: Selection
4+
Bundle-SymbolicName: de.vogella.plugin.selection;singleton:=true
55
Bundle-Version: 1.0.0.qualifier
6-
Bundle-Activator: de.vogella.swtbrowser.Activator
6+
Bundle-Activator: de.vogella.plugin.selection.Activator
77
Require-Bundle: org.eclipse.ui,
88
org.eclipse.core.runtime
99
Bundle-ActivationPolicy: lazy

0 commit comments

Comments
 (0)