<commit_before>/*---
   Copyright 2007 The Scripps Research Institute
   http://www.scripps.edu

   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 wicket.contrib.webbeans.databinder;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import wicket.contrib.webbeans.containers.BeanTablePanel;
import wicket.contrib.webbeans.model.BeanMetaData;

import net.databinder.components.hibernate.SearchPanel;
import net.databinder.models.DatabinderProvider;
import net.databinder.DataStaticService;
import org.apache.wicket.markup.repeater.data.IDataProvider;

import org.hibernate.classic.Session;

/**
 * A basic Databinder/Hibernate Bean List panel. 
 * A subclass and corresponding beanprops file are required for customization.
 * 
 * @author <NAME> (mrsouthern)
 */
public abstract class DataBeanListPanel extends Panel
{    
    private BeanTablePanel panel;
    private BeanMetaData metaData;
    
    /**
     *
     * @param beanClass the fully qualified class name of the bean to be edited 
     */
	public DataBeanListPanel(String id, String beanClass)
	{
	    super(id);
	    try
	    {  
	        Class clazz = Class.forName(beanClass);
	        DataStaticService.getHibernateSession().beginTransaction();
    		metaData = new BeanMetaData(clazz, null, this, null, true);
    		Label label = new Label("label", new Model(metaData.getParameter("label")));
    		add(label);

    		SearchPanel search = new SearchPanel("search", new Model(null))
            {
                public void onUpdate(AjaxRequestTarget target) {
                        target.addComponent(panel);
                }
            };
            add(search);
    		
    		DataSorter sorter = new DataSorter(metaData.getParameter("orderBy"));
    		String filter = metaData.getParameter("filter");
    		IDataProvider provider = new DatabinderProvider(clazz,new DataSearchFilter(search,filter),sorter);
    		panel = new BeanTablePanel("beanTable", provider, sorter, metaData, true, 20);
    		panel.setOutputMarkupId(true);
    		Form form = new Form("form");
    		add(form);
    		form.add(panel);
	    }
	    catch(Exception ex)
	    {
	        ex.printStackTrace();
	        throw new RuntimeException(ex);
	    }
	}<commit_msg>Now takes a bean Class in a constructor as well as a String.<commit_after>/*---
   Copyright 2007 The Scripps Research Institute
   http://www.scripps.edu

   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 wicket.contrib.webbeans.databinder;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import wicket.contrib.webbeans.containers.BeanTablePanel;
import wicket.contrib.webbeans.model.BeanMetaData;

import net.databinder.components.hibernate.SearchPanel;
import net.databinder.models.DatabinderProvider;
import net.databinder.DataStaticService;
import org.apache.wicket.markup.repeater.data.IDataProvider;

import org.hibernate.classic.Session;

/**
 * A basic Databinder/Hibernate Bean List panel. 
 * A subclass and corresponding beanprops file are required for customization.
 * 
 * @author <NAME> (mrsouthern)
 */
public abstract class DataBeanListPanel extends Panel
{    
    private BeanTablePanel panel;
    private BeanMetaData metaData;
    
    public DataBeanListPanel(String id, Class beanClass)
    {
    	this(id,beanClass.getName());
    }
    
    /**
     *
     * @param beanClass the fully qualified class name of the bean to be edited 
     */
	public DataBeanListPanel(String id, String beanClass)
	{
	    super(id);
	    try
	    {  
	        Class clazz = Class.forName(beanClass);
	        DataStaticService.getHibernateSession().beginTransaction();
    		metaData = new BeanMetaData(clazz, null, this, null, true);
    		Label label = new Label("label", new Model(metaData.getParameter("label")));
    		add(label);

    		SearchPanel search = new SearchPanel("search", new Model(null))
            {
                public void onUpdate(AjaxRequestTarget target) {
                        target.addComponent(panel);
                }
            };
            add(search);
    		
            DataSorter sorter;
            String orderBy = metaData.getParameter("orderBy");
            if( orderBy.contains(" ") )
            {
            	String[] items = orderBy.split("\\s+");
            	boolean asc = ( "desc".equalsIgnoreCase(items[1]) ? false : true );
            		sorter = new DataSorter(items[0], asc);
            }
            else
            	sorter = new DataSorter(orderBy);
    		
    		String filter = metaData.getParameter("filter");
    		IDataProvider provider = new DatabinderProvider(clazz,new DataSearchFilter(search,filter),sorter);
    		panel = new BeanTablePanel("beanTable", provider, sorter, metaData, true, 20);
    		panel.setOutputMarkupId(true);
    		Form form = new Form("form");
    		add(form);
    		form.add(panel);
	    }
	    catch(Exception ex)
	    {
	        ex.printStackTrace();
	        throw new RuntimeException(ex);
	    }
	}
{'fraction_non_alphanumeric': 0.0944645954896704, 'fraction_numerical': 0.0034694843084686956, 'mean_word_length': 2.961274203622736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5665190', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1789, 'n_words': 489}