Package com.foreach.across.modules.web.menu

Examples of com.foreach.across.modules.web.menu.Menu


    assertFalse( menu.getItemWithPath( "subsub2" ).isSelected() );
  }

  @Test
  public void deselectingParentDeselectsChild() {
    Menu menu = new Menu();
    menu.addItem( "path1" );

    Menu item = menu.addItem( "path2" );
    item.addItem( "sub1" );
    Menu subItem = item.addItem( "sub2" );

    subItem.addItem( "subsub1" ).setSelected( true );
    subItem.addItem( "subsub2" );

    item.setSelected( false );

    assertFalse( menu.getItemWithPath( "path1" ).isSelected() );
    assertFalse( menu.getItemWithPath( "path2" ).isSelected() );
View Full Code Here


    assertFalse( menu.getItemWithPath( "subsub2" ).isSelected() );
  }

  @Test
  public void deselectingChildDoesNotDeselectParent() {
    Menu menu = new Menu();
    menu.addItem( "path1" );

    Menu item = menu.addItem( "path2" );
    item.addItem( "sub1" );
    Menu subItem = item.addItem( "sub2" );

    subItem.addItem( "subsub1" ).setSelected( true );
    subItem.addItem( "subsub2" );

    subItem.getItemWithPath( "subsub1" ).setSelected( false );

    assertFalse( menu.getItemWithPath( "path1" ).isSelected() );
    assertTrue( menu.getItemWithPath( "path2" ).isSelected() );
    assertFalse( menu.getItemWithPath( "sub1" ).isSelected() );
    assertTrue( menu.getItemWithPath( "sub2" ).isSelected() );
View Full Code Here

    assertFalse( menu.getItemWithPath( "subsub2" ).isSelected() );
  }

  @Test
  public void onlyOneItemCanBeSelected() {
    Menu menu = new Menu();
    menu.addItem( "path1" );

    Menu item = menu.addItem( "path2" );
    item.addItem( "sub1" );
    Menu subItem = item.addItem( "sub2" );

    subItem.addItem( "subsub1" ).setSelected( true );
    subItem.addItem( "subsub2" );

    menu.getItemWithPath( "sub1" ).setSelected( true );

    assertFalse( menu.getItemWithPath( "path1" ).isSelected() );
    assertTrue( menu.getItemWithPath( "path2" ).isSelected() );
View Full Code Here

    assertFalse( menu.getItemWithPath( "subsub2" ).isSelected() );
  }

  @Test
  public void selectedItemIsAlwaysLookedForInTheSubtree() {
    Menu menu = new Menu();
    menu.addItem( "path1" );

    Menu item = menu.addItem( "path2" );
    item.addItem( "sub1" );
    Menu subItem = item.addItem( "sub2" );

    subItem.addItem( "subsub1" ).setSelected( true );
    subItem.addItem( "subsub2" );

    Menu selected = menu.getSelectedItem();
    assertSame( item, selected );

    selected = menu.getLowestSelectedItem();
    assertSame( menu.getItemWithPath( "subsub1" ), selected );
    assertNull( menu.getItemWithPath( "path1" ).getSelectedItem() );
View Full Code Here

    assertNull( subItem.getSelectedItem() );
  }

  @Test
  public void selectedItemPathIfNoneSelected() {
    Menu menu = new Menu();
    menu.addItem( "one" );

    assertNull( menu.getSelectedItem() );
    assertTrue( menu.getSelectedItemPath().isEmpty() );
  }
View Full Code Here

    assertTrue( menu.getSelectedItemPath().isEmpty() );
  }

  @Test
  public void selectedItemPathIfRootSelected() {
    Menu menu = new Menu();
    menu.addItem( "one" );

    menu.setSelected( true );

    assertNull( menu.getSelectedItem() );
    List<Menu> items = menu.getSelectedItemPath();
    assertEquals( 1, items.size() );
    assertSame( menu, items.get( 0 ) );
  }
View Full Code Here

    assertSame( menu, items.get( 0 ) );
  }

  @Test
  public void selectedItemPathIfLowerSelected() {
    Menu menu = new Menu();
    Menu item = menu.addItem( "one" );
    item.addItem( "sub-one" );
    Menu subTwo = item.addItem( "sub-two" );

    subTwo.setSelected( true );

    List<Menu> items = menu.getSelectedItemPath();
    assertEquals( 3, items.size() );
    assertSame( menu, items.get( 0 ) );
    assertSame( item, items.get( 1 ) );
View Full Code Here

  @Test
  public void mergeMenu() {
    @SuppressWarnings("unchecked")
    Comparator<Menu> mockComparator = mock( Comparator.class );

    Menu menu = new Menu();
    menu.addItem( "path1" );

    Menu item = menu.addItem( "path2" );
    item.setAttribute( "myattribute", "myvalue" );
    item.setAttribute( "myattribute2", "myvalue" );

    Menu other = new Menu();
    other.setPath( "other" );
    other.setTitle( "title other" );
    other.setDisabled( true );
    other.setGroup( true );
    other.setAttribute( "myattribute", "myothervalue" );
    other.setAttribute( "myotherattribute", "myothervalue" );

    Menu otherItem = other.addItem( "otherItem" );
    otherItem.setSelected( true );
    otherItem.setUrl( "other item url" );
    otherItem.setComparator( mockComparator, true );

    // Merge into sub-tree
    item.merge( other, false );

    assertEquals( 2, menu.size() );
    assertEquals( "path1", menu.getFirstItem().getPath() );

    Menu modified = menu.getItems().get( 1 );
    assertEquals( "other", modified.getPath() );
    assertEquals( "title other", modified.getTitle() );
    assertTrue( modified.isDisabled() );
    assertTrue( modified.isGroup() );
    assertEquals( 3, modified.getAttributes().size() );
    assertEquals( "myothervalue", modified.getAttribute( "myattribute" ) );
    assertEquals( "myvalue", modified.getAttribute( "myattribute2" ) );
    assertEquals( "myothervalue", modified.getAttribute( "myotherattribute" ) );
    assertTrue( modified.isSelected() );

    assertEquals( 1, modified.size() );
    modified = modified.getFirstItem();
    assertEquals( "otherItem", modified.getPath() );
    assertEquals( "other item url", modified.getUrl() );
    assertTrue( modified.isSelected() );
    assertSame( mockComparator, modified.getComparator() );
    assertTrue( modified.isComparatorInheritable() );
  }
View Full Code Here

public class TestTraversingMenuSelector
{
  @Test
  public void findFirstItem() {
    Menu menu = new Menu();
    Menu item1 = menu.addItem( "path1" );
    Menu item2 = menu.addItem( "path2" );
    Menu subItem1 = item2.addItem( "path1" );
    Menu subItem2 = item2.addItem( "sub2" );
    Menu subSubItem1 = subItem1.addItem( "subsub1" );
    Menu subSubItem2 = subItem2.addItem( "path1" );

    Menu found = menu.getItem( new TraversingMenuSelector( false )
    {
      @Override
      protected boolean matches( Menu item ) {
        return StringUtils.equals( "path1", item.getPath() );
      }
View Full Code Here

    assertSame( item1, found );
  }

  @Test
  public void findLowestItem() {
    Menu menu = new Menu();
    Menu item1 = menu.addItem( "path1" );
    Menu item2 = menu.addItem( "path2" );
    Menu subItem1 = item2.addItem( "path1" );
    Menu subItem2 = item2.addItem( "sub2" );
    Menu subSubItem1 = subItem1.addItem( "subsub1" );
    Menu subSubItem2 = subItem2.addItem( "path1" );

    Menu found = menu.getItem( new TraversingMenuSelector( true )
    {
      @Override
      protected boolean matches( Menu item ) {
        return StringUtils.equals( "path1", item.getPath() );
      }
View Full Code Here

TOP

Related Classes of com.foreach.across.modules.web.menu.Menu

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.