1 18 package org.apache.beehive.netui.databinding.datagrid.api.sort; 19 20 import java.util.List ; 21 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection; 22 23 45 public class SortModel 46 implements java.io.Serializable { 47 48 49 50 51 private SortStrategy _sortStrategy = null; 52 private List _sorts = null; 53 54 58 public SortModel(List sorts) { 59 _sorts = sorts; 60 } 61 62 67 public SortStrategy getSortStrategy() { 68 return _sortStrategy; 69 } 70 71 75 public void setSortStrategy(SortStrategy sortStrategy) { 76 _sortStrategy = sortStrategy; 77 } 78 79 public List getSorts() { 80 if(_sorts == null) 81 return null; 82 else 83 return _sorts; 84 } 85 86 96 public boolean isPrimarySort(String sortExpression) { 97 if(sortExpression == null) 98 return false; 99 100 101 if(_sorts != null && 102 _sorts.size() > 0 && 103 ((Sort)_sorts.get(0)).getSortExpression().equals(sortExpression)) { 104 return true; 105 } 106 else 107 return false; 108 } 109 110 118 public boolean isSorted(String sortExpression) { 119 if(sortExpression == null) 120 return false; 121 122 Sort term = findSort(sortExpression); 123 if(term == null || term.getDirection() == SortDirection.NONE) 124 return false; 125 else return true; 126 } 127 128 135 public SortDirection getSortDirection(String sortExpression) { 136 Sort term = findSort(sortExpression); 137 return term == null ? SortDirection.NONE : term.getDirection(); 138 } 139 140 148 public Sort lookupSort(String sortExpression) { 149 return findSort(sortExpression); 150 } 151 152 private final Sort findSort(String sortExpression) { 153 if(_sorts == null) 154 return null; 155 156 for(int i = 0; i < _sorts.size(); i++) { 157 assert _sorts.get(i) instanceof Sort; 158 Sort sort = (Sort)_sorts.get(i); 159 if(sort.getSortExpression().equals(sortExpression)) 160 return sort; 161 } 162 163 return null; 164 } 165 } 166 | Popular Tags |