1 13 14 package org.ejbca.ui.web.admin.approval; 15 16 import java.util.AbstractList ; 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.Collections ; 20 import java.util.Comparator ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.ejbca.core.model.approval.ApprovalDataVO; 25 26 32 33 public class ApprovalDataVOViewList extends AbstractList implements java.io.Serializable { 34 35 44 private static final long serialVersionUID = 1680993305950225012L; 45 46 List listData; 47 48 public ApprovalDataVOViewList(Collection approvalDataVOs){ 49 listData = new ArrayList (); 50 Iterator iter = approvalDataVOs.iterator(); 51 while(iter.hasNext()){ 52 listData.add(new ApprovalDataVOView((ApprovalDataVO) iter.next())); 53 } 54 55 } 56 57 58 59 public Object 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 _sort; 70 private boolean _ascending; 71 72 73 76 protected void sort(final String column, final boolean ascending){ 77 78 79 Comparator comparator = new Comparator () 80 { 81 public int compare(Object o1, Object 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 117 protected boolean isDefaultAscending(String sortColumn){ 118 return true; 119 } 120 121 122 public void sort(String sortColumn) 123 { 124 if (sortColumn == null) 125 { 126 throw new IllegalArgumentException ("Argument sortColumn must not be null."); 127 } 128 129 if (_sort.equals(sortColumn)) 130 { 131 _ascending = !_ascending; 133 } 134 else 135 { 136 _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 getData() 150 { 151 sort(getSort(), isAscending()); 152 return this; 153 } 154 public void setData(List data) 155 { 156 157 } 158 159 public String getSort() 160 { 161 162 return _sort; 163 } 164 165 public void setSort(String 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 |