1 16 package com.blandware.atleap.webapp.taglib.core.grid.util; 17 18 import org.apache.commons.lang.builder.ToStringBuilder; 19 import org.apache.commons.lang.builder.ToStringStyle; 20 21 import java.io.Serializable ; 22 import java.util.Collections ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 34 public class SortField implements Serializable { 35 36 38 41 public static final String ORDER_ASCENDING = "asc"; 42 43 46 public static final String ORDER_DESCENDING = "desc"; 47 48 50 53 protected String fieldName; 54 55 58 protected String property; 59 60 63 protected String order = ORDER_ASCENDING; 64 65 68 protected boolean orderChanged = false; 69 70 73 protected List rowIterators = Collections.synchronizedList(new LinkedList ()); 74 75 80 public SortField(String fieldName) { 81 this(fieldName, ORDER_ASCENDING); 82 } 83 84 90 public SortField(String fieldName, String order) { 91 this.fieldName = fieldName; 92 if ( ORDER_ASCENDING.equalsIgnoreCase(order) ) { 93 this.order = ORDER_ASCENDING; 94 } else { 95 this.order = ORDER_DESCENDING; 96 } 97 } 98 99 105 public String getFieldName() { 106 return fieldName; 107 } 108 109 115 public void setFieldName(String fieldName) { 116 this.fieldName = fieldName; 117 } 118 119 125 public String getProperty() { 126 return property; 127 } 128 129 135 public void setProperty(String property) { 136 this.property = property; 137 } 138 139 145 public String getOrder() { 146 return order; 147 } 148 149 155 public List getRowIterators() { 156 return rowIterators; 157 } 158 159 165 public void setRowIterators(List rowIterators) { 166 this.rowIterators = rowIterators; 167 } 168 169 175 public void addRowIterator(String rowIteratorId) { 176 this.rowIterators.add(rowIteratorId); 177 } 178 179 186 public String getClause(String rowIteratorId) { 187 if ( (rowIteratorId == null) || (rowIterators.size() == 0) || (rowIterators.contains(rowIteratorId)) ) { 188 return fieldName + " " + order; 189 } else { 190 return null; 191 } 192 } 193 194 199 public boolean isOrderAscending() { 200 return order.equalsIgnoreCase(ORDER_ASCENDING); 201 } 202 203 206 public void reverseOrder() { 207 if ( order.equalsIgnoreCase(ORDER_ASCENDING) ) { 208 order = ORDER_DESCENDING; 209 } else { 210 order = ORDER_ASCENDING; 211 } 212 orderChanged = true; 213 } 214 215 220 public boolean hasOrderChanged() { 221 boolean orderChanged = this.orderChanged; 222 223 this.orderChanged = false; 225 return orderChanged; 226 } 227 228 public String toString() { 229 return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); 230 } 231 232 239 public boolean equals(Object anObject) { 240 if ( anObject instanceof SortField ) { 241 SortField sortField = (SortField) anObject; 242 return (this.fieldName.equalsIgnoreCase(sortField.getFieldName())) && (this.order.equalsIgnoreCase(sortField.getOrder())); 243 } else { 244 return false; 245 } 246 } 247 248 253 public int hashCode() { 254 int result; 255 result = (fieldName != null ? fieldName.hashCode() : 0); 256 result = 29 * result + (order != null ? order.hashCode() : 0); 257 return result; 258 } 259 260 261 } 262 | Popular Tags |