1 24 package org.riotfamily.riot.list.support; 25 26 import java.util.Iterator ; 27 import java.util.LinkedList ; 28 import java.util.List ; 29 30 import org.riotfamily.riot.dao.ListParams; 31 import org.riotfamily.riot.dao.Order; 32 33 36 public class ListParamsImpl implements ListParams { 37 38 private Object filter; 39 40 private String [] filteredProperties; 41 42 private String search; 43 44 private String [] searchProperties; 45 46 private List order; 47 48 private int pageSize; 49 50 private int offset; 51 52 53 public ListParamsImpl() { 54 } 55 56 public Object getFilter() { 57 return filter; 58 } 59 60 public void setFilter(Object filter) { 61 this.filter = filter; 62 } 63 64 public String [] getFilteredProperties() { 65 return this.filteredProperties; 66 } 67 68 public void setFilteredProperties(String [] filterProperties) { 69 this.filteredProperties = filterProperties; 70 } 71 72 public String getSearch() { 73 return this.search; 74 } 75 76 public void setSearch(String search) { 77 this.search = search; 78 } 79 80 public String [] getSearchProperties() { 81 return this.searchProperties; 82 } 83 84 public void setSearchProperties(String [] searchProperties) { 85 this.searchProperties = searchProperties; 86 } 87 88 public int getOffset() { 89 return offset; 90 } 91 92 public void setOffset(int offset) { 93 this.offset = offset; 94 } 95 96 public int getPage() { 97 return offset / pageSize + 1; 98 } 99 100 public void setPage(int page) { 101 offset = (page - 1) * pageSize; 102 } 103 104 public List getOrder() { 105 return order; 106 } 107 108 public void setOrder(List order) { 109 this.order = order; 110 } 111 112 public void setOrder(Order order) { 113 this.order = new LinkedList (); 114 if (order != null) { 115 this.order.add(order); 116 } 117 } 118 119 public boolean hasOrder() { 120 return order != null && !order.isEmpty(); 121 } 122 123 public Order getPrimaryOrder() { 124 if (!hasOrder()) { 125 return null; 126 } 127 return (Order) getOrder().get(0); 128 } 129 130 136 public void orderBy(String property, boolean ascending, boolean caseSensitive) { 137 if (getOrder() == null) { 138 setOrder(new LinkedList ()); 139 } 140 else { 141 Order primary = getPrimaryOrder(); 142 if (primary != null && primary.isProperty(property)) { 143 primary.toggleDirection(); 144 return; 145 } 146 Iterator it = getOrder().iterator(); 147 while (it.hasNext()) { 148 Order order = (Order) it.next(); 149 if (order.isProperty(property)) { 150 it.remove(); 151 } 152 } 153 } 154 getOrder().add(0, new Order(property, ascending, caseSensitive)); 155 } 156 157 public int getPageSize() { 158 return pageSize; 159 } 160 161 public void setPageSize(int pageSize) { 162 this.pageSize = pageSize; 163 } 164 165 } 166 | Popular Tags |