Package com.cedarsoft.wicket.attachments

Source Code of com.cedarsoft.wicket.attachments.AttachmentsComponent

/**
* 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.attachments;

import com.cedarsoft.wicket.FriendsOnly;
import com.cedarsoft.wicket.WicketConstants;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.DownloadLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
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 java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
* Shows the attachments
*/
@FriendsOnly
public class AttachmentsComponent extends Panel {
  public AttachmentsComponent( @NotNull @NonNls String id, @NotNull List<? extends File> resourceFiles ) {
    super( id );
    add( new StyleSheetReference( WicketConstants.ID_STYLE_SHEET, AttachmentsComponent.class, "AttachmentsComponent.css" ) );
    add( new ListView<File>( "attachments", new ArrayList<File>( resourceFiles ) ) {
      @Override
      protected void populateItem( @NotNull ListItem<File> item ) {
        final File file = item.getModelObject();
        DownloadLink link = new DownloadLink( "downloadLink", file );
        item.add( link );
        link.add( new Label( "label", file.getName() ) );
      }
    } );
  }
}
TOP

Related Classes of com.cedarsoft.wicket.attachments.AttachmentsComponent

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.