@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 (button == Mouse.Button.LEFT) {
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
&& selectMode == TableView.SelectMode.MULTI) {
Filter<?> disabledRowFilter = tableView.getDisabledRowFilter();
if (disabledRowFilter == null) {
// Select the range
int startIndex = tableView.getFirstSelectedIndex();
int endIndex = tableView.getLastSelectedIndex();
// if there is nothing currently selected, selected the indicated row
if (startIndex == -1) {
tableView.addSelectedIndex(rowIndex);
} else {
// otherwise select the range of rows
Span selectedRange = (rowIndex > startIndex) ?
new Span(startIndex, rowIndex) : new Span(rowIndex, endIndex);
ArrayList<Span> selectedRanges = new ArrayList<Span>();
selectedRanges.add(selectedRange);
tableView.setSelectedRanges(selectedRanges);
}
}
} else if (Keyboard.isPressed(commandModifier)
&& selectMode == TableView.SelectMode.MULTI) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.removeSelectedIndex(rowIndex);
} else {
tableView.addSelectedIndex(rowIndex);
}
} else if (Keyboard.isPressed(commandModifier)
&& selectMode == TableView.SelectMode.SINGLE) {
// Toggle the item's selection state
if (tableView.isRowSelected(rowIndex)) {
tableView.setSelectedIndex(-1);
} else {
tableView.setSelectedIndex(rowIndex);
}
} else {
if (selectMode != TableView.SelectMode.NONE) {
if (tableView.isRowSelected(rowIndex)) {
selectIndex = rowIndex;
} else {
tableView.setSelectedIndex(rowIndex);
}
}
}
}
}
tableView.requestFocus();
return consumed;
}