| 1 |
|
package org.kuali.student.common.ui.client.widgets.table.scroll; |
| 2 |
|
|
| 3 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
| 4 |
|
import com.google.gwt.event.dom.client.ClickHandler; |
| 5 |
|
import com.google.gwt.user.client.DOM; |
| 6 |
|
import com.google.gwt.user.client.ui.CheckBox; |
| 7 |
|
|
| 8 |
|
import java.util.ArrayList; |
| 9 |
|
import java.util.Collections; |
| 10 |
|
import java.util.List; |
| 11 |
|
|
|
|
|
| 0% |
Uncovered Elements: 117 (117) |
Complexity: 36 |
Complexity Density: 0.53 |
|
| 12 |
|
public class DefaultTableModel extends AbstractTableModel { |
| 13 |
|
private ArrayList<Column> columnList = new ArrayList<Column>(); |
| 14 |
|
private ArrayList<Row> rowList = new ArrayList<Row>(); |
| 15 |
|
private ArrayList<Column> sortedColumnList = new ArrayList<Column>(); |
| 16 |
|
private int sortableColumnCount = 1; |
| 17 |
|
private boolean moreData = true; |
| 18 |
|
private boolean multipleSelectable = true; |
| 19 |
|
private int currentRowIndex; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
Column rowHeader = new Column(); |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
| 24 |
0
|
public void installCheckBoxRowHeaderColumn() {... |
| 25 |
0
|
columnList.remove(rowHeader); |
| 26 |
0
|
rowHeader.setId("RowHeader"); |
| 27 |
0
|
rowHeader.setName("RowHeader"); |
| 28 |
0
|
final CheckBox checkBox = new CheckBox(); |
| 29 |
0
|
checkBox.setTabIndex(-1); |
| 30 |
0
|
checkBox.addClickHandler(new ClickHandler() { |
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 31 |
0
|
@Override... |
| 32 |
|
public void onClick(ClickEvent event) { |
| 33 |
0
|
int count = getRowCount(); |
| 34 |
0
|
for (int i = 0; i < count; i++) { |
| 35 |
0
|
getRow(i).setSelected(checkBox.getValue()); |
| 36 |
|
} |
| 37 |
0
|
fireTableDataChanged(); |
| 38 |
|
} |
| 39 |
|
}); |
| 40 |
0
|
DOM.setStyleAttribute(checkBox.getElement(), "style", "padding-right: 0.8em"); |
| 41 |
0
|
rowHeader.setColumnTitleWidget(checkBox); |
| 42 |
0
|
rowHeader.setWidth("40px"); |
| 43 |
0
|
rowHeader.setVisible(true); |
| 44 |
|
|
| 45 |
0
|
columnList.add(0, rowHeader); |
| 46 |
|
} |
| 47 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 48 |
0
|
public void addRow(Row row) {... |
| 49 |
0
|
rowList.add(row); |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
0
|
public void insertRow(int index, Row row) {... |
| 53 |
0
|
rowList.add(index, row); |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 56 |
0
|
public void addColumn(Column col) {... |
| 57 |
0
|
columnList.add(col); |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 60 |
0
|
public void insertColumn(int index, Column col) {... |
| 61 |
0
|
columnList.add(index, col); |
| 62 |
|
} |
| 63 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
0
|
public boolean isMultipleSelectable() {... |
| 65 |
0
|
return multipleSelectable; |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
| 68 |
0
|
@Override... |
| 69 |
|
public void setCurrentIndex(int index) { |
| 70 |
0
|
if (index != currentRowIndex && currentRowIndex != -1){ |
| 71 |
0
|
if(currentRowIndex < rowList.size()){ |
| 72 |
0
|
rowList.get(currentRowIndex).setHighlighted(false); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
0
|
currentRowIndex = index; |
| 76 |
|
} |
| 77 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 78 |
0
|
@Override... |
| 79 |
|
public int getCurrentIndex() { |
| 80 |
0
|
return currentRowIndex; |
| 81 |
|
} |
| 82 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 83 |
0
|
@Override... |
| 84 |
|
public void setSelectedRow(int index) { |
| 85 |
0
|
for (int rowIndex = 0; rowIndex < getRowCount(); rowIndex++) { |
| 86 |
0
|
Row currentRow = rowList.get(rowIndex); |
| 87 |
0
|
if (rowIndex == index) { |
| 88 |
0
|
currentRow.setSelected(true); |
| 89 |
0
|
} else if (!isMultipleSelectable()) { |
| 90 |
0
|
currentRow.setSelected(false); |
| 91 |
|
} |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
0
|
public void setMultipleSelectable(boolean value) {... |
| 96 |
0
|
multipleSelectable = value; |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
0
|
public void setMoreData(boolean hasMoreData) {... |
| 100 |
0
|
moreData = hasMoreData; |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 103 |
0
|
public boolean getMoreData() {... |
| 104 |
0
|
return moreData; |
| 105 |
|
} |
| 106 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
0
|
public int getRowCount() {... |
| 108 |
0
|
return rowList.size(); |
| 109 |
|
} |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 111 |
0
|
public void sort(Column column) {... |
| 112 |
0
|
if (column.isSortable() == false) { |
| 113 |
0
|
return; |
| 114 |
|
} |
| 115 |
0
|
if (sortedColumnList.contains(column) == false) { |
| 116 |
0
|
if (sortedColumnList.size() >= sortableColumnCount) { |
| 117 |
0
|
Column removed = sortedColumnList.remove(0); |
| 118 |
0
|
removed.setSortDirection(Column.NotOrdered); |
| 119 |
|
} |
| 120 |
0
|
sortedColumnList.add(column); |
| 121 |
|
|
| 122 |
|
} |
| 123 |
|
|
| 124 |
0
|
column.changeSortDirection(); |
| 125 |
0
|
RowComparator comparator = column.getComparator(); |
| 126 |
0
|
if (comparator != null) { |
| 127 |
0
|
Collections.sort(rowList, comparator); |
| 128 |
|
} |
| 129 |
0
|
super.fireTableStructureChanged(); |
| 130 |
|
} |
| 131 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 132 |
0
|
public Row getRow(int rowIndex) {... |
| 133 |
0
|
return rowList.get(rowIndex); |
| 134 |
|
} |
| 135 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 136 |
0
|
public List<Row> getSelectedRows() {... |
| 137 |
0
|
ArrayList<Row> selectedRows = new ArrayList<Row>(); |
| 138 |
0
|
for (Row row : rowList) { |
| 139 |
0
|
if (row.isSelected()) { |
| 140 |
0
|
selectedRows.add(row); |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
0
|
return selectedRows; |
| 144 |
|
} |
| 145 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 146 |
0
|
public Column getColumn(int columnIndex) {... |
| 147 |
0
|
ArrayList<Column> list = new ArrayList<Column>(); |
| 148 |
0
|
for (Column col : columnList) { |
| 149 |
0
|
if (col.isVisible()) { |
| 150 |
0
|
list.add(col); |
| 151 |
|
} |
| 152 |
|
} |
| 153 |
0
|
return list.get(columnIndex); |
| 154 |
|
} |
| 155 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 156 |
0
|
public int getColumnCount() {... |
| 157 |
0
|
int count = 0; |
| 158 |
0
|
for (Column col : columnList) { |
| 159 |
0
|
if (col.isVisible()) { |
| 160 |
0
|
count++; |
| 161 |
|
} |
| 162 |
|
} |
| 163 |
0
|
return count; |
| 164 |
|
} |
| 165 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 166 |
0
|
public void clearRows() {... |
| 167 |
0
|
rowList = new ArrayList<Row>(); |
| 168 |
0
|
super.fireTableDataChanged(); |
| 169 |
|
} |
| 170 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 171 |
0
|
public void selectFirstRow() {... |
| 172 |
0
|
if (!rowList.isEmpty()) { |
| 173 |
0
|
currentRowIndex = 0; |
| 174 |
0
|
rowList.get(0).setHighlighted(true); |
| 175 |
|
} |
| 176 |
|
} |
| 177 |
|
} |