KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > approval > ApprovalDataVOViewList


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.ui.web.admin.approval;
15
16 import java.util.AbstractList JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.Comparator JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.ejbca.core.model.approval.ApprovalDataVO;
25
26 /**
27  * Class used to manage the list of approvaldatas resulted in the query.
28  *
29  * @author Philip Vendil
30  * @version $Id: ApprovalDataVOViewList.java,v 1.2.6.1 2007/03/09 17:27:53 anatom Exp $
31  */

32
33 public class ApprovalDataVOViewList extends AbstractList JavaDoc implements java.io.Serializable JavaDoc {
34
35     /**
36      * Determines if a de-serialized file is compatible with this class.
37      *
38      * Maintainers must change this value if and only if the new version
39      * of this class is not compatible with old versions. See Sun docs
40      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
41      * /serialization/spec/version.doc.html> details. </a>
42      *
43      */

44     private static final long serialVersionUID = 1680993305950225012L;
45     
46     List JavaDoc listData;
47     
48     public ApprovalDataVOViewList(Collection JavaDoc approvalDataVOs){
49        listData = new ArrayList JavaDoc();
50        Iterator JavaDoc iter = approvalDataVOs.iterator();
51        while(iter.hasNext()){
52           listData.add(new ApprovalDataVOView((ApprovalDataVO) iter.next()));
53        }
54          
55     }
56     
57
58     
59     public Object JavaDoc get(int arg0) {
60         return listData.get(arg0);
61     }
62
63
64     public int size() {
65         return listData.size();
66     }
67     
68     
69     private String JavaDoc _sort;
70     private boolean _ascending;
71
72
73     /**
74      * Sort the list.
75      */

76     protected void sort(final String JavaDoc column, final boolean ascending){
77
78         
79         Comparator JavaDoc comparator = new Comparator JavaDoc()
80         {
81             public int compare(Object JavaDoc o1, Object JavaDoc o2)
82             {
83                 ApprovalDataVOView c1 = (ApprovalDataVOView)o1;
84                 ApprovalDataVOView c2 = (ApprovalDataVOView)o2;
85                 if (column == null)
86                 {
87                     return 0;
88                 }
89                 if (column.equals("requestDate"))
90                 {
91                     return ascending ? c1.getApproveActionDataVO().getRequestDate().compareTo(c2.getApproveActionDataVO().getRequestDate()) :
92                                        c2.getApproveActionDataVO().getRequestDate().compareTo(c1.getApproveActionDataVO().getRequestDate());
93                 }
94                 else if (column.equals("approveActionName"))
95                 {
96                     return ascending ? c1.getApproveActionName().compareTo(c2.getApproveActionName()) : c2.getApproveActionName().compareTo(c1.getApproveActionName());
97                 }
98                 else if (column.equals("requestUsername"))
99                 {
100                     return ascending ? c1.getRequestAdminName().compareTo(c2.getRequestAdminName()) : c2.getRequestAdminName().compareTo(c1.getRequestAdminName());
101                 }
102                 else if (column.equals("status"))
103                 {
104                     return ascending ? c1.getStatus().compareTo(c2.getStatus()) : c2.getStatus().compareTo(c1.getStatus());
105                 }
106                 else return 0;
107             }
108         };
109         
110         
111         Collections.sort(listData,comparator);
112     }
113
114     /**
115      * Is the default sort direction for the given column "ascending" ?
116      */

117     protected boolean isDefaultAscending(String JavaDoc sortColumn){
118        return true;
119     }
120
121
122     public void sort(String JavaDoc sortColumn)
123     {
124         if (sortColumn == null)
125         {
126             throw new IllegalArgumentException JavaDoc("Argument sortColumn must not be null.");
127         }
128
129         if (_sort.equals(sortColumn))
130         {
131             //current sort equals new sortColumn -> reverse sort order
132
_ascending = !_ascending;
133         }
134         else
135         {
136             //sort new column in default direction
137
_sort = sortColumn;
138             _ascending = isDefaultAscending(_sort);
139         }
140
141         sort(_sort, _ascending);
142     }
143     
144     public void sort()
145     {
146         sort(_sort);
147     }
148     
149     public List JavaDoc getData()
150     {
151         sort(getSort(), isAscending());
152         return this;
153     }
154     public void setData(List JavaDoc data)
155     {
156      
157     }
158
159     public String JavaDoc getSort()
160     {
161
162         return _sort;
163     }
164
165     public void setSort(String JavaDoc sort)
166     {
167         _sort = sort;
168     }
169
170     public boolean isAscending()
171     {
172         return _ascending;
173     }
174
175     public void setAscending(boolean ascending)
176     {
177         _ascending = ascending;
178     }
179     
180
181
182 }
183
Popular Tags