Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.cdlflex.ui.markup.html.nav;
 
 import java.util.List;
 
A Bootstrap Navbar that renders INavbarComponent providers as navbar items.
 
 public class Navbar extends Panel {
 
     private static final long serialVersionUID = 1L;
 
     private List<INavbarComponent<? extends Component>> components;
 
     public Navbar(String id) {
         this(idnull);
     }
 
     public Navbar(String idIModel<?> model) {
         this(idmodelnew ArrayList<INavbarComponent<? extends Component>>());
     }
 
     public Navbar(String idIModel<?> modelList<INavbarComponent<? extends Component>> components) {
         super(idmodel);
         this. = components;
     }

    
Uses the given INavbarComponent to create a component within the bar.

Parameters:
component the component factory
<T> the component type
Returns:
this for chaining
 
     public <T extends ComponentNavbar add(INavbarComponent<T> component) {
         this..add(component);
         return this;
     }

    
Uses the given INavbarComponent to create a component within the bar.

Parameters:
components the component factories
Returns:
this for chaining
 
     public Navbar add(Collection<? extends INavbarComponent<? extends Component>> components) {
         this..addAll(components);
         return this;
     }
 
     @Override
     protected void onInitialize() {
         super.onInitialize();
 
         add(newContainer("navbar-container"));
     }
 
     @Override
     protected void onComponentTag(ComponentTag tag) {
         super.onComponentTag(tag);
 
         tag.put("role""navigation");
         CssClassNameAppender.append(tag"navbar""navbar-default");
     }

    
Creates the outermost navbar container wrapper within the <nav> component.

Parameters:
id component id
Returns:
a component
 
     protected Component newContainer(String id) {
         WebMarkupContainer container = new WebMarkupContainer(id);
 
        container.add(newNavbarHeader("navbar-header"));
        container.add(newNavLeft("nav-left"));
        container.add(newNavRight("nav-right"));
        return container;
    }

    
Creates the navbar header that contains the brand link.

Parameters:
id component id
Returns:
a component
    protected Component newNavbarHeader(String id) {
        WebMarkupContainer header = new WebMarkupContainer(id);
        Component brand = newBrandLink("brand-link");
        if (brand == null) {
            brand = new WebMarkupContainer("brand-link").setVisible(false);
        }
        header.add(brand);
        return header;
    }

    
Creates the brand link of the navbar header. May return null, causing nothing to be rendered.

Parameters:
id component id
Returns:
a component
    protected Component newBrandLink(String id) {
        return null;
    }

    
Creates the container that contains the navigation items on the left side.

Parameters:
id component id
Returns:
a component
    protected Component newNavLeft(String id) {
        return newNav(id, Collections.filter(new PositionFilter(.)));
    }

    
Creates the container that contains the navigation items on the right side.

Parameters:
id component id
Returns:
a component
    protected Component newNavRight(String id) {
        return newNav(id, Collections.filter(new PositionFilter(.)));
    }
    private Component newNav(String idList<INavbarComponent<? extends Component>> components) {
        return new ListView<INavbarComponent<? extends Component>>(idcomponents) {
            private static final long serialVersionUID = 1L;
            @Override
            protected ListItem<INavbarComponent<? extends Component>> newItem(int index,
                IModel<INavbarComponent<? extends Component>> itemModel) {
                return super.newItem(indexitemModel);
            }
            @Override
            protected void populateItem(ListItem<INavbarComponent<? extends Component>> item) {
                INavbarComponent<? extends ComponentnavbarComponent = item.getModelObject();
                item.add(newNavElement("nav-component-container"navbarComponent));
                navbarComponent.onAfterPopulateItem(item);
            }
        };
    }
    private <T extends ComponentComponent newNavElement(String idINavbarComponent<T> navbarComponent) {
        T component = navbarComponent.create("nav-component");
        return wrapComponent(idnavbarComponentcomponent);
    }
    private <T extends ComponentComponent wrapComponent(String idINavbarComponent<T> navbarComponent, T component) {
        WebMarkupContainer container;
        if (navbarComponent instanceof NavbarDropDown) {
            container = new Fragment(id"nav-transparent"this);
        } else if (navbarComponent instanceof NavbarLink) {
            container = new Fragment(id"nav-link"this);
        } else {
            container = new Fragment(id"nav-transparent"this);
        }
        return container.add(component);
    }

    
Filters a list of INavbarComponent by their position, i.e. the return value of INavbarComponent.getPosition().
    protected static class PositionFilter implements Collections.Predicate<INavbarComponent<? extends Component>> {
        private final Position position;
        public PositionFilter(Position position) {
            this. = position;
        }
        @Override
        public Boolean call(INavbarComponent<? extends Componentobject) {
            return .equals(object.getPosition());
        }
    }
New to GrepCode? Check out our FAQ X