001    package net.databinder.components.hib;
002    
003    import net.databinder.components.SourceListPanel;
004    
005    import org.apache.wicket.Page;
006    import org.apache.wicket.markup.html.link.Link;
007    import org.apache.wicket.model.IModel;
008    
009    /**
010     * Displays a list of PageSourceLinks to the selected page. The panel renders to an
011     * unordered list of class <tt>source-list</tt>.
012     * @see PageSourceLink
013     * @author Nathan Hamblen
014     */
015    public class PageSourceListPanel extends SourceListPanel {
016            private Class<? extends Page> pageClass;
017            private String idParameter;
018    
019            /**
020             * Creates list with identifiers bound to an "id" parameter.
021             * @param id component id
022             * @param page targeted page
023             * @param bodyProperty object property for link body text
024             * @param listModel list of entities to render
025             */
026            public PageSourceListPanel(String id, Class<? extends Page> page, String bodyProperty, IModel listModel ) {
027                    super(id, bodyProperty, listModel);
028                    this.pageClass = page;
029            }
030    
031            /**
032             * Creates list with identifiers bound to the chosen parameter
033             * @param id component id
034             * @param page targeted page
035             * @param bodyProperty object property for link body text
036             * @param idParameter identifer passed through this parameter
037             * @param listModel list of entities to render
038             */
039            public PageSourceListPanel(String id, Class<? extends Page> page, 
040                            String bodyProperty, String idParameter, IModel listModel ) {
041                    super(id, bodyProperty, listModel);
042                    this.pageClass = page;
043                    this.idParameter = idParameter;
044            }
045    
046            /** Called from super-class to construct source links. Note: subclasses my override
047             * to add attribute modifiers to the Link object constructed here, for example. */
048            @Override
049            protected Link sourceLink(String id, final IModel model) {
050                    PageSourceLink link = new PageSourceLink(id, pageClass, model, idParameter) {
051                            @Override
052                            protected void setParameters() {
053                                    super.setParameters();
054                                    PageSourceListPanel.this.setParameters(this);
055                            }
056                    };
057                    return link;
058            }
059            /**
060             * Called before rendering links. Override to set custom link parameters (the id parameter will
061             * always be set before calling this method).
062             * @param link one link of the list, with model set correspondingly
063             */
064            protected void setParameters(PageSourceLink link) { }
065    }