KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > simple > SimpleTableColumnModel


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.contrib.table.model.simple;
16
17 import java.io.Serializable JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.tapestry.contrib.table.model.ITableColumn;
24 import org.apache.tapestry.contrib.table.model.ITableColumnModel;
25 import org.apache.tapestry.contrib.table.model.common.ArrayIterator;
26
27 /**
28  * A minimal implementation of the
29  * {@link org.apache.tapestry.contrib.table.model.ITableColumnModel} interface
30  * that stores columns as an array.
31  *
32  * @author mindbridge
33  */

34 public class SimpleTableColumnModel implements ITableColumnModel, Serializable JavaDoc
35 {
36     private static final long serialVersionUID = 1L;
37     
38     private ITableColumn[] m_arrColumns;
39     private Map JavaDoc m_mapColumns;
40
41     public SimpleTableColumnModel(ITableColumn[] arrColumns)
42     {
43         m_arrColumns = arrColumns;
44
45         m_mapColumns = new HashMap JavaDoc();
46         for (int i = 0; i < m_arrColumns.length; i++)
47             m_mapColumns.put(m_arrColumns[i].getColumnName(), m_arrColumns[i]);
48     }
49
50     public SimpleTableColumnModel(List JavaDoc arrColumns)
51     {
52         this((ITableColumn[]) arrColumns.toArray(new ITableColumn[arrColumns.size()]));
53     }
54
55     public int getColumnCount()
56     {
57         return m_arrColumns.length;
58     }
59
60     public ITableColumn getColumn(int nColumn)
61     {
62         if (nColumn < 0 || nColumn >= m_arrColumns.length)
63         {
64             // error message
65
return null;
66         }
67         return m_arrColumns[nColumn];
68     }
69
70     public ITableColumn getColumn(String JavaDoc strColumn)
71     {
72         return (ITableColumn) m_mapColumns.get(strColumn);
73     }
74
75     public Iterator JavaDoc getColumns()
76     {
77         return new ArrayIterator(m_arrColumns);
78     }
79
80 }
81
Popular Tags