View Javadoc

1   /*
2    * 
3    * 
4    */
5   package oscon2006.web.excel;
6   
7   import java.util.*;
8   import wicket.extensions.markup.html.tabs.AbstractTab;
9   import wicket.markup.html.panel.Panel;
10  import wicket.model.IModel;
11  import wicket.model.Model;
12  import wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
13  import org.apache.poi.hssf.usermodel.*;
14  
15  public class ExcelTabbedPanel
16  	extends AjaxTabbedPanel
17  {
18  	
19  	public ExcelTabbedPanel(String id, HSSFWorkbook w)
20  	{
21  		super(id, buildTabs(w));
22  	}
23  	
24  	private static List buildTabs(HSSFWorkbook wb)
25  	{
26  		List tabList = new ArrayList();
27  		
28  		for (int i = 0; i < wb.getNumberOfSheets(); i++)
29  		{
30  			String name = wb.getSheetName(i);
31  			ExcelTabModel m = new ExcelTabModel(name, i);
32  			tabList.add(new Tab(m, wb));
33  		}
34  		return tabList;
35  	}
36  	
37  	static public class Tab extends AbstractTab
38  	{
39  		private HSSFWorkbook wb;
40  		
41  		public Tab(IModel title, HSSFWorkbook w)
42  		{
43  			super(title);
44  			this.wb = w;
45  		}
46  
47  		@Override
48  		public Panel getPanel(String panelId)
49  		{
50  			ExcelTabModel m = (ExcelTabModel) this.getTitle();
51  			
52  			Panel p = new ExcelDataPanel(panelId, 
53  														this.wb, 
54  														m.getSheetNumber(), 
55  														30);
56  			
57  			return p;
58  		}
59  		
60  	}
61  	
62  	static private class ExcelTabModel extends Model
63  	{
64  		private String sheetName;
65  		private int sheetNumber;
66  		
67  		public ExcelTabModel(String sheetName, int sheetNumber)
68  		{
69  			super(sheetName);
70  			this.sheetName = sheetName;
71  			this.sheetNumber = sheetNumber;
72  			
73  		}
74  		
75  		public String getSheetName()
76  		{
77  			return this.sheetName;
78  		}
79  		
80  		public int getSheetNumber()
81  		{
82  			return this.sheetNumber;
83  		}
84  	}
85  }