1 19 20 package com.sslexplorer.table.forms; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpSession ; 26 27 import org.apache.struts.action.ActionMapping; 28 29 import com.sslexplorer.core.forms.CoreForm; 30 import com.sslexplorer.navigation.AbstractFavoriteItem; 31 import com.sslexplorer.properties.PersistentSettings; 32 import com.sslexplorer.security.LogonControllerFactory; 33 import com.sslexplorer.security.SessionInfo; 34 import com.sslexplorer.table.Pager; 35 import com.sslexplorer.table.TableItemModel; 36 37 public class AbstractPagerForm extends CoreForm { 38 39 ArrayList accounts = new ArrayList (); 40 boolean isEditable; 41 TableItemModel model; 42 Pager pager; 43 int startRow; 44 String sortName; 45 boolean sortReverse; 46 int pageSize; 47 HttpSession session; 48 String filterText; 49 String selectedItem; 50 boolean filterMatchedNothing; 51 List userFavorites; 52 List globalFavorites; 53 String defaultSortColumnId; 54 55 public AbstractPagerForm(TableItemModel model) { 56 this.model = model; 57 pager = new Pager(model); 58 } 59 60 public List getUserFavorites() { 61 return userFavorites; 62 } 63 64 public void setUserFavorites(List userFavorites) { 65 this.userFavorites = userFavorites; 66 } 67 68 public List getGlobalFavorites() { 69 return globalFavorites; 70 } 71 72 public void setGlobalFavorites(List policyFavorites) { 73 this.globalFavorites = policyFavorites; 74 } 75 76 public String getFavoriteType(int resourceId) { 77 if(globalFavorites != null && globalFavorites.contains(new Integer (resourceId))) { 78 return AbstractFavoriteItem.GLOBAL_FAVORITE; 79 } 80 else if(userFavorites != null && userFavorites.contains(new Integer (resourceId))) { 81 return AbstractFavoriteItem.USER_FAVORITE; 82 } 83 else { 84 return AbstractFavoriteItem.NO_FAVORITE; 85 } 86 } 87 88 public TableItemModel getModel() { 89 return model; 90 } 91 92 public String getFilterText() { 93 return filterText; 94 } 95 96 public void setFilterText(String filterText) { 97 this.filterText = filterText; 98 } 99 100 public void initialize(HttpSession session, String defaultSortColumnId) { 101 this.session = session; 102 this.defaultSortColumnId = defaultSortColumnId; 103 model.clear(); 104 105 SessionInfo info = LogonControllerFactory.getInstance().getSessionInfo(session); 106 107 if(pageSize != -1) { 108 pager.setPageSize(pageSize); 109 PersistentSettings.setIntValue(info, "pager." + model.getId() + ".pageSize", pageSize, 10); 110 } 111 else { 112 pager.setPageSize(PersistentSettings.getIntValue(info, "pager." + model.getId() + ".pageSize", 10)); 113 } 114 115 if(startRow != -1) { 116 pager.setStartRow(startRow); 117 session.setAttribute("pager." + model.getId() + ".startRow", new Integer (startRow)); 118 } 119 else { 120 Integer startRowAttr = (Integer )session.getAttribute("pager." + model.getId() + ".startRow"); 121 if(startRowAttr != null) { 122 pager.setStartRow(startRowAttr.intValue()); 123 } 124 else { 125 pager.setStartRow(0); 126 } 127 } 128 checkSort(); 129 } 130 131 public String getSortName() { 132 return sortName; 133 } 134 135 public void setSortName(String sortName) { 136 this.sortName = sortName; 137 } 138 139 public boolean getSortReverse() { 140 return sortReverse; 141 } 142 143 public void setSortReverse(boolean sortReverse) { 144 this.sortReverse = sortReverse; 145 } 146 147 public int getStartRow() { 148 return startRow; 149 } 150 151 public void setStartRow(int startRow) { 152 this.startRow = startRow; 153 } 154 155 public int getPageSize() { 156 return pageSize; 157 } 158 159 public void setPageSize(int pageSize) { 160 this.pageSize = pageSize; 161 } 162 163 public Pager getPager() { 164 return pager; 165 } 166 167 public String getSelectedItem() { 168 return selectedItem; 169 } 170 171 public void setSelectedItem(String selectedItem) { 172 this.selectedItem = selectedItem; 173 } 174 175 public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { 176 startRow = -1; 177 sortName = null; 178 sortReverse = false; 179 pageSize = -1; 180 } 181 182 protected void checkSort() { 183 if(getSortName() != null) { 184 String sortId = getSortName().substring(getSortName().lastIndexOf(".") + 1); 185 getPager().setSortName(sortId); 186 getPager().setSortReverse(getSortReverse()); 187 session.setAttribute("pager." + model.getId() + ".sortName", sortId); 188 session.setAttribute("pager." + model.getId() + ".sortReverse", Boolean.valueOf(getSortReverse())); 189 } 190 else { 191 194 String lastSortName = (String )session.getAttribute("pager." + model.getId() + ".sortName"); 195 if(lastSortName != null) { 196 getPager().setSortName(lastSortName); 197 getPager().setSortReverse(((Boolean )session.getAttribute("pager." + model.getId() + ".sortReverse")).booleanValue()); 198 } 199 else { 200 String colId = defaultSortColumnId == null ? getModel().getColumnName(0) : defaultSortColumnId; 201 getPager().setSortName(colId); 202 getPager().setSortReverse(false); 203 } 204 setSortName(getPager().getSortName()); 205 setSortReverse(getPager().getSortReverse()); 206 } 207 } 208 } | Popular Tags |