/**
* Tests select responses to shift clicks that should do range selects.
*/
public void testShiftSelect() {
FileTreeNode root = mockTree.getModel().getRoot();
// Render the tree.
mockTree.renderTree(-1);
SignalEvent shiftSignalEvent = new MockSignalEvent(false, true);
FileTreeNode AD1 = getNodeByPath(0);
assertNotNull("Node did not get rendered!", AD1.getRenderedTreeNode());
assertFalse(AD1.getRenderedTreeNode().isSelected(resources.treeCss()));
JsoArray<FileTreeNode> expectedSelects = JsoArray.create();
// Select the first top level dir.
mockSelectionModel.selectNode(AD1, shiftSignalEvent);
expectedSelects.add(AD1);
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(AD1.getRenderedTreeNode().isSelected(resources.treeCss()));
// Shift select the last top level file.
FileTreeNode BF1 = getNodeByPath(4);
mockSelectionModel.selectNode(BF1, shiftSignalEvent);
expectedSelects.add(getNodeByPath(1));
expectedSelects.add(getNodeByPath(2));
expectedSelects.add(getNodeByPath(3));
expectedSelects.add(getNodeByPath(4));
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(BF1.getRenderedTreeNode().isSelected(resources.treeCss()));
assertTrue(getNodeByPath(2).getRenderedTreeNode().isSelected(resources.treeCss()));
assertTrue(getNodeByPath(3).getRenderedTreeNode().isSelected(resources.treeCss()));
// Select the last file. It should zero the shift selection.
mockSelectionModel.selectNode(BF1, shiftSignalEvent);
expectedSelects.clear();
expectedSelects.add(BF1);
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(BF1.getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(getNodeByPath(0).getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(getNodeByPath(1).getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(getNodeByPath(2).getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(getNodeByPath(3).getRenderedTreeNode().isSelected(resources.treeCss()));
// Select deeper. We should not allow cross depth selecting and
// should replace it with just the new select.
FileTreeNode AF2 = getNodeByPath(0, 0);
assertNotNull("Node did not get rendered!", AF2.getRenderedTreeNode());
assertFalse(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
// Change the select.
mockSelectionModel.selectNode(AF2, shiftSignalEvent);
expectedSelects.clear();
expectedSelects.add(AF2);
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(BF1.getRenderedTreeNode().isSelected(resources.treeCss()));
// Select the adjacent peer node.
FileTreeNode BF2 = getNodeByPath(0, 1);
assertNotNull("Node did not get rendered!", BF2.getRenderedTreeNode());
assertFalse(BF2.getRenderedTreeNode().isSelected(resources.treeCss()));
// Change the select.
mockSelectionModel.selectNode(BF2, shiftSignalEvent);
expectedSelects.add(BF2);
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
assertTrue(BF2.getRenderedTreeNode().isSelected(resources.treeCss()));
// Select the last peer node.
FileTreeNode DF2 = getNodeByPath(0, 3);
assertNotNull("Node did not get rendered!", DF2.getRenderedTreeNode());
assertFalse(DF2.getRenderedTreeNode().isSelected(resources.treeCss()));
// Change the select.
mockSelectionModel.selectNode(DF2, shiftSignalEvent);
expectedSelects.add(getNodeByPath(0, 2));
expectedSelects.add(getNodeByPath(0, 3));
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(DF2.getRenderedTreeNode().isSelected(resources.treeCss()));
assertTrue(getNodeByPath(0, 2).getRenderedTreeNode().isSelected(resources.treeCss()));
// Ensure that if we shift click the last one we clear the selected list.
mockSelectionModel.selectNode(DF2, shiftSignalEvent);
expectedSelects.clear();
expectedSelects.add(DF2);
checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
assertTrue(DF2.getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(BF2.getRenderedTreeNode().isSelected(resources.treeCss()));
assertFalse(getNodeByPath(0, 2).getRenderedTreeNode().isSelected(resources.treeCss()));
}