Search in sources :

Example 1 with Account

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);
}
Also used : Account(org.eclipse.jface.examples.databinding.model.Account) CCombo(org.eclipse.swt.custom.CCombo) WritableList(org.eclipse.core.databinding.observable.list.WritableList) Test(org.junit.Test)

Example 2 with Account

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());
}
Also used : Binding(org.eclipse.core.databinding.Binding) Account(org.eclipse.jface.examples.databinding.model.Account) Text(org.eclipse.swt.widgets.Text) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Account

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));
    }
}
Also used : Account(org.eclipse.jface.examples.databinding.model.Account) Table(org.eclipse.swt.widgets.Table) WritableList(org.eclipse.core.databinding.observable.list.WritableList) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) Test(org.junit.Test)

Example 4 with Account

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);
}
Also used : Account(org.eclipse.jface.examples.databinding.model.Account) WritableList(org.eclipse.core.databinding.observable.list.WritableList) WritableList(org.eclipse.core.databinding.observable.list.WritableList) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) Test(org.junit.Test)

Example 5 with Account

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());
}
Also used : Account(org.eclipse.jface.examples.databinding.model.Account) CCombo(org.eclipse.swt.custom.CCombo) WritableList(org.eclipse.core.databinding.observable.list.WritableList) Test(org.junit.Test)

Aggregations

Account (org.eclipse.jface.examples.databinding.model.Account)5 Test (org.junit.Test)5 WritableList (org.eclipse.core.databinding.observable.list.WritableList)4 ArrayList (java.util.ArrayList)2 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)2 CCombo (org.eclipse.swt.custom.CCombo)2 Date (java.util.Date)1 List (java.util.List)1 Binding (org.eclipse.core.databinding.Binding)1 Table (org.eclipse.swt.widgets.Table)1 TableItem (org.eclipse.swt.widgets.TableItem)1 Text (org.eclipse.swt.widgets.Text)1