Search in sources :

Example 11 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson 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 12 with SimplePerson

use of org.eclipse.jface.examples.databinding.model.SimplePerson 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)

Example 13 with SimplePerson

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

the class SetDetailValueObservableMapTest method testContainsValue.

@Test
public void testContainsValue() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Add a person with a given name.
    SimplePerson person = new SimplePerson();
    person.setName("name");
    masterKeySet.add(person);
    // Make sure the name of the person is contained.
    assertTrue(sdom.containsValue(person.getName()));
    // Remove the person and make sure that it's name cannot be found
    // anymore.
    masterKeySet.remove(person);
    assertFalse(sdom.containsValue(person.getName()));
}
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 14 with SimplePerson

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

the class SetDetailValueObservableMapTest method testMasterSetInitiallyNotEmpty.

@Test
public void testMasterSetInitiallyNotEmpty() {
    WritableSet masterKeySet = new WritableSet();
    SimplePerson person = new SimplePerson();
    person.setName("name");
    masterKeySet.add(person);
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Make sure that a non-empty master key set is initialized correctly.
    assertEquals(masterKeySet.size(), sdom.size());
    assertEquals(person.getName(), sdom.get(person));
}
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 15 with SimplePerson

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

the class SetDetailValueObservableMapTest method testPut.

@Test
public void testPut() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Change the detail attribute explicitly.
    SimplePerson person = new SimplePerson();
    person.setName("name1");
    masterKeySet.add(person);
    assertEquals(person.getName(), sdom.get(person));
    // Set a new name on the detail map.
    sdom.put(person, "name2");
    // Check that the name has been propagated to the master.
    assertEquals("name2", person.getName());
    assertEquals(person.getName(), sdom.get(person));
}
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)

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