Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTable/DefaultRowSorterCacheTest.java
41149 views
1
/*
2
* Copyright (c) 2018, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @key headful
27
* @bug 7007967
28
* @summary Verifies that DefaultRowSorter updates its cache properly when the
29
* all the row are deleted and then new rows are added to the table
30
* @run main DefaultRowSorterCacheTest
31
*/
32
33
34
import javax.swing.table.DefaultTableModel;
35
import javax.swing.table.TableRowSorter;
36
import javax.swing.SwingUtilities;
37
38
class CustomTableModel extends DefaultTableModel
39
{
40
public CustomTableModel(Object[][] data, Object[] columnNames) {
41
super(data, columnNames);
42
}
43
44
@Override
45
public Class<?> getColumnClass(int columnIndex) {
46
if (getRowCount() > 0) {
47
return getValueAt(0, columnIndex).getClass();
48
}
49
return super.getColumnClass(columnIndex);
50
}
51
}
52
53
public class DefaultRowSorterCacheTest {
54
55
public void testSort() {
56
Object[] values = new Object[]{1, 2, 10};
57
Object[][] data = new Object[][]{{values[0]}, {values[1]}, {values[2]}};
58
59
//Create custom table model
60
DefaultTableModel model = new CustomTableModel(data, new Object[]{"A"});
61
62
TableRowSorter<DefaultTableModel> rowSorter =
63
new TableRowSorter<DefaultTableModel>(model);
64
rowSorter.toggleSortOrder(0);
65
66
for (int row = 0; row < model.getRowCount(); row++) {
67
// values are in sorted ascending. so the row index and
68
// view index from sorter should be same
69
if (row != rowSorter.convertRowIndexToView(row)) {
70
throw new RuntimeException("Wrong sorting before making any " +
71
"changes in test case");
72
}
73
}
74
75
// clear model and notify sorter
76
model.setRowCount(0);
77
rowSorter.rowsDeleted(0, values.length - 1);
78
79
// refill the model and notify sorter
80
for (int i = 0; i < values.length; i++) {
81
model.addRow(new Object[]{values[i]});
82
rowSorter.rowsInserted(i, i);
83
}
84
85
for (int row = 0; row < model.getRowCount(); row++) {
86
// values are in sorted ascending. so the row index and
87
// view index from sorter should be same
88
if (row != rowSorter.convertRowIndexToView(row)) {
89
throw new RuntimeException("Wrong sorting at end of test case");
90
}
91
}
92
}
93
94
public static void main(String[] args) throws Exception{
95
SwingUtilities.invokeAndWait(new Runnable() {
96
@Override
97
public void run() {
98
new DefaultRowSorterCacheTest().testSort();
99
}
100
});
101
}
102
}
103
104