Search in sources :

Example 1 with MapDetailValueObservableMap

use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap 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 2 with MapDetailValueObservableMap

use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap 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)

Example 3 with MapDetailValueObservableMap

use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.

the class MapDetailValueObservableMapTest method testGetKeyType.

@Test
public void testGetKeyType() {
    MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(new WritableMap(SimplePerson.class, SimplePerson.class), BeansObservables.valueFactory("name"), String.class);
    assertSame(SimplePerson.class, mdom.getKeyType());
}
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 4 with MapDetailValueObservableMap

use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.

the class MapDetailValueObservableMapTest method testAddRemove.

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

use of org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap in project eclipse.platform.ui by eclipse-platform.

the class MapDetailValueObservableMapTest method testRemove.

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

Aggregations

WritableMap (org.eclipse.core.databinding.observable.map.WritableMap)13 MapDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap)13 Test (org.junit.Test)13 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)9 MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BeansObservables (org.eclipse.core.databinding.beans.BeansObservables)1 IObservableFactory (org.eclipse.core.databinding.observable.masterdetail.IObservableFactory)1 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)1 AbstractDefaultRealmTestCase (org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertSame (org.junit.Assert.assertSame)1 Assert.assertTrue (org.junit.Assert.assertTrue)1