@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
TableView tableView = (TableView)getComponent();
int rowIndex = getRowAt(y);
if (rowIndex >= 0
&& !tableView.isRowDisabled(rowIndex)) {
TableView.SelectMode selectMode = tableView.getSelectMode();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
&& selectMode == TableView.SelectMode.MULTI) {
// Select the range
int startIndex = tableView.getFirstSelectedIndex();
int endIndex = tableView.getLastSelectedIndex();
Span selectedRange = (rowIndex > startIndex) ?
new Span(startIndex, rowIndex) : new Span(rowIndex, endIndex);
ArrayList<Span> selectedRanges = new ArrayList<Span>();
Sequence<Integer> disabledIndexes = tableView.getDisabledIndexes();
if (disabledIndexes.getLength() == 0) {
selectedRanges.add(selectedRange);
} else {
// TODO Split the range by the disabled indexes; for now,
// just return
return consumed;
}
tableView.setSelectedRanges(selectedRanges);
} else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)
&& selectMode == TableView.SelectMode.MULTI) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.removeSelectedIndex(rowIndex);
} else {
tableView.addSelectedIndex(rowIndex);
}
} else {
if (selectMode != TableView.SelectMode.NONE) {
if (tableView.isRowSelected(rowIndex)
&& tableView.isFocused()) {
// Edit the row
editIndex = rowIndex;
} else {
// Select the row
tableView.setSelectedIndex(rowIndex);
}
}
}
}
if (tableView.isFocusable()) {
tableView.requestFocus();
}
return consumed;
}