Skip to content

Commit 005e3bf

Browse files
committed
[Databinding-Example] Added inline comments and another combined
IConverter Change-Id: I8d07b0f1ea8f202034a3431d3f4206f1436e2d02 Signed-off-by: Simon Scholz <[email protected]>
1 parent b18e1a2 commit 005e3bf

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

de.vogella.databinding.example/src/de/vogella/databinding/example/View.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
1515
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
1616
import org.eclipse.jface.databinding.swt.WidgetProperties;
17+
import org.eclipse.jface.layout.GridDataFactory;
18+
import org.eclipse.jface.layout.GridLayoutFactory;
1719
import org.eclipse.swt.SWT;
1820
import org.eclipse.swt.events.SelectionAdapter;
1921
import org.eclipse.swt.events.SelectionEvent;
@@ -49,9 +51,7 @@ public void createPartControl(Composite parent) {
4951

5052
person = createPerson();
5153
// Lets put thing to order
52-
GridLayout layout = new GridLayout(2, false);
53-
layout.marginRight = 5;
54-
parent.setLayout(layout);
54+
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);
5555

5656
Label firstLabel = new Label(parent, SWT.NONE);
5757
firstLabel.setText("Firstname: ");
@@ -84,14 +84,13 @@ public void createPartControl(Composite parent) {
8484
Label countryLabel = new Label(parent, SWT.NONE);
8585
countryLabel.setText("Country");
8686
countryText = new Text(parent, SWT.BORDER);
87-
87+
8888
Label programmingSkillsLabel = new Label(parent, SWT.NONE);
8989
programmingSkillsLabel.setText("Programming Skills");
90+
GridDataFactory.swtDefaults().applyTo(programmingSkillsLabel);
91+
9092
programmingSkillsText = new Text(parent, SWT.BORDER);
91-
gridData = new GridData();
92-
gridData.horizontalAlignment = SWT.FILL;
93-
gridData.grabExcessHorizontalSpace = true;
94-
programmingSkillsText.setLayoutData(gridData);
93+
GridDataFactory.fillDefaults().grab(true, false).applyTo(programmingSkillsText);
9594

9695
Button button1 = new Button(parent, SWT.PUSH);
9796
button1.setText("Write model");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.vogella.databinding.example.converter;
2+
3+
import org.eclipse.core.databinding.conversion.Converter;
4+
5+
public class CommaSeparatedStringStringArrayConverter extends Converter {
6+
7+
public CommaSeparatedStringStringArrayConverter() {
8+
// pass null for undefined fromType and toType
9+
super(null, null);
10+
}
11+
12+
@Override
13+
public Object convert(Object fromObject) {
14+
if (fromObject instanceof String) {
15+
return ((String) fromObject).split(";");
16+
} else if (fromObject instanceof String[]) {
17+
String[] stringArray = (String[]) fromObject;
18+
StringBuilder sb = new StringBuilder();
19+
int length = stringArray.length;
20+
for (int i = 0; i < length; i++) {
21+
String string = stringArray[i];
22+
sb.append(string);
23+
if (i + 1 < length) {
24+
sb.append(",");
25+
}
26+
}
27+
return sb.toString();
28+
}
29+
throw new IllegalArgumentException(fromObject.getClass() + " type cannot be converted by " + getClass());
30+
}
31+
32+
}

de.vogella.databinding.example/src/de/vogella/databinding/example/converter/CommaSeparatedStringToStringArrayConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
public class CommaSeparatedStringToStringArrayConverter extends Converter {
66

77
public CommaSeparatedStringToStringArrayConverter() {
8+
// Ensure that the fromType is a String and the toType is a String[] array
89
super(String.class, String[].class);
910
}
1011

1112
@Override
1213
public Object convert(Object fromObject) {
1314
if(fromObject instanceof String){
14-
return ((String) fromObject).split(";");
15+
return ((String) fromObject).split(",");
1516
}
1617
return null;
1718
}

de.vogella.databinding.example/src/de/vogella/databinding/example/converter/StringArrayToCommaSeparatedStringConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
public class StringArrayToCommaSeparatedStringConverter extends Converter {
66

77
public StringArrayToCommaSeparatedStringConverter() {
8+
// Ensure that the fromType is a String[] array and the toType is a String
89
super(String[].class, String.class);
910
}
1011

0 commit comments

Comments
 (0)