Package com.cedarsoft.wicket.attachments

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

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.