/**
 * @author smallufo 
 * Created on 2009/2/5
 */ 
package quickstart;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;

public class MyPanel extends Panel implements ExpandCollapseListener
{
  private List<String[]> namePhoneList = Collections.synchronizedList(new ArrayList<String[]>());
  
  private String title;
  
  private WebMarkupContainer listViewContainer;
  
  private ListView listView;
  
  public MyPanel(String id , String title , boolean defaultShown)
  {
    super(id);
    this.title = title;
    
    // dummy data preparation
    namePhoneList.add(new String[]{"John" , "555-1111"});
    namePhoneList.add(new String[]{"Mary" , "555-2222"});
    
    PulldownBorder border = new PulldownBorder("border" , title , defaultShown);
    border.setTransparentResolver(true);
    add(border);
    
    listViewContainer = new WebMarkupContainer("listViewContainer"); 
    listViewContainer.setOutputMarkupPlaceholderTag(true);
    listViewContainer.setVisible(defaultShown);
    
    listView =new ListView("data" , namePhoneList)
    {
    
      @Override
      protected void populateItem(ListItem item)
      {
        String[] namePhonePair = (String[]) item.getModelObject();
        item.add(new Label("name" , namePhonePair[0]));
        item.add(new Label("phone" , namePhonePair[1]));
      }
    };
    
    listView.setOutputMarkupPlaceholderTag(true);
    add(listViewContainer.add(listView));
  }

  @Override
  public void setExpanded(boolean value, AjaxRequestTarget target)
  {
    // store the panel's state to the session
    MySession.get().setVisible(title, value);
  }

}
