/**
* Copyright (C) cedarsoft GmbH.
*
* 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 com.cedarsoft.wicket.navigation;
import com.cedarsoft.wicket.WicketConstants;
import org.apache.wicket.Component;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.html.resources.StyleSheetReference;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
*
*/
public class NavigationComponent extends Panel {
@NonNls
public static final String NAVIGATION_UL = "navigationUl";
public NavigationComponent( @NotNull @NonNls String id, @NotNull final LinksDataView<?> dataView ) {
this( id, dataView, null );
}
public NavigationComponent( @NotNull @NonNls String id, @NotNull final LinksDataView<?> dataView, @Nullable ResourceReference styleSheetReference ) {
super( id );
if ( styleSheetReference == null ) {
add( new EmptyPanel( WicketConstants.ID_STYLE_SHEET ) );
} else {
add( new StyleSheetReference( WicketConstants.ID_STYLE_SHEET, styleSheetReference ) );
}
WebMarkupContainer container = new WebMarkupContainer( NAVIGATION_UL );
add( container );
container.add( dataView );
//Adds the big reference
container.add( new AbstractBehavior() {
@Override
public void onComponentTag( @NotNull Component component, @NotNull ComponentTag tag ) {
if ( dataView.getRowCount() > 6 ) {
tag.put( "id", "big" );
} else {
tag.put( "id", "small" );
}
}
} );
}
}