Search in sources :

Example 26 with SimplePerson

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

the class SetDetailValueObservableMapTest method testChangeDetail.

@Test
public void testChangeDetail() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Change the detail attribute explicitly.
    SimplePerson p1 = new SimplePerson();
    p1.setName("name1");
    masterKeySet.add(p1);
    assertEquals(p1.getName(), sdom.get(p1));
    p1.setName("name2");
    assertEquals(p1.getName(), sdom.get(p1));
    // Change the detail attribute by changing the master.
    SimplePerson p2 = new SimplePerson();
    p2.setName("name3");
    masterKeySet.add(p2);
    assertEquals(p2.getName(), sdom.get(p2));
}
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 27 with SimplePerson

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

the class SetDetailValueObservableMapTest method testRemove.

@Test
public void testRemove() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Add two person objects to the map.
    SimplePerson p1 = new SimplePerson();
    SimplePerson p2 = new SimplePerson();
    masterKeySet.add(p1);
    masterKeySet.add(p2);
    // Initially, both person objects should be contained in the detail map.
    assertTrue(sdom.containsKey(p1));
    assertTrue(sdom.containsKey(p2));
    // Remove one person and check that it is not contained anymore.
    sdom.remove(p1);
    assertFalse(sdom.containsKey(p1));
    assertTrue(sdom.containsKey(p2));
    // Trying to remove a non-existent is allowed but has no effect.
    sdom.remove(p1);
    assertFalse(sdom.containsKey(p1));
    assertTrue(sdom.containsKey(p2));
}
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 28 with SimplePerson

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

the class CompositeMapTest method testChangeInFirstMap.

@Test
public void testChangeInFirstMap() {
    SimplePerson person1 = new SimplePerson("p1", "a1", "c1", "s1");
    person1.getCart().setNumItems(42);
    persons.add(person1);
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    person1.setCart(new SimpleCart());
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getAddedKeys().size());
    assertEquals(0, tracker.event.diff.getRemovedKeys().size());
    assertEquals(Collections.singleton(person1), tracker.event.diff.getChangedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getOldValue(person1));
    assertEquals(Integer.valueOf(0), tracker.event.diff.getNewValue(person1));
    assertEquals(Integer.valueOf(0), composedMap.get(person1));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimpleCart(org.eclipse.jface.examples.databinding.model.SimpleCart) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 29 with SimplePerson

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

the class CompositeMapTest method testRemoveFromFirstMap.

@Test
public void testRemoveFromFirstMap() {
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    SimplePerson newPerson = new SimplePerson("p1", "a1", "c1", "s1");
    newPerson.getCart().setNumItems(42);
    persons.add(newPerson);
    assertTrue("newPerson should be added", composedMap.containsKey(newPerson));
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    persons.remove(newPerson);
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getAddedKeys().size());
    assertEquals(0, tracker.event.diff.getChangedKeys().size());
    assertEquals(Collections.singleton(newPerson), tracker.event.diff.getRemovedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getOldValue(newPerson));
    assertFalse("newPerson should be removed", composedMap.containsKey(newPerson));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 30 with SimplePerson

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

the class CompositeMapTest method testAddToFirstMap.

@Test
public void testAddToFirstMap() {
    MapChangeEventTracker<Object, Object> tracker = new MapChangeEventTracker<>();
    composedMap.addMapChangeListener(tracker);
    assertEquals(0, tracker.count);
    SimplePerson newPerson = new SimplePerson("p1", "a1", "c1", "s1");
    newPerson.getCart().setNumItems(42);
    persons.add(newPerson);
    assertEquals(1, tracker.count);
    assertEquals(0, tracker.event.diff.getRemovedKeys().size());
    assertEquals(0, tracker.event.diff.getChangedKeys().size());
    assertEquals(Collections.singleton(newPerson), tracker.event.diff.getAddedKeys());
    assertEquals(Integer.valueOf(42), tracker.event.diff.getNewValue(newPerson));
    assertEquals(Integer.valueOf(42), composedMap.get(newPerson));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) 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