private ListenerList<EnableListener> enableListeners = new ListenerList<EnableListener>();
private int[] sortedRows;
+
+ private boolean showEnabled = true;
private static final Comparator<? super String> VALUE_COMPARATOR = (a, b) -> {
try {
public TechTypeTableDataProvider(String data, int[] enabledList) {
setData(data);
setEnabledFlags(enabledList);
+ showEnabled = enabledList != null;
}
public TechTypeTableDataProvider(String data) {
- // load csv
setData(data);
+ showEnabled = false;
}
public void setEnabledFlags(int[] enabledList) {
enabled[i] = true;
}
}
+
+ showEnabled = enabledList != null;
+ }
+
+ public boolean isCheckBoxColumn(int columnIndex) {
+ return isEnabledColumn(columnIndex);
}
public String getVariableName(int columnIndex) {
- return variables != null && columnIndex > 0 && columnIndex <= variables.size() ? variables.get(columnIndex - 1) : null;
+ return variables != null && columnIndex > 0 && columnIndex <= variables.size()
+ ? variables.get(columnIndex - columnOffset())
+ : null;
}
+ private int columnOffset() {
+ return showEnabled ? 1 : 0;
+ }
+
public int getVariableIndex(String variableName) {
- return variables != null ? variables.indexOf(variableName) + 1 : -1;
+ return variables != null ? variables.indexOf(variableName) + columnOffset() : -1;
}
public CSVRecord getRecord(int rowIndex) {
public String getHeaderValue(int columnIndex) {
if (headers == null) {
return "<empty>";
- } else if (columnIndex == 0) {
+ } else if (isEnabledColumn(columnIndex)) {
return "Enabled";
} else {
- return headers.get(columnIndex - 1);
+ return headers.get(columnIndex - columnOffset());
}
}
@Override
public Object getDataValue(int columnIndex, int rowIndex) {
- if (columnIndex == 0) {
+ if (isEnabledColumn(columnIndex)) {
return isEnabled(rowIndex);
}
- return getRecord(rowIndex).get(columnIndex - 1);
+ return getRecord(rowIndex).get(columnIndex - columnOffset());
}
@Override
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
- if (columnIndex == 0) {
+ if (isEnabledColumn(columnIndex)) {
boolean value = Boolean.parseBoolean((String) newValue);
enabled[recordIndex(rowIndex)] = value;
fireEnableEvent(rowIndex, value);
if (records.isEmpty()) {
return 0;
}
- return records.get(0).size() + 1;
+ return records.get(0).size() + columnOffset();
}
@Override
}
public boolean isEditable(int columnIndex, int rowIndex) {
- return columnIndex == 0;
+ return isEnabledColumn(columnIndex);
}
+ private boolean isEnabledColumn(int columnIndex) {
+ return showEnabled && columnIndex == 0;
+ }
+
public void setFilter(String text) {
this.filter = text != null ? text.toLowerCase() : null;
public void sortBy(int columnIndex, SortDirectionEnum sortDirection) {
if (columnIndex >= 0 && !sortDirection.equals(SortDirectionEnum.NONE)) {
- Comparator<Integer> comparator = columnIndex == 0 ?
+ int offset = columnOffset();
+ Comparator<Integer> comparator = isEnabledColumn(columnIndex) ?
Comparator.comparing(k -> enabled[sortedRows[(int) k]]) :
- Comparator.comparing(k -> records.get(sortedRows[(int) k]).get(columnIndex-1), VALUE_COMPARATOR);
+ Comparator.comparing(k -> records.get(sortedRows[(int) k]).get(columnIndex-offset), VALUE_COMPARATOR);
if (sortDirection.equals(SortDirectionEnum.DESC))
comparator = comparator.reversed();