Search in sources :

Example 1 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class FXBinderTest method testCorrectUnbind.

@Test
public void testCorrectUnbind() {
    ObservableList<String> dolphinList = new ObservableArrayList<>();
    ObservableList<String> dolphinList2 = new ObservableArrayList<>();
    javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
    Binding binding = FXBinder.bind(javaFXList).to(dolphinList);
    dolphinList.add("Foo");
    assertEquals(dolphinList.size(), 1);
    assertEquals(dolphinList2.size(), 0);
    assertEquals(javaFXList.size(), 1);
    binding.unbind();
    FXBinder.bind(javaFXList).to(dolphinList2);
    assertEquals(dolphinList.size(), 1);
    assertEquals(dolphinList2.size(), 0);
    assertEquals(javaFXList.size(), 0);
    dolphinList2.add("Foo");
    dolphinList2.add("Bar");
    assertEquals(dolphinList.size(), 1);
    assertEquals(dolphinList2.size(), 2);
    assertEquals(javaFXList.size(), 2);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 2 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class FXBinderTest method severalBindings.

@Test
public void severalBindings() {
    ObservableList<String> dolphinList1 = new ObservableArrayList<>();
    ObservableList<String> dolphinList2 = new ObservableArrayList<>();
    ObservableList<String> dolphinList3 = new ObservableArrayList<>();
    ObservableList<String> dolphinList4 = new ObservableArrayList<>();
    javafx.collections.ObservableList<String> javaFXList1 = FXCollections.observableArrayList();
    javafx.collections.ObservableList<String> javaFXList2 = FXCollections.observableArrayList();
    javafx.collections.ObservableList<String> javaFXList3 = FXCollections.observableArrayList();
    javafx.collections.ObservableList<String> javaFXList4 = FXCollections.observableArrayList();
    Binding binding1 = FXBinder.bind(javaFXList1).to(dolphinList1);
    Binding binding2 = FXBinder.bind(javaFXList2).to(dolphinList2);
    Binding binding3 = FXBinder.bind(javaFXList3).to(dolphinList3);
    Binding binding4 = FXBinder.bind(javaFXList4).to(dolphinList4);
    binding1.unbind();
    binding2.unbind();
    binding1 = FXBinder.bind(javaFXList1).to(dolphinList2);
    binding2 = FXBinder.bind(javaFXList2).to(dolphinList1);
    binding3.unbind();
    binding4.unbind();
    binding3 = FXBinder.bind(javaFXList3).to(dolphinList4);
    binding4 = FXBinder.bind(javaFXList4).to(dolphinList3);
    binding1.unbind();
    binding2.unbind();
    binding3.unbind();
    binding4.unbind();
    binding1 = FXBinder.bind(javaFXList1).to(dolphinList4);
    binding2 = FXBinder.bind(javaFXList2).to(dolphinList3);
    binding3 = FXBinder.bind(javaFXList3).to(dolphinList2);
    binding4 = FXBinder.bind(javaFXList4).to(dolphinList1);
    binding1.unbind();
    binding2.unbind();
    binding3.unbind();
    binding4.unbind();
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 3 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class FXBinderTest method testListBindingWithNonEmptyLists.

@Test
public void testListBindingWithNonEmptyLists() {
    ObservableList<String> dolphinList = new ObservableArrayList<>();
    javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
    dolphinList.addAll(Arrays.asList("A", "B", "C"));
    Binding binding1 = FXBinder.bind(javaFXList).to(dolphinList);
    assertEquals(dolphinList.size(), 3);
    assertEquals(javaFXList.size(), 3);
    assertTrue(dolphinList.contains("A"));
    assertTrue(dolphinList.contains("B"));
    assertTrue(dolphinList.contains("C"));
    assertTrue(javaFXList.contains("A"));
    assertTrue(javaFXList.contains("B"));
    assertTrue(javaFXList.contains("C"));
    binding1.unbind();
    dolphinList.clear();
    javaFXList.clear();
    javaFXList.addAll("A", "B", "C");
    Binding binding2 = FXBinder.bind(javaFXList).to(dolphinList);
    assertEquals(dolphinList.size(), 0);
    assertEquals(javaFXList.size(), 0);
    binding2.unbind();
    dolphinList.clear();
    javaFXList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C"));
    javaFXList.addAll("D", "E", "F");
    FXBinder.bind(javaFXList).to(dolphinList);
    assertEquals(dolphinList.size(), 3);
    assertEquals(javaFXList.size(), 3);
    assertTrue(dolphinList.contains("A"));
    assertTrue(dolphinList.contains("B"));
    assertTrue(dolphinList.contains("C"));
    assertTrue(javaFXList.contains("A"));
    assertTrue(javaFXList.contains("B"));
    assertTrue(javaFXList.contains("C"));
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 4 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class TestObservableArrayList method testListIterator.

@Test
public void testListIterator() {
    final AtomicBoolean removed = new AtomicBoolean(false);
    final AtomicBoolean added = new AtomicBoolean(false);
    final AtomicInteger callCount = new AtomicInteger(0);
    final ObservableArrayList<String> list = new ObservableArrayList<>();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals(list.size(), 0);
    addOnChangeListener(removed, added, callCount, list);
    list.addAll("1", "2", "3", "4", "5");
    ListIterator<String> iterator = list.listIterator();
    Assert.assertTrue(iterator.nextIndex() == 0);
    String current = iterator.next();
    Assert.assertTrue(current.equals("1"));
    Assert.assertTrue(iterator.nextIndex() == 1);
    current = iterator.next();
    Assert.assertTrue(current.equals("2"));
    Assert.assertTrue(iterator.nextIndex() == 2);
    current = iterator.previous();
    Assert.assertTrue(current.equals("2"));
    Assert.assertTrue(iterator.previousIndex() == 0);
    // Add using iterator
    iterator.add("Test");
    Assert.assertTrue(added.get());
    Assert.assertFalse(removed.get());
    Assert.assertEquals(list.size(), 6);
    current = iterator.previous();
    Assert.assertTrue(current.equals("Test"));
    Assert.assertTrue(iterator.nextIndex() == 1);
    // Remove using iterator
    iterator.remove();
    Assert.assertFalse(added.get());
    Assert.assertTrue(removed.get());
    Assert.assertEquals(list.size(), 5);
    current = iterator.next();
    Assert.assertTrue(current.equals("2"));
    Assert.assertTrue(iterator.nextIndex() == 2);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 5 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class TestObservableArrayListWriteOperations method removeListener_shouldNotFireListener.

// TODO: removeAll, retainAll
// ////////////////////////////////////////
// add(Object)
// ////////////////////////////////////////
@Test
public void removeListener_shouldNotFireListener() {
    final ObservableArrayList<String> list = new ObservableArrayList<>();
    final TestListChangeListener listener = new TestListChangeListener();
    final Subscription subscription = list.onChanged(listener);
    subscription.unsubscribe();
    list.add("42");
    assertThat(listener.calls, is(0));
}
Also used : ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Subscription(com.canoo.platform.core.functional.Subscription) Test(org.testng.annotations.Test)

Aggregations

ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)11 Test (org.testng.annotations.Test)11 Binding (com.canoo.platform.core.functional.Binding)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Subscription (com.canoo.platform.core.functional.Subscription)2