Search in sources :

Example 1 with ListDetailValueObservableList

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

the class ListDetailValueObservableListTest method testUnmodifiability.

@Test
public void testUnmodifiability() {
    WritableList masterObservableList = new WritableList();
    masterObservableList.add(new SimplePerson());
    masterObservableList.add(new SimplePerson());
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterObservableList, BeansObservables.valueFactory("name"), null);
    try {
        ldol.add("name");
        fail("ListDetailValueObservableList must not be modifiable.");
    } catch (UnsupportedOperationException e) {
    // expected exception
    }
    try {
        ldol.remove(masterObservableList.get(0));
        fail("ListDetailValueObservableList must not be modifiable.");
    } catch (UnsupportedOperationException e) {
    // expected exception
    }
    try {
        ldol.removeAll(Collections.singleton(masterObservableList.get(0)));
        fail("ListDetailValueObservableList must not be modifiable.");
    } catch (UnsupportedOperationException e) {
    // expected exception
    }
    try {
        ldol.retainAll(Collections.EMPTY_LIST);
        fail("ListDetailValueObservableList must not be modifiable.");
    } catch (UnsupportedOperationException e) {
    // expected exception
    }
    try {
        ldol.move(0, 1);
        fail("ListDetailValueObservableList must not be modifiable.");
    } catch (UnsupportedOperationException e) {
    // expected exception
    }
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 2 with ListDetailValueObservableList

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

the class ListDetailValueObservableListTest method testDuplicateMasterElements.

@Test
public void testDuplicateMasterElements() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    SimplePerson master = new SimplePerson();
    master.setName("name1");
    // Add the same master twice.
    masterList.add(master);
    masterList.add(master);
    // Attach the change listener to the detail list.
    ListChangeEventTracker changeTracker = ListChangeEventTracker.observe(ldol);
    // Setting the name on master should trigger an event on both
    // occurrences of in the master list.
    master.setName("name2");
    // We should have 2 replace diffs, i.e. 4 diff entries.
    assertEquals(1, changeTracker.count);
    assertEquals(4, changeTracker.event.diff.getDifferences().length);
    assertReplaceDiffAt(changeTracker.event.diff, 0, 0, "name1", "name2");
    assertReplaceDiffAt(changeTracker.event.diff, 2, 0, "name1", "name2");
    // Remove one instance of the master (one will remain).
    masterList.remove(master);
    // It should still be possible to work on the remaining master instance.
    ldol.set(0, "name3");
    assertEquals("name3", master.getName());
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) ListChangeEventTracker(org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker) SimplePerson(org.eclipse.jface.examples.databinding.model.SimplePerson) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 3 with ListDetailValueObservableList

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

the class ListDetailValueObservableListTest method testGetElementType.

@Test
public void testGetElementType() {
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(new WritableList(), BeansObservables.valueFactory("name"), String.class);
    assertSame(String.class, ldol.getElementType());
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 4 with ListDetailValueObservableList

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

the class ListDetailValueObservableListTest method testGetObserved.

@Test
public void testGetObserved() {
    WritableList masterList = new WritableList();
    ListDetailValueObservableList ldol = new ListDetailValueObservableList(masterList, BeansObservables.valueFactory("name"), String.class);
    // The observed object is the master list.
    assertSame(masterList, ldol.getObserved());
}
Also used : WritableList(org.eclipse.core.databinding.observable.list.WritableList) ListDetailValueObservableList(org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList) Test(org.junit.Test) ObservableListContractTest(org.eclipse.jface.databinding.conformance.ObservableListContractTest)

Example 5 with ListDetailValueObservableList

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

the class ListDetailValueObservableListTest method testDisposeOnMasterDisposed.

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

Aggregations

WritableList (org.eclipse.core.databinding.observable.list.WritableList)12 ListDetailValueObservableList (org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList)12 ObservableListContractTest (org.eclipse.jface.databinding.conformance.ObservableListContractTest)12 Test (org.junit.Test)12 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)8 ListChangeEventTracker (org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker)3 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 BeansObservables (org.eclipse.core.databinding.beans.BeansObservables)1 IObservable (org.eclipse.core.databinding.observable.IObservable)1 IObservableCollection (org.eclipse.core.databinding.observable.IObservableCollection)1 Realm (org.eclipse.core.databinding.observable.Realm)1 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)1 ListDiff (org.eclipse.core.databinding.observable.list.ListDiff)1 ListDiffEntry (org.eclipse.core.databinding.observable.list.ListDiffEntry)1 IObservableFactory (org.eclipse.core.databinding.observable.masterdetail.IObservableFactory)1 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)1 AbstractObservableCollectionContractDelegate (org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate)1 TestCollection (org.eclipse.jface.databinding.conformance.util.TestCollection)1