Search in sources :

Example 1 with IObservableFactory

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

the class PojoObservablesTest method testValueFactory_DoesNotAttachListeners.

@Test
public void testValueFactory_DoesNotAttachListeners() throws Exception {
    IObservableFactory factory = PojoObservables.valueFactory(Realm.getDefault(), "value");
    IObservableValue observable = (IObservableValue) factory.createObservable(pojo);
    assertFalse(pojo.hasListeners("value"));
    ChangeEventTracker.observe(observable);
    assertFalse(pojo.hasListeners("value"));
}
Also used : IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) Test(org.junit.Test)

Example 2 with IObservableFactory

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

the class PojoObservablesTest method testSetFactoryWithElementType_DoesNotAttachListeners.

@Test
public void testSetFactoryWithElementType_DoesNotAttachListeners() throws Exception {
    IObservableFactory factory = PojoObservables.setFactory(Realm.getDefault(), propertyName, String.class);
    IObservableSet observable = (IObservableSet) factory.createObservable(pojo);
    assertFalse(pojo.hasListeners("set"));
    ChangeEventTracker.observe(observable);
    assertFalse(pojo.hasListeners("set"));
}
Also used : IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) Test(org.junit.Test)

Example 3 with IObservableFactory

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

the class PojoObservablesTest method testListFactory_DoesNotAttachListeners.

@Test
public void testListFactory_DoesNotAttachListeners() throws Exception {
    IObservableFactory factory = PojoObservables.listFactory(Realm.getDefault(), "list", String.class);
    IObservableList observable = (IObservableList) factory.createObservable(pojo);
    assertFalse(pojo.hasListeners("value"));
    ChangeEventTracker.observe(observable);
    assertFalse(pojo.hasListeners("value"));
}
Also used : IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) Test(org.junit.Test)

Example 4 with IObservableFactory

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

the class ListDetailValueObservableListTest method testDetailObservableValuesAreDisposed.

@Test
public void testDetailObservableValuesAreDisposed() {
    final List detailObservables = new ArrayList();
    IObservableFactory detailValueFactory = target -> {
        WritableValue detailObservable = new WritableValue();
        // Remember the created observables.
        detailObservables.add(detailObservable);
        return detailObservable;
    };
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, detailValueFactory, null);
    masterList.add(new Object());
    masterList.add(new Object());
    assertEquals(ldol.size(), detailObservables.size());
    // No detail observables should be disposed yet.
    assertFalse(((WritableValue) detailObservables.get(0)).isDisposed());
    assertFalse(((WritableValue) detailObservables.get(1)).isDisposed());
    // Only the detail observable for the removed master should be disposed.
    masterList.remove(1);
    assertFalse(((WritableValue) detailObservables.get(0)).isDisposed());
    assertTrue(((WritableValue) detailObservables.get(1)).isDisposed());
    // After disposing the detail list, all detail observables should be
    // disposed.
    ldol.dispose();
    assertTrue(((WritableValue) detailObservables.get(0)).isDisposed());
    assertTrue(((WritableValue) detailObservables.get(1)).isDisposed());
}
Also used : AbstractObservableCollectionContractDelegate(org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate) WritableList(org.eclipse.core.databinding.observable.list.WritableList) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) Assert.assertSame(org.junit.Assert.assertSame) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) BeansObservables(org.eclipse.core.databinding.beans.BeansObservables) Assert.fail(org.junit.Assert.fail) ListDiff(org.eclipse.core.databinding.observable.list.ListDiff) Realm(org.eclipse.core.databinding.observable.Realm) IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) List(java.util.List) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest) Assert.assertNull(org.junit.Assert.assertNull) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) TestCollection(org.eclipse.jface.databinding.conformance.util.TestCollection) AbstractDefaultRealmTestCase(org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase) Assert.assertFalse(org.junit.Assert.assertFalse) IObservable(org.eclipse.core.databinding.observable.IObservable) IObservableCollection(org.eclipse.core.databinding.observable.IObservableCollection) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ListDiffEntry(org.eclipse.core.databinding.observable.list.ListDiffEntry) WritableList(org.eclipse.core.databinding.observable.list.WritableList) ArrayList(java.util.ArrayList) IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) WritableList(org.eclipse.core.databinding.observable.list.WritableList) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 5 with IObservableFactory

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

the class MapDetailValueObservableMapTest method testDetailObservableValuesAreDisposed.

@Test
public void testDetailObservableValuesAreDisposed() {
    final Map detailObservables = new HashMap();
    IObservableFactory detailValueFactory = target -> {
        WritableValue detailObservable = new WritableValue();
        // Remember the created observables.
        detailObservables.put(target, detailObservable);
        return detailObservable;
    };
    WritableMap masterMap = new WritableMap();
    MapDetailValueObservableMap mdom = new MapDetailValueObservableMap(masterMap, detailValueFactory, null);
    Object master1 = new Object();
    Object master2 = new Object();
    masterMap.put(master1, master1);
    masterMap.put(master2, master2);
    // Attach a listener in order to ensure that all detail observables are
    // actually created.
    MapChangeEventTracker.observe(mdom);
    assertEquals(mdom.size(), detailObservables.size());
    // No detail observables should be disposed yet.
    assertFalse(((WritableValue) detailObservables.get(master1)).isDisposed());
    assertFalse(((WritableValue) detailObservables.get(master2)).isDisposed());
    // Only the detail observable for the removed master should be disposed.
    masterMap.remove(master2);
    assertFalse(((WritableValue) detailObservables.get(master1)).isDisposed());
    assertTrue(((WritableValue) detailObservables.get(master2)).isDisposed());
    // After disposing the detail map, all detail observables should be
    // disposed.
    mdom.dispose();
    assertTrue(((WritableValue) detailObservables.get(master1)).isDisposed());
    assertTrue(((WritableValue) detailObservables.get(master2)).isDisposed());
}
Also used : MapChangeEventTracker(org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker) IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertNull(org.junit.Assert.assertNull) AbstractDefaultRealmTestCase(org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) BeansObservables(org.eclipse.core.databinding.beans.BeansObservables) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Assert.assertEquals(org.junit.Assert.assertEquals) WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) HashMap(java.util.HashMap) IObservableFactory(org.eclipse.core.databinding.observable.masterdetail.IObservableFactory) HashMap(java.util.HashMap) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) WritableMap(org.eclipse.core.databinding.observable.map.WritableMap) Map(java.util.Map) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) MapDetailValueObservableMap(org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap) Test(org.junit.Test)

Aggregations

IObservableFactory (org.eclipse.core.databinding.observable.masterdetail.IObservableFactory)8 Test (org.junit.Test)7 BeansObservables (org.eclipse.core.databinding.beans.BeansObservables)3 IObservableSet (org.eclipse.core.databinding.observable.set.IObservableSet)3 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)3 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)3 AbstractDefaultRealmTestCase (org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertNull (org.junit.Assert.assertNull)3 Assert.assertSame (org.junit.Assert.assertSame)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Realm (org.eclipse.core.databinding.observable.Realm)2 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)2 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)2 MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1