Search in sources :

Example 21 with SimplePerson

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

the class MapDetailValueObservableMapTest method testMasterSetInitiallyNotEmpty.

@Test
public void testMasterSetInitiallyNotEmpty() {
    WritableMap masterMap = new WritableMap();
    SimplePerson person = new SimplePerson();
    person.setName("name");
    masterMap.put(person, person);
    MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, BeansObservables.valueFactory("name"), String.class);
    // Make sure that a non-empty master key set is initialized correctly.
    assertEquals(masterMap.size(), mdom.size());
    assertEquals(person.getName(), mdom.get(person));
}
Also used : WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) Test(org.junit.Test)

Example 22 with SimplePerson

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

the class MapDetailValueObservableMapTest method testPut.

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

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

the class MapDetailValueObservableMapTest method testChangeDetail.

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

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

the class JavaBeanObservableValueTest method testBug198519.

@Test
public void testBug198519() {
    final SimplePerson person = new SimplePerson();
    final ComputedValue cv = new ComputedValue() {

        final IObservableValue name = BeansObservables.observeValue(person, // $NON-NLS-1$
        "name");

        @Override
        protected Object calculate() {
            return Boolean.valueOf(name.getValue() != null);
        }
    };
    cv.addChangeListener(event -> cv.getValue());
    person.setName("foo");
}
Also used : ComputedValue(org.eclipse.core.databinding.observable.value.ComputedValue) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) MutableObservableValueContractTest(org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest) Test(org.junit.Test)

Example 25 with SimplePerson

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

the class SetDetailValueObservableMapTest method testDetailObservableChangeEvent.

@Test
public void testDetailObservableChangeEvent() {
    WritableSet masterKeySet = new WritableSet();
    SetDetailValueObservableMap sdom = new SetDetailValueObservableMap(masterKeySet, BeansObservables.valueFactory("name"), String.class);
    MapChangeEventTracker changeTracker = MapChangeEventTracker.observe(sdom);
    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.
    masterKeySet.add(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) 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