Search in sources :

Example 1 with SetDetailValueObservableMap

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

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

the class SetDetailValueObservableMapTest method testMasterNull.

@Test
public void testMasterNull() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Make sure null values are handled gracefully.
    masterKeySet.add(null);
    assertEquals(1, sdom.size());
    assertNull(sdom.get(null));
}
Also used : SetDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 3 with SetDetailValueObservableMap

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

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

the class SetDetailValueObservableMapTest method testDisposeOnMasterDisposed.

@Test
public void testDisposeOnMasterDisposed() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    // Initially, nothing should be disposed.
    assertFalse(masterKeySet.isDisposed());
    assertFalse(sdom.isDisposed());
    // Upon disposing the master list, the detail list should be disposed as
    // well.
    masterKeySet.dispose();
    assertTrue(masterKeySet.isDisposed());
    assertTrue(sdom.isDisposed());
}
Also used : SetDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 5 with SetDetailValueObservableMap

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

WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)12 SetDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap)12 Test (org.junit.Test)12 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)8 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