001 /*
002 * Databinder: a simple bridge from Wicket to Hibernate
003 * Copyright (C) 2006 Nathan Hamblen nathan@technically.us
004
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either
008 * version 2.1 of the License, or (at your option) any later version.
009 *
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public
016 * License along with this library; if not, write to the Free Software
017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018 */
019
020 package net.databinder.components.hib;
021
022 import java.util.ArrayList;
023
024 import net.databinder.components.DataStyleLink;
025 import net.databinder.hib.Databinder;
026
027 import org.apache.wicket.markup.html.WebPage;
028 import org.apache.wicket.markup.html.basic.Label;
029 import org.apache.wicket.markup.html.list.ListItem;
030 import org.apache.wicket.markup.html.list.ListView;
031 import org.apache.wicket.markup.html.pages.AccessDeniedPage;
032 import org.apache.wicket.model.LoadableDetachableModel;
033
034 /**
035 * Page containing a QueryPanel for browsing data and testing Hibernate queries. This
036 * page is not bookmarkable, so that it will not be inadverdantly
037 * available from the classpath. To access the page it must be subclassed or manually
038 * linked. DataApplication.BmarkDataBrowser is a subclass that requires that the
039 * running application be assignable to DataApplication and return true for
040 * isDataBrowserAllowed(). To use this page from an application that does not extend
041 * DataApplication, make a bookmarkable subclass and call super(true),
042 * or link to the class with PageLink.
043 * @author Nathan Hamblen
044 */
045 public class DataBrowser extends WebPage {
046 public DataBrowser(boolean allowAccess) {
047 if (allowAccess) {
048 add(new DataStyleLink("css"));
049 add(new QueryPanel("queryPanel"));
050 add(new ListView("entities", new LoadableDetachableModel() {
051 @SuppressWarnings("unchecked")
052 @Override
053 protected Object load() {
054 return new ArrayList(
055 Databinder.getHibernateSessionFactory().getAllClassMetadata().keySet());
056 }
057 }) {
058 @Override
059 protected void populateItem(ListItem item) {
060 item.add(new Label("name", item.getModel()));
061 }
062 });
063
064 } else setResponsePage(AccessDeniedPage.class);
065 }
066 }