use of org.eclipse.jface.examples.databinding.model.Account in project eclipse.platform.ui by eclipse-platform.
the class ComboScenarios method test_ROCombo_SWTCCombo.
/**
* This scenario tests a simple SWT CCombo that is bound to a list of
* Country objects. The Country object's name property is listed in the
* Combo.
*
* The Combo's selection is bounded to the Country property of an Account.
*/
@Test
public void test_ROCombo_SWTCCombo() {
// Create a list of Strings for the countries
IObservableList<String> list = new WritableList<>();
for (int i = 0; i < catalog.getAccounts().length; i++) {
list.add(catalog.getAccounts()[i].getCountry());
}
CCombo ccombo = new CCombo(getComposite(), SWT.READ_ONLY | SWT.DROP_DOWN);
// Bind the combo's content to that of the String based list
getDbc().bindList(WidgetProperties.items().observe(ccombo), list);
assertEquals(Arrays.asList(ccombo.getItems()), list);
Account account = catalog.getAccounts()[0];
// simple Combo's selection bound to the Account's country property
IObservableValue<String> comboSelection = WidgetProperties.ccomboSelection().observe(ccombo);
getDbc().bindValue(comboSelection, BeanProperties.value("country").observe(account));
// Drive the combo selection
String selection = list.get(2);
// this should drive the selection
ccombo.setText(selection);
assertEquals(account.getCountry(), selection);
}
use of org.eclipse.jface.examples.databinding.model.Account in project eclipse.platform.ui by eclipse-platform.
the class PropertyScenarios method testScenario15.
@Test
public void testScenario15() {
Text text = new Text(getComposite(), SWT.NONE);
Account account = new Account();
account.setExpiryDate(new Date());
Binding b = getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), BeansObservables.observeValue(account, "expiryDate"));
Text errorText = new Text(getComposite(), SWT.NONE);
getDbc().bindValue(SWTObservables.observeText(errorText, SWT.Modify), b.getValidationStatus(), UpdateValueStrategy.never(), null);
assertTrue(b.getValidationStatus().getValue().isOK());
enterText(text, "foo");
assertFalse(b.getValidationStatus().getValue().isOK());
}
use of org.eclipse.jface.examples.databinding.model.Account in project eclipse.platform.ui by eclipse-platform.
the class TableScenarios method testScenario01.
@Test
public void testScenario01() {
// Show that a TableViewer with three columns renders the accounts
Account[] accounts = catalog.getAccounts();
IObservableList list = new WritableList(new ArrayList(), Account.class);
list.addAll(Arrays.asList(accounts));
ViewerSupport.bind(tableViewer, list, BeanProperties.values(Account.class, new String[] { "firstName", "lastName", "state" }));
Table table = tableViewer.getTable();
// Verify the data in the table columns matches the accounts
for (int i = 0; i < accounts.length; i++) {
Account account = catalog.getAccounts()[i];
TableItem item = table.getItem(i);
assertEquals(account.getFirstName(), item.getText(0));
assertEquals(account.getLastName(), item.getText(1));
assertEquals(account.getState(), item.getText(2));
}
}
use of org.eclipse.jface.examples.databinding.model.Account in project eclipse.platform.ui by eclipse-platform.
the class ComboScenarios method test_ROCombo_SWTList.
/**
* This scenario tests a simple SWT CCombo that is bound to a list of
* Country objects. The Country object's name property is listed in the
* Combo.
*
* The Combo's selection is bounded to the Country property of an Account.
*/
@Test
public void test_ROCombo_SWTList() {
// Create a list of Strings for the countries
IObservableList<String> list = new WritableList<>();
for (int i = 0; i < catalog.getAccounts().length; i++) {
list.add(catalog.getAccounts()[i].getCountry());
}
org.eclipse.swt.widgets.List swtlist = new org.eclipse.swt.widgets.List(getComposite(), SWT.READ_ONLY | SWT.SINGLE);
// Bind the combo's content to that of the String based list
getDbc().bindList(WidgetProperties.items().observe(swtlist), list);
assertEquals(Arrays.asList(swtlist.getItems()), list);
Account account = catalog.getAccounts()[0];
// simple Combo's selection bound to the Account's country property
IObservableValue<String> listSelection = WidgetProperties.listSelection().observe(swtlist);
getDbc().bindValue(listSelection, BeanProperties.value("country").observe(account));
String selection = list.get(2);
// this should drive the selection
swtlist.select(2);
// Force notification
swtlist.notifyListeners(SWT.Selection, null);
assertEquals(account.getCountry(), selection);
}
use of org.eclipse.jface.examples.databinding.model.Account in project eclipse.platform.ui by eclipse-platform.
the class ComboScenarios method test_WCombo_SWTCCombo.
/**
* This scenario tests a simple SWT CCombo that is bound to a list of
* Country objects. The Country object's name property is listed in the
* Combo.
*
* The Combo's selection is bounded to the Country property of an Account.
*/
@Test
public void test_WCombo_SWTCCombo() {
// Create a list of Strings for the countries
IObservableList<String> list = new WritableList<>();
for (int i = 0; i < catalog.getAccounts().length; i++) {
list.add(catalog.getAccounts()[i].getCountry());
}
CCombo ccombo = new CCombo(getComposite(), SWT.READ_ONLY | SWT.DROP_DOWN);
// Bind the combo's content to that of the String based list
getDbc().bindList(WidgetProperties.items().observe(ccombo), list);
assertEquals(Arrays.asList(ccombo.getItems()), list);
Account account = catalog.getAccounts()[0];
// simple Combo's selection bound to the Account's country property
IObservableValue<String> comboSelection = WidgetProperties.ccomboSelection().observe(ccombo);
getDbc().bindValue(comboSelection, BeanProperties.value("country").observe(account));
// Drive the combo selection
String selection = list.get(2);
// this should drive the selection
ccombo.setText(selection);
assertEquals(account.getCountry(), selection);
selection = list.get(1);
account.setCountry(selection);
assertEquals(selection, ccombo.getItem(ccombo.getSelectionIndex()));
assertEquals(selection, ccombo.getText());
selection = "country not in list";
account.setCountry(selection);
assertEquals(-1, ccombo.getSelectionIndex());
assertEquals(selection, ccombo.getText());
}
Aggregations