Search in sources :

Example 16 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.

the class SetDetailValueObservableMapTest method testAddRemove.

@Test
public void testAddRemove() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Initially, the detail map is empty.
    assertTrue(sdom.isEmpty());
    // Add a first person and check that its name is in the detail list.
    SimplePerson p1 = new SimplePerson();
    p1.setName("name1");
    masterKeySet.add(p1);
    assertEquals(masterKeySet.size(), sdom.size());
    assertEquals(p1.getName(), sdom.get(p1));
    // Add a second person and check that it's name is in the detail list.
    SimplePerson p2 = new SimplePerson();
    p2.setName("name2");
    masterKeySet.add(p2);
    assertEquals(masterKeySet.size(), sdom.size());
    assertEquals(p2.getName(), sdom.get(p2));
    // Remove the first person from the master list and check that we still
    // have the name of the second person in the detail list.
    masterKeySet.remove(p1);
    assertEquals(masterKeySet.size(), sdom.size());
    assertEquals(p2.getName(), sdom.get(p2));
    // Remove the second person as well.
    masterKeySet.remove(p2);
    assertTrue(sdom.isEmpty());
}
Also used : SetDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 17 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.

the class PersonTests method testSetName.

@Test
public void testSetName() {
    SimplePerson person = new SimplePerson();
    Listener listener = new Listener();
    person.addPropertyChangeListener(listener);
    assertEquals(0, listener.count);
    assertNull(listener.lastEvent);
    // $NON-NLS-1$
    person.setState("new state");
    assertEquals(1, listener.count);
    assertNotNull(listener.lastEvent);
    // $NON-NLS-1$
    assertEquals("state", listener.lastEvent.getPropertyName());
    assertEquals("", listener.lastEvent.getOldValue());
    // $NON-NLS-1$
    assertEquals("new state", listener.lastEvent.getNewValue());
    assertEquals("new state", person.getState());
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 18 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.

the class ListDetailValueObservableListTest method testDetailObservableChangeEvent.

@Test
public void testDetailObservableChangeEvent() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
    SimplePerson person = new SimplePerson();
    person.setName("old name");
    // Initially, we should not have received any event.
    assertEquals(0, changeTracker.count);
    // Add the person and check that we receive an addition event on the
    // correct index and with the correct value.
    masterList.add(person);
    assertEquals(1, changeTracker.count);
    assertEquals(1, changeTracker.event.diff.getDifferences().length);
    assertTrue(changeTracker.event.diff.getDifferences()[0].isAddition());
    assertEquals(0, changeTracker.event.diff.getDifferences()[0].getPosition());
    assertEquals(person.getName(), changeTracker.event.diff.getDifferences()[0].getElement());
    // Change the detail property and check that we receive a replace event.
    person.setName("new name");
    assertEquals(2, changeTracker.count);
    assertIsSingleReplaceDiff(changeTracker.event.diff, 0, "old name", "new name");
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 19 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.

the class ListDetailValueObservableListTest method testChangeDetail.

@Test
public void testChangeDetail() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    // Change the detail attribute explicitly.
    SimplePerson p1 = new SimplePerson();
    p1.setName("name1");
    masterList.add(p1);
    assertEquals(p1.getName(), ldol.get(0));
    p1.setName("name2");
    assertEquals(p1.getName(), ldol.get(0));
    // Change the detail attribute by changing the master.
    SimplePerson p2 = new SimplePerson();
    p2.setName("name3");
    masterList.set(0, p2);
    assertEquals(p2.getName(), ldol.get(0));
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 20 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson in project eclipse.platform.ui by eclipse-platform.

the class ListDetailValueObservableListTest method testSet.

@Test
public void testSet() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    // Change the detail attribute explicitly.
    SimplePerson person = new SimplePerson();
    person.setName("name1");
    masterList.add(person);
    assertEquals(person.getName(), ldol.get(0));
    // Set a new name on the detail list.
    ldol.set(0, "name2");
    // Check that the name has been propagated to the master.
    assertEquals("name2", person.getName());
    assertEquals(person.getName(), ldol.get(0));
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Aggregations

SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)33 Test (org.junit.Test)32 MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)10 WritableList (org.eclipse.core.databinding.observable.list.WritableList)8 WritableMap (org.eclipse.core.databinding.observable.map.WritableMap)7 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)7 ListDetailValueObservableList (org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList)7 MapDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap)7 SetDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap)7 ObservableListContractTest (org.eclipse.jface.databinding.conformance.ObservableListContractTest)7 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 ListChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker)2 SimpleCart (org.eclipse.jface.examples.databinding.model.SimpleCart)2 PropertyChangeListener (java.beans.PropertyChangeListener)1 Binding (org.eclipse.core.databinding.Binding)1 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)1 BeanProperties (org.eclipse.core.databinding.beans.typed.BeanProperties)1 IConverter (org.eclipse.core.databinding.conversion.IConverter)1 AbstractObservable (org.eclipse.core.databinding.observable.AbstractObservable)1