KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > component > data > GridListDataModel


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.component.data;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.web.data.QuickSort;
22
23 /**
24  * @author kevinr
25  */

26 public class GridListDataModel implements IGridDataModel
27 {
28    /**
29     * Constructor
30     *
31     * @param data List of Object[] row data
32     */

33    public GridListDataModel(List JavaDoc data)
34    {
35       this.data = data;
36    }
37    
38    /**
39     * Get a row object for the specified row index
40     *
41     * @param index valid row index
42     *
43     * @return row object for the specified index
44     */

45    public Object JavaDoc getRow(int index)
46    {
47       return this.data.get(index);
48    }
49    
50    /**
51     * Return the number of rows in the data model
52     *
53     * @return row count
54     */

55    public int size()
56    {
57       return this.data.size();
58    }
59    
60    /**
61     * Sort the data set using the specified sort parameters
62     *
63     * @param column Column to sort
64     * @param descending True for descending sort, false for ascending
65     * @param mode Sort mode to use (see IDataContainer constants)
66     */

67    public void sort(String JavaDoc column, boolean descending, String JavaDoc mode)
68    {
69       try
70       {
71          QuickSort sorter = new QuickSort(this.data, column, !descending, mode);
72          sorter.sort();
73       }
74       catch (Exception JavaDoc err)
75       {
76          throw new RuntimeException JavaDoc("Failed to sort data: " + err.getMessage(), err);
77       }
78    }
79    
80    private List JavaDoc data = null;
81 }
82
Popular Tags