}
}
}
protected void onMouseDown(NativeEvent e) {
XEvent xe = e.<XEvent> cast();
Element target = e.getEventTarget().cast();
TreeNode<M> node = tree.findNode(target);
if (node == null) {
return;
}
M item = (M) node.getModel();
if (item == null) return;
if (!tree.getView().isSelectableTarget(item, target)) {
return;
}
if (e.<XEvent> cast().isRightClick() && isSelected((M) item)) {
return;
}
M sel = item;
switch (selectionMode) {
case SIMPLE:
if (isSelected(sel)) {
deselect(sel);
} else {
doSelect(Collections.singletonList(sel), true, false);
}
break;
case SINGLE:
tree.focus();
doSingleSelect(sel, false);
break;
case MULTI:
if (isSelected(sel) && !xe.getCtrlOrMetaKey() && !e.getShiftKey()) {
return;
}
if (e.getShiftKey() && lastSelected != null) {
List<M> items = new ArrayList<M>();
if (lastSelected == sel) {
return;
}
TreeNode<M> selNode = tree.findNode(lastSelected);
TreeNode<M> itemNode = tree.findNode(sel);
if (selNode.getElement() != null && itemNode.getElement() != null) {
if (selNode.getElement().getAbsoluteTop() < itemNode.getElement().getAbsoluteTop()) {
M next = next();
while (next != null) {
items.add(next);
lastSelected = next;
if (next == sel) break;
next = next();
}
} else {
M prev = prev();
while (prev != null) {
items.add(prev);
lastSelected = prev;
if (prev == sel) break;
prev = prev();
}
}
tree.focus();
doSelect(items, true, false);
}
} else if (xe.getCtrlOrMetaKey() && isSelected(sel)) {
tree.focus();
doDeselect(Collections.singletonList(sel), false);
} else {
tree.focus();
doSelect(Collections.singletonList(sel), xe.getCtrlOrMetaKey(), false);
}
break;
}
}