Package com.cedarsoft.wicket.navigation

Source Code of com.cedarsoft.wicket.navigation.LinksDataView

/**
* 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 org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

/**
* A view for links. The given {@link IDataProvider} must provide {@link LinkProvider}s
*/
public class LinksDataView<T extends LinkProvider> extends DataView<T> {
  @NotNull
  @NonNls
  public static final String ID = "links";

  @NotNull
  @NonNls
  static final String ID_LINK = "link";
  @NotNull
  @NonNls
  static final String ID_LABEL = "label";

  public LinksDataView( @NotNull IDataProvider<T> dataProvider ) {
    super( ID, dataProvider );
  }

  @Override
  protected void populateItem( @NotNull Item<T> item ) {
    LinkProvider linkProvider = item.getModelObject();

    WebMarkupContainer link = linkProvider.createLink( ID_LINK );
    if ( !ID_LINK.equals( link.getId() ) ) {
      throw new IllegalStateException( "Link must have the ID set to " + ID_LINK );
    }
    WebComponent label = linkProvider.createLabel( ID_LABEL );
    if ( !ID_LABEL.equals( label.getId() ) ) {
      throw new IllegalStateException( "Label must have the ID set to " + ID_LABEL );
    }

    link.add( label );
    item.add( link );
  }
}
TOP

Related Classes of com.cedarsoft.wicket.navigation.LinksDataView

TOP
Copyright © 2018 www.massapi.com. 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.