示例#1
0
 private static void checkNodeArray(
     JsoArray<FileTreeNode> expected, JsoArray<FileTreeNode> actual) {
   assertEquals("Array sizes don't line up!", expected.size(), actual.size());
   for (int i = 0; i < expected.size(); i++) {
     assertEquals(
         "expected: " + expected.get(i).getName() + " != " + actual.get(i).getName(),
         expected.get(i),
         actual.get(i));
   }
 }
示例#2
0
  /** Tests select responses to ctrl clicks that should result in select toggling */
  public void testCtrlSelectToggle() {
    FileTreeNode root = mockTree.getModel().getRoot();

    // Render the tree.
    mockTree.renderTree(-1);

    SignalEvent ctrlSignalEvent = new MockSignalEvent(true, false);

    // Select a bunch of nodes at the same tier.
    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, ctrlSignalEvent);
    expectedSelects.add(AD1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AD1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Select the second top level dir
    FileTreeNode BD1 = getNodeByPath(1);
    mockSelectionModel.selectNode(BD1, ctrlSignalEvent);
    expectedSelects.add(BD1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(BD1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Select the first file.
    FileTreeNode AF1 = getNodeByPath(3);
    assertNotNull("Node did not get rendered!", AF1.getRenderedTreeNode());
    assertFalse(AF1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Change the select.
    mockSelectionModel.selectNode(AF1, ctrlSignalEvent);
    expectedSelects.add(AF1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AF1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Now toggle the second dir.
    mockSelectionModel.selectNode(BD1, ctrlSignalEvent);
    expectedSelects.remove(BD1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertFalse(BD1.getRenderedTreeNode().isSelected(resources.treeCss()));
  }
示例#3
0
  /** Tests select responses to ctrl clicks across tiers in the tree. */
  public void testCtrlSelectAcrossTiers() {
    FileTreeNode root = mockTree.getModel().getRoot();

    // Render the tree.
    mockTree.renderTree(-1);

    SignalEvent ctrlSignalEvent = new MockSignalEvent(true, false);

    // Select a bunch of nodes at the same tier.
    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, ctrlSignalEvent);
    expectedSelects.add(AD1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AD1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Select the second top level dir
    FileTreeNode BD1 = getNodeByPath(1);
    mockSelectionModel.selectNode(BD1, ctrlSignalEvent);
    expectedSelects.add(BD1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(BD1.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, ctrlSignalEvent);
    expectedSelects.clear();
    expectedSelects.add(AF2);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertFalse(AD1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Select another peer node.
    FileTreeNode CF2 = getNodeByPath(0, 2);
    assertNotNull("Node did not get rendered!", CF2.getRenderedTreeNode());
    assertFalse(CF2.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Change the select.
    mockSelectionModel.selectNode(CF2, ctrlSignalEvent);
    expectedSelects.add(CF2);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertTrue(CF2.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Select another 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, ctrlSignalEvent);
    // We need to enforce sort order. AF2, BF2, CF2.
    expectedSelects.splice(1, 0, BF2);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertTrue(BF2.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertTrue(CF2.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Ensure that if we ctrl click back higher in the stack that we clear the
    // selected list.
    FileTreeNode AF1 = getNodeByPath(3);
    assertNotNull("Node did not get rendered!", AF1.getRenderedTreeNode());
    assertFalse(AF1.getRenderedTreeNode().isSelected(resources.treeCss()));

    // Change the select.
    mockSelectionModel.selectNode(AF1, ctrlSignalEvent);
    expectedSelects.clear();
    expectedSelects.add(AF1);
    checkNodeArray(expectedSelects, mockSelectionModel.getSelectedNodes());
    assertTrue(AF1.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertFalse(AF2.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertFalse(BF2.getRenderedTreeNode().isSelected(resources.treeCss()));
    assertFalse(CF2.getRenderedTreeNode().isSelected(resources.treeCss()));
  }
示例#4
0
  /** 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()));
  }