1 /*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.scene.control;
27
28 import com.sun.javafx.scene.control.VirtualScrollBar;
29 import com.sun.javafx.scene.control.behavior.ListCellBehavior;
30 import com.sun.javafx.tk.Toolkit;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.List;
35 import javafx.application.Platform;
36 import javafx.beans.binding.Bindings;
37 import javafx.beans.property.ObjectProperty;
38 import javafx.beans.property.ReadOnlyBooleanWrapper;
39 import javafx.beans.property.SimpleObjectProperty;
40 import javafx.collections.FXCollections;
41 import javafx.collections.ListChangeListener;
42 import javafx.collections.ObservableList;
43 import javafx.collections.transformation.SortedList;
44 import javafx.scene.control.Button;
45 import javafx.scene.control.FocusModel;
46 import javafx.scene.control.IndexedCell;
47 import javafx.scene.control.ListCell;
48 import javafx.scene.control.ListCellShim;
49 import javafx.scene.control.ListView;
50 import javafx.scene.control.ListViewShim;
51 import javafx.scene.control.MultipleSelectionModel;
52 import javafx.scene.control.SelectionMode;
53 import javafx.scene.control.SelectionModel;
54 import javafx.scene.control.TextField;
1812 assertEquals(0, (int) sm.getSelectedIndices().get(0));
1813 assertEquals("2", sm.getSelectedItems().get(0));
1814
1815 items.addAll("1", "3");
1816 assertEquals("2", sm.getSelectedItem());
1817 assertEquals(1, sm.getSelectedIndex());
1818 assertEquals(1, (int) sm.getSelectedIndices().get(0));
1819 assertEquals("2", sm.getSelectedItems().get(0));
1820 }
1821
1822 @Test public void test_jdk_8143594() {
1823 MultipleSelectionModel model = listView.getSelectionModel();
1824 model.setSelectionMode(SelectionMode.MULTIPLE);
1825
1826 listView.getItems().addAll("Apple", "Orange", null);
1827
1828 model.select(0);
1829 model.clearAndSelect(2);
1830 model.clearAndSelect(0);
1831 model.clearAndSelect(2);
1832 }
1833 }
|
1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.scene.control;
27
28 import com.sun.javafx.scene.control.VirtualScrollBar;
29 import com.sun.javafx.scene.control.behavior.ListCellBehavior;
30 import com.sun.javafx.tk.Toolkit;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.List;
35 import java.util.ListIterator;
36 import java.util.NoSuchElementException;
37 import javafx.application.Platform;
38 import javafx.beans.binding.Bindings;
39 import javafx.beans.property.ObjectProperty;
40 import javafx.beans.property.ReadOnlyBooleanWrapper;
41 import javafx.beans.property.SimpleObjectProperty;
42 import javafx.collections.FXCollections;
43 import javafx.collections.ListChangeListener;
44 import javafx.collections.ObservableList;
45 import javafx.collections.transformation.SortedList;
46 import javafx.scene.control.Button;
47 import javafx.scene.control.FocusModel;
48 import javafx.scene.control.IndexedCell;
49 import javafx.scene.control.ListCell;
50 import javafx.scene.control.ListCellShim;
51 import javafx.scene.control.ListView;
52 import javafx.scene.control.ListViewShim;
53 import javafx.scene.control.MultipleSelectionModel;
54 import javafx.scene.control.SelectionMode;
55 import javafx.scene.control.SelectionModel;
56 import javafx.scene.control.TextField;
1814 assertEquals(0, (int) sm.getSelectedIndices().get(0));
1815 assertEquals("2", sm.getSelectedItems().get(0));
1816
1817 items.addAll("1", "3");
1818 assertEquals("2", sm.getSelectedItem());
1819 assertEquals(1, sm.getSelectedIndex());
1820 assertEquals(1, (int) sm.getSelectedIndices().get(0));
1821 assertEquals("2", sm.getSelectedItems().get(0));
1822 }
1823
1824 @Test public void test_jdk_8143594() {
1825 MultipleSelectionModel model = listView.getSelectionModel();
1826 model.setSelectionMode(SelectionMode.MULTIPLE);
1827
1828 listView.getItems().addAll("Apple", "Orange", null);
1829
1830 model.select(0);
1831 model.clearAndSelect(2);
1832 model.clearAndSelect(0);
1833 model.clearAndSelect(2);
1834 }
1835
1836 @Test public void test_jdk_8145887_selectedIndices_ListIterator() {
1837 int selectIndices[] = { 4, 7, 9 };
1838 ListView<Integer> lv = new ListView<>();
1839 for (int i = 0; i < 10; ++i) {
1840 lv.getItems().add(i);
1841 }
1842
1843 MultipleSelectionModel msm = lv.getSelectionModel();
1844 msm.setSelectionMode(SelectionMode.MULTIPLE);
1845 for (int i = 0 ; i < selectIndices.length; ++i) {
1846 msm.select(selectIndices[i]);
1847 }
1848
1849 ListIterator iter = lv.getSelectionModel().getSelectedIndices().listIterator();
1850
1851 // Step 1. Initial values
1852 assertEquals(0, iter.nextIndex());
1853 assertEquals(-1, iter.previousIndex());
1854 assertEquals(true, iter.hasNext());
1855 assertEquals(false, iter.hasPrevious());
1856
1857 // Step 2. Iterate forward.
1858 assertEquals(4, iter.next());
1859 assertEquals(1, iter.nextIndex());
1860 assertEquals(0, iter.previousIndex());
1861 assertEquals(true, iter.hasNext());
1862 assertEquals(true, iter.hasPrevious());
1863
1864 // Step 3. Iterate forward.
1865 // Values would be at similar state of Step 2.
1866 assertEquals(7, iter.next());
1867
1868 // Step 4. Iterate forward to Last element.
1869 assertEquals(9, iter.next());
1870 assertEquals(3, iter.nextIndex());
1871 assertEquals(2, iter.previousIndex());
1872 assertEquals(false, iter.hasNext());
1873 assertEquals(true, iter.hasPrevious());
1874
1875 // Step 5. Verify NoSuchElementException by next()
1876 try {
1877 iter.next();
1878 } catch (Exception e) {
1879 assert(e instanceof NoSuchElementException);
1880 }
1881
1882 // Step 6. Iterate backward to Last element.
1883 assertEquals(9, iter.previous());
1884 assertEquals(2, iter.nextIndex());
1885 assertEquals(1, iter.previousIndex());
1886 assertEquals(true, iter.hasNext());
1887 assertEquals(true, iter.hasPrevious());
1888
1889 // Step 7. Iterate forward to Last element.
1890 assertEquals(9, iter.next());
1891 assertEquals(3, iter.nextIndex());
1892 assertEquals(2, iter.previousIndex());
1893 assertEquals(false, iter.hasNext());
1894 assertEquals(true, iter.hasPrevious());
1895
1896 // Step 8. Iterate forward to last element.
1897 // Values would be at Same state of Step 2.
1898 assertEquals(9, iter.previous());
1899
1900 // Step 9. Iterate backward.
1901 assertEquals(7, iter.previous());
1902 assertEquals(1, iter.nextIndex());
1903 assertEquals(0, iter.previousIndex());
1904 assertEquals(true, iter.hasNext());
1905 assertEquals(true, iter.hasPrevious());
1906
1907 // Step 10. Iterate back to first element.
1908 assertEquals(4, iter.previous());
1909 assertEquals(0, iter.nextIndex());
1910 assertEquals(-1, iter.previousIndex());
1911 assertEquals(true, iter.hasNext());
1912 assertEquals(false, iter.hasPrevious());
1913
1914 // Step 11. Verify NoSuchElementException by previous()
1915 try {
1916 iter.previous();
1917 } catch (Exception e) {
1918 assert(e instanceof NoSuchElementException);
1919 }
1920 }
1921 }
|