Search in sources :

Example 6 with SimplePerson

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

the class ListDetailValueObservableListTest method testDuplicateMasterElements.

@Test
public void testDuplicateMasterElements() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    SimplePerson master = new SimplePerson();
    master.setName("name1");
    // Add the same master twice.
    masterList.add(master);
    masterList.add(master);
    // Attach the change listener to the detail list.
    ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
    // Setting the name on master should trigger an event on both
    // occurrences of in the master list.
    master.setName("name2");
    // We should have 2 replace diffs, i.e. 4 diff entries.
    assertEquals(1, changeTracker.count);
    assertEquals(4, changeTracker.event.diff.getDifferences().length);
    assertReplaceDiffAt(changeTracker.event.diff, 0, 0, "name1", "name2");
    assertReplaceDiffAt(changeTracker.event.diff, 2, 0, "name1", "name2");
    // Remove one instance of the master (one will remain).
    masterList.remove(master);
    // It should still be possible to work on the remaining master instance.
    ldol.set(0, "name3");
    assertEquals("name3", master.getName());
}
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 7 with SimplePerson

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

the class ListDetailValueObservableListTest method testAddRemove.

@Test
public void testAddRemove() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    // Initially, the detail list is empty.
    assertTrue(ldol.isEmpty());
    // Add a first person and check that its name is in the detail list.
    SimplePerson p1 = new SimplePerson();
    p1.setName("name1");
    masterList.add(p1);
    assertEquals(masterList.size(), ldol.size());
    assertEquals(p1.getName(), ldol.get(0));
    // Add a second person and check that it's name is in the detail list.
    SimplePerson p2 = new SimplePerson();
    p2.setName("name2");
    masterList.add(p2);
    assertEquals(masterList.size(), ldol.size());
    assertEquals(p2.getName(), ldol.get(1));
    // Remove the first person from the master list and check that we still
    // have the name of the second person in the detail list.
    masterList.remove(0);
    assertEquals(masterList.size(), ldol.size());
    assertEquals(p2.getName(), ldol.get(0));
    // Remove the second person as well.
    masterList.remove(0);
    assertTrue(ldol.isEmpty());
}
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 8 with SimplePerson

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

the class ListDetailValueObservableListTest method testMasterListInitiallyNotEmpty.

@Test
public void testMasterListInitiallyNotEmpty() {
    WritableList masterList = new WritableList();
    SimplePerson person = new SimplePerson();
    person.setName("name");
    masterList.add(person);
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    // Make sure that a non-empty master list is initialized correctly.
    assertEquals(masterList.size(), ldol.size());
    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)

Example 9 with SimplePerson

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

the class MapDetailValueObservableMapTest method testContainsValue.

@Test
public void testContainsValue() {
    WritableMap masterMap = new WritableMap();
    MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
    // Add a person with a given name.
    SimplePerson person = new SimplePerson();
    person.setName("name");
    masterMap.put(person, person);
    // Make sure the name of the person is contained.
    assertTrue(mdom.containsValue(person.getName()));
    // Remove the person and make sure that it's name cannot be found
    // anymore.
    masterMap.remove(person);
    assertFalse(mdom.containsValue(person.getName()));
}
Also used : WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 10 with SimplePerson

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

the class MapDetailValueObservableMapTest method testDetailObservableChangeEvent.

@Test
public void testDetailObservableChangeEvent() {
    WritableMap masterMap = new WritableMap();
    MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
    MapChangeEventTracker changeTracker = MapChangeEventTracker.observe(mdom);
    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.
    masterMap.put(person, person);
    assertEquals(1, changeTracker.count);
    assertEquals(1, changeTracker.event.diff.getAddedKeys().size());
    assertEquals(0, changeTracker.event.diff.getRemovedKeys().size());
    assertEquals(0, changeTracker.event.diff.getChangedKeys().size());
    assertSame(person, changeTracker.event.diff.getAddedKeys().iterator().next());
    assertNull(changeTracker.event.diff.getOldValue(person));
    assertEquals("old name", changeTracker.event.diff.getNewValue(person));
    // Change the detail property and check that we receive a replace
    person.setName("new name");
    assertEquals(2, changeTracker.count);
    assertEquals(0, changeTracker.event.diff.getAddedKeys().size());
    assertEquals(0, changeTracker.event.diff.getRemovedKeys().size());
    assertEquals(1, changeTracker.event.diff.getChangedKeys().size());
    assertSame(person, changeTracker.event.diff.getChangedKeys().iterator().next());
    assertEquals("old name", changeTracker.event.diff.getOldValue(person));
    assertEquals("new name", changeTracker.event.diff.getNewValue(person));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

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