@Override
@SuppressWarnings("unchecked")
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
ListView listView = (ListView)getComponent();
List<Object> listData = (List<Object>)listView.getListData();
int itemHeight = getItemHeight();
int itemIndex = y / itemHeight;
if (itemIndex < listData.getLength()
&& !listView.isItemDisabled(itemIndex)) {
int itemY = itemIndex * itemHeight;
if (!(listView.getCheckmarksEnabled()
&& x > checkboxPadding.left
&& x < checkboxPadding.left + CHECKBOX.getWidth()
&& y > itemY + checkboxPadding.top
&& y < itemY + checkboxPadding.top + CHECKBOX.getHeight())) {
ListView.SelectMode selectMode = listView.getSelectMode();
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
&& selectMode == ListView.SelectMode.MULTI) {
// Select the range
int startIndex = listView.getFirstSelectedIndex();
int endIndex = listView.getLastSelectedIndex();
Span selectedRange = (itemIndex > startIndex) ?
new Span(startIndex, itemIndex) : new Span(itemIndex, endIndex);
ArrayList<Span> selectedRanges = new ArrayList<Span>();
Sequence<Integer> disabledIndexes = listView.getDisabledIndexes();
if (disabledIndexes.getLength() == 0) {
selectedRanges.add(selectedRange);
} else {
// TODO Split the range by the disabled indexes; for now,
// just return
return consumed;
}
listView.setSelectedRanges(selectedRanges);
} else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)
&& selectMode == ListView.SelectMode.MULTI) {
// Toggle the item's selection state
if (listView.isItemSelected(itemIndex)) {
listView.removeSelectedIndex(itemIndex);
} else {
listView.addSelectedIndex(itemIndex);
}
} else {
if (selectMode != ListView.SelectMode.NONE) {
if (listView.isItemSelected(itemIndex)
&& listView.isFocused()) {
// Edit the item
editIndex = itemIndex;
} else {
// Select the item
listView.setSelectedIndex(itemIndex);
}
}
}
}
}
if (listView.isFocusable()) {
listView.requestFocus();
}
return consumed;
}