Search in sources :

Example 31 with SimplePerson

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

the class CompositeMapTest method testAddSharedToFirstMap.

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

Example 32 with SimplePerson

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

the class CompositeMapTest method testChangeInFirstMapToShared.

@Test
public void testChangeInFirstMapToShared() {
    SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0");
    person0.getCart().setNumItems(13);
    persons.add(person0);
    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(person0.getCart());
    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(13), tracker.event.diff.getNewValue(person1));
    assertEquals(Integer.valueOf(13), composedMap.get(person1));
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test)

Example 33 with SimplePerson

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

the class CompositeMapTest method testDispose.

@Test
public void testDispose() {
    SimplePerson person0 = new SimplePerson("p0", "a0", "c0", "s0");
    person0.getCart().setNumItems(13);
    persons.add(person0);
    assertTrue(hasListeners((AbstractObservable) first));
    composedMap.dispose();
    assertFalse(hasListeners((AbstractObservable) first));
}
Also used : AbstractObservable(org.eclipse.core.databinding.observable.AbstractObservable) 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