001    package net.databinder.components;
002    
003    import org.apache.wicket.markup.html.basic.Label;
004    import org.apache.wicket.markup.html.link.Link;
005    import org.apache.wicket.markup.html.list.ListItem;
006    import org.apache.wicket.markup.html.list.PropertyListView;
007    import org.apache.wicket.markup.html.panel.Panel;
008    import org.apache.wicket.model.ComponentPropertyModel;
009    import org.apache.wicket.model.IModel;
010    
011    /**
012     * Displays a list of links to set the model of a target component or page. The panel renders to an
013     * unordered list of class <tt>source-list</tt>. 
014     * @author Nathan Hamblen
015     */
016    public abstract class SourceListPanel extends Panel {
017            /**
018             * @param id panel id
019             * @param bodyProperty property to display as link body
020             * @param listModel must  the list from which the model objects will be drawn
021             */
022            public SourceListPanel(String id, final String bodyProperty, IModel listModel) {
023                    super(id);
024                    add(new PropertyListView("list", listModel) {
025                            protected void populateItem(final ListItem item) {
026                                    Link link = sourceLink("link", item.getModel());
027                                    Label title = new Label("title", new ComponentPropertyModel(bodyProperty));
028                                    item.add(link.add(title));
029                            }
030                    });
031            }
032            /** Supply a source link for the model and id */
033            protected abstract Link sourceLink(String id, IModel model);
034    }