@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
ListView listView = (ListView)getComponent();
int itemIndex = getItemAt(y);
if (itemIndex != -1
&& !listView.isItemDisabled(itemIndex)) {
if (!listView.getCheckmarksEnabled()
|| listView.isCheckmarkDisabled(itemIndex)
|| !getCheckboxBounds(itemIndex).contains(x, y)) {
ListView.SelectMode selectMode = listView.getSelectMode();
if (button == Mouse.Button.LEFT) {
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
&& selectMode == ListView.SelectMode.MULTI) {
Filter<?> disabledItemFilter = listView.getDisabledItemFilter();
if (disabledItemFilter == null) {
// Select the range
ArrayList<Span> selectedRanges = new ArrayList<Span>();
int startIndex = listView.getFirstSelectedIndex();
int endIndex = listView.getLastSelectedIndex();
Span selectedRange = (itemIndex > startIndex) ?
new Span(startIndex, itemIndex) : new Span(itemIndex, endIndex);
selectedRanges.add(selectedRange);
listView.setSelectedRanges(selectedRanges);
}
} else if (Keyboard.isPressed(commandModifier)
&& selectMode == ListView.SelectMode.MULTI) {
// Toggle the item's selection state
if (listView.isItemSelected(itemIndex)) {
listView.removeSelectedIndex(itemIndex);
} else {
listView.addSelectedIndex(itemIndex);
}
} else if (Keyboard.isPressed(commandModifier)
&& selectMode == ListView.SelectMode.SINGLE) {
// Toggle the item's selection state
if (listView.isItemSelected(itemIndex)) {
listView.setSelectedIndex(-1);
} else {
listView.setSelectedIndex(itemIndex);
}
} else {
if (selectMode != ListView.SelectMode.NONE) {
if (listView.isItemSelected(itemIndex)) {
selectIndex = itemIndex;
} else {
listView.setSelectedIndex(itemIndex);
}
}
}
}
}
}
listView.requestFocus();
return consumed;
}