Skip to content

Commit 07af89a

Browse files
Jeanette Winzenburgaghaisas
authored andcommitted
8221334: TableViewSkin: must initialize flow's cellCount in constructor
Reviewed-by: aghaisas
1 parent 4ddf554 commit 07af89a

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/skin/TableViewSkin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public TableViewSkin(final TableView<T> control) {
133133

134134
registerChangeListener(control.fixedCellSizeProperty(), e -> flow.setFixedCellSize(getSkinnable().getFixedCellSize()));
135135

136+
updateItemCount();
136137
}
137138

138139

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2019, 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.skin;
27+
28+
import java.util.Arrays;
29+
import java.util.List;
30+
import java.util.Locale;
31+
import java.util.stream.Collectors;
32+
33+
import org.junit.Test;
34+
35+
import static org.junit.Assert.*;
36+
37+
import javafx.collections.FXCollections;
38+
import javafx.scene.control.ListView;
39+
import javafx.scene.control.TableView;
40+
import javafx.scene.control.TreeItem;
41+
import javafx.scene.control.TreeTableView;
42+
import javafx.scene.control.TreeView;
43+
import javafx.scene.control.skin.ListViewSkin;
44+
import javafx.scene.control.skin.TableViewSkin;
45+
import javafx.scene.control.skin.TreeTableViewSkin;
46+
import javafx.scene.control.skin.TreeViewSkin;
47+
48+
/**
49+
* Contains tests that should pass for all concrete implementations
50+
* of VirtualContainerBase.
51+
*/
52+
public class ConcreteVirtualContainerTest {
53+
54+
/**
55+
* Test for JDK-8221334: flow's cellCount must be initialized.
56+
*/
57+
@Test
58+
public void testTableSkinCellCountInitial() {
59+
TableView<Locale> control = new TableView<>(FXCollections.observableArrayList(Locale.getAvailableLocales()));
60+
control.setSkin(new TableViewSkin<>(control) {
61+
{
62+
assertEquals("flow's cellCount must be initialized", control.getItems().size(),
63+
getVirtualFlow().getCellCount());
64+
}
65+
});
66+
}
67+
68+
@Test
69+
public void testTreeTableSkinCellCountInitial() {
70+
List<TreeItem<Locale>> treeItems = Arrays.stream(Locale.getAvailableLocales())
71+
.map(TreeItem::new)
72+
.collect(Collectors.toList());
73+
TreeItem<Locale> root = new TreeItem<>(new Locale("dummy"));
74+
root.setExpanded(true);
75+
root.getChildren().addAll(treeItems);
76+
TreeTableView<Locale> control = new TreeTableView<>(root);
77+
control.setSkin(new TreeTableViewSkin<>(control) {
78+
{
79+
assertEquals("flow's cellCount must be initialized", treeItems.size() + 1,
80+
getVirtualFlow().getCellCount());
81+
}
82+
});
83+
}
84+
85+
@Test
86+
public void testTreeSkinCellCountInitial() {
87+
List<TreeItem<Locale>> treeItems = Arrays.stream(Locale.getAvailableLocales())
88+
.map(TreeItem::new)
89+
.collect(Collectors.toList());
90+
TreeItem<Locale> root = new TreeItem<>(new Locale("dummy"));
91+
root.setExpanded(true);
92+
root.getChildren().addAll(treeItems);
93+
TreeView<Locale> control = new TreeView<>(root);
94+
control.setSkin(new TreeViewSkin<>(control) {
95+
{
96+
assertEquals("flow's cellCount must be initialized", treeItems.size() +1,
97+
getVirtualFlow().getCellCount());
98+
}
99+
});
100+
}
101+
102+
@Test
103+
public void testListSkinCellCountInitial() {
104+
ListView<Locale> control = new ListView<>(FXCollections.observableArrayList(Locale.getAvailableLocales()));
105+
control.setSkin(new ListViewSkin<>(control) {
106+
{
107+
assertEquals("flow's cellCount must be initialized", control.getItems().size(),
108+
getVirtualFlow().getCellCount());
109+
}
110+
});
111+
}
112+
}

0 commit comments

Comments
 (0)