Package org.eclipse.jface.viewers

Examples of org.eclipse.jface.viewers.TreePath


  private TreePathContentProvider content;

  @Before
  public void before() {
    TreePath path1 = new TreePath(new Object[]{"1", "2", "3"});
    TreePath path2 = new TreePath(new Object[]{"a", "b"});
    ITreePathBuilder builder = mock(ITreePathBuilder.class);
    when(builder.build(any())).thenReturn(Arrays.asList(path1, path2));
    content = create(builder);

    // Call once to initialize:
View Full Code Here


  }

  @Test
  public void getChildrenShouldReturnAnEmptyArrayIfParentHasNoChildren() {
    // Given a non-null parent has no children:
    TreePath parent = new TreePath(new Object[]{this});

    // When asking for the children of the parent:
    Object[] children = content.getChildren(parent);

    // The an empty array is returned:
View Full Code Here

  }

  @Test
  public void getChildrenShouldReturnAnEmtpyArrayIfParentIsNull() {
    // Given a parent path is null:
    TreePath parent = null;

    // When asking for the children of the null object:
    Object[] children = content.getChildren(parent);

    // The an empty array should be returned as the children:
View Full Code Here

  }

  @Test
  public void getChildrenShouldReturnTheDistinctChildrenOfAParent() {
    // Given a tree path has 3 children, 2 of which are equal:
    TreePath branch = new TreePath(new Object[]{0, 1});
    TreePath leaf1 = branch.createChildPath(2);
    TreePath leaf2 = branch.createChildPath(3);
    TreePath leaf3 = branch.createChildPath(3);
    Object input = new Object();

    ITreePathBuilder builder = mock(ITreePathBuilder.class);
    given(builder.build(input)).willReturn(asList(leaf1, leaf2, leaf3));
    content = create(builder);

    // When asking for the children of the parent path:
    content.inputChanged(null, null, input); // Sets the input.
    List<Object> children = newArrayList(content.getChildren(branch));

    // Then the distinct children should be returned:
    List<Object> expected = newArrayList(newHashSet( // Get unique children
        leaf1.getLastSegment(),
        leaf2.getLastSegment(),
        leaf3.getLastSegment()));
    assertThat(children, is(equalTo(expected)));
  }
View Full Code Here

  public void getElementsShouldReturnAnEmptyArrayIfAllLeavesAreEmptyPaths() {
    // Given all tree paths are empty paths:
    Object input = new Object();
    ITreePathBuilder builder = mock(ITreePathBuilder.class);
    given(builder.build(input)).willReturn(
        asList(TreePath.EMPTY, new TreePath(new Object[0])));
    content = create(builder);

    // When set and ask for elements:
    content.inputChanged(null, null, input);
    Object[] elements = content.getElements(input);
View Full Code Here

  }

  @Test
  public void getElementsShouldReturnTheDistinctElementsOfAllLeaves() {
    // Given we have 3 leaves, the 0th segments of 2 of them are equal::
    TreePath leaf1 = new TreePath(new Object[]{0, 1});
    TreePath leaf2 = new TreePath(new Object[]{2, 3});
    TreePath leaf3 = new TreePath(new Object[]{9, 8});
    Object input = new Object();

    ITreePathBuilder builder = mock(ITreePathBuilder.class);
    given(builder.build(input)).willReturn(asList(leaf1, leaf2, leaf3));
    content = create(builder);

    // When asking for elements of the new input:
    content.inputChanged(null, null, input);
    List<Object> actual = newArrayList(content.getElements(input));

    // Then the distinct first elements of each leave is returned:
    List<Object> expected = newArrayList(newHashSet( // Get distinct elements
        leaf1.getFirstSegment(),
        leaf2.getFirstSegment(),
        leaf3.getFirstSegment()));
    assertThat(actual, is(equalTo(expected)));
  }
View Full Code Here

  @Test
  public void getParentsShouldReturnTheParentsOfAChild() {
    // Given we have two leaves that have the same last segments:
    Object child = "Child";
    TreePath leaf1 = new TreePath(new Object[]{0, child});
    TreePath leaf2 = new TreePath(new Object[]{2, child});

    ITreePathBuilder builder = mock(ITreePathBuilder.class);
    given(builder.build("input")).willReturn(asList(leaf1, leaf2));
    content = create(builder);

    // When getting the parents of the child:
    content.inputChanged(null, null, "input");
    Set<TreePath> actual = newHashSet(content.getParents(child));

    // Then the parent path of the two leaves should be returned:e
    Set<TreePath> expected = newHashSet(
        leaf1.getParentPath(),
        leaf2.getParentPath());
    assertThat(actual, is(expected));
  }
View Full Code Here

    assertThat(create(mock(ITreePathBuilder.class)).get().isEmpty(), is(true));
  }

  @Test(expected = UnsupportedOperationException.class)
  public void getShouldReturnAnImmutableCollection() {
    content.get().add(new TreePath(new Object[]{}));
  }
View Full Code Here

  }

  @Test
  public void getShouldReturnTheTreePathsCurrentlyInUse() {
    List<TreePath> paths = Lists.newArrayList();
    paths.add(new TreePath(new Object[]{}));
    paths.add(new TreePath(new Object[]{"a", "b"}));

    ITreePathBuilder builder = mock(ITreePathBuilder.class);
    given(builder.build(any())).willReturn(paths);
    content = create(builder);
    content.inputChanged(null, null, null);
View Full Code Here

  }

  @Test
  public void hasChildrenShouldReturnFalseIfTheGivenPathHasNoChildren() {
    // Given a non-null parent has no children:
    TreePath parent = new TreePath(new Object[]{this});

    // When asking whether the parent has children or not:
    boolean hasChildren = content.hasChildren(parent);

    // Then false is returned:
View Full Code Here

TOP

Related Classes of org.eclipse.jface.viewers.TreePath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.