1 17 package org.alfresco.web.config; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.alfresco.config.ConfigElement; 25 import org.alfresco.config.ConfigException; 26 import org.alfresco.config.element.ConfigElementAdapter; 27 28 33 public class ViewsConfigElement extends ConfigElementAdapter 34 { 35 public static final String CONFIG_ELEMENT_ID = "views"; 36 37 public static final String VIEW_DETAILS = "details"; 38 public static final String VIEW_ICONS = "icons"; 39 public static final String VIEW_LIST = "list"; 40 public static final String VIEW_BUBBLE = "bubble"; 41 public static final String SORT_ASCENDING = "ascending"; 42 public static final String SORT_DESCENDING = "descending"; 43 44 private static final String SEPARATOR = ":"; 45 46 private int defaultPageSize = 10; 48 private String defaultView = "details"; 49 private String defaultSortColumn = "name"; 50 51 private List <String > views = new ArrayList <String >(4); 53 54 private Map <String , String > defaultViews = new HashMap <String , String >(4); 56 57 private Map <String , Integer > pageSizes = new HashMap <String , Integer >(10); 59 60 private Map <String , String > sortColumns = new HashMap <String , String >(4); 62 63 private Map <String , String > sortDirections = new HashMap <String , String >(1); 65 66 69 public ViewsConfigElement() 70 { 71 super(CONFIG_ELEMENT_ID); 72 73 this.pageSizes.put(VIEW_DETAILS, defaultPageSize); 75 this.pageSizes.put(VIEW_LIST, defaultPageSize); 76 this.pageSizes.put(VIEW_ICONS, 9); 77 this.pageSizes.put(VIEW_BUBBLE, 5); 78 } 79 80 85 public ViewsConfigElement(String name) 86 { 87 super(name); 88 } 89 90 93 @Override 94 public List <ConfigElement> getChildren() 95 { 96 throw new ConfigException("Reading the views config via the generic interfaces is not supported"); 97 } 98 99 102 public ConfigElement combine(ConfigElement configElement) 103 { 104 ViewsConfigElement existingElement = (ViewsConfigElement)configElement; 105 ViewsConfigElement newElement = new ViewsConfigElement(); 106 107 for (String viewImpl : this.views) 109 { 110 newElement.addView(viewImpl); 111 } 112 113 for (String page : this.defaultViews.keySet()) 114 { 115 newElement.addDefaultView(page, this.defaultViews.get(page)); 116 } 117 118 for (String pageView : this.pageSizes.keySet()) 119 { 120 if (pageView.indexOf(SEPARATOR) != -1) 121 { 122 String page = pageView.substring(0, pageView.indexOf(SEPARATOR)); 123 String view = pageView.substring(pageView.indexOf(SEPARATOR)+1); 124 newElement.addDefaultPageSize(page, view, this.pageSizes.get(pageView).intValue()); 125 } 126 } 127 128 for (String page : this.sortColumns.keySet()) 129 { 130 newElement.addDefaultSortColumn(page, this.sortColumns.get(page)); 131 } 132 133 for (String page : this.sortDirections.keySet()) 134 { 135 newElement.addSortDirection(page, this.sortDirections.get(page)); 136 } 137 138 for (String viewImpl : existingElement.getViews()) 140 { 141 newElement.addView(viewImpl); 142 } 143 144 Map <String , String > existingDefaultViews = existingElement.getDefaultViews(); 145 for (String page : existingDefaultViews.keySet()) 146 { 147 newElement.addDefaultView(page, existingDefaultViews.get(page)); 148 } 149 150 Map <String , Integer > existingPageSizes = existingElement.getDefaultPageSizes(); 151 for (String pageView : existingPageSizes.keySet()) 152 { 153 if (pageView.indexOf(SEPARATOR) != -1) 154 { 155 String page = pageView.substring(0, pageView.indexOf(SEPARATOR)); 156 String view = pageView.substring(pageView.indexOf(SEPARATOR)+1); 157 newElement.addDefaultPageSize(page, view, existingPageSizes.get(pageView).intValue()); 158 } 159 } 160 161 Map <String , String > existingSortColumns = existingElement.getDefaultSortColumns(); 162 for (String page : existingSortColumns.keySet()) 163 { 164 newElement.addDefaultSortColumn(page, existingSortColumns.get(page)); 165 } 166 167 Map <String , String > existingSortDirs = existingElement.getSortDirections(); 168 for (String page : existingSortDirs.keySet()) 169 { 170 newElement.addSortDirection(page, existingSortDirs.get(page)); 171 } 172 173 return newElement; 174 } 175 176 181 void addView(String renderer) 182 { 183 this.views.add(renderer); 184 } 185 186 191 public List <String > getViews() 192 { 193 return this.views; 194 } 195 196 202 void addDefaultView(String page, String view) 203 { 204 this.defaultViews.put(page, view); 205 } 206 207 214 public String getDefaultView(String page) 215 { 216 String view = this.defaultViews.get(page); 217 218 if (view == null) 219 { 220 view = this.defaultView; 221 } 222 223 return view; 224 } 225 226 231 Map <String , String > getDefaultViews() 232 { 233 return this.defaultViews; 234 } 235 236 243 void addDefaultPageSize(String page, String view, int size) 244 { 245 this.pageSizes.put(page + SEPARATOR + view, new Integer (size)); 246 } 247 248 257 public int getDefaultPageSize(String page, String view) 258 { 259 Integer pageSize = this.pageSizes.get(page + SEPARATOR + view); 260 261 if (pageSize == null) 263 { 264 pageSize = this.pageSizes.get(view); 265 266 if (pageSize == null) 268 { 269 pageSize = new Integer (10); 270 } 271 } 272 273 return pageSize.intValue(); 274 } 275 276 281 Map <String , Integer > getDefaultPageSizes() 282 { 283 return this.pageSizes; 284 } 285 286 292 void addDefaultSortColumn(String page, String column) 293 { 294 this.sortColumns.put(page, column); 295 } 296 297 304 public String getDefaultSortColumn(String page) 305 { 306 String column = this.sortColumns.get(page); 307 308 if (column == null) 309 { 310 column = this.defaultSortColumn; 311 } 312 313 return column; 314 } 315 316 321 Map <String , String > getDefaultSortColumns() 322 { 323 return this.sortColumns; 324 } 325 326 332 void addSortDirection(String page, String dir) 333 { 334 this.sortDirections.put(page, dir); 335 } 336 337 344 public boolean hasDescendingSort(String page) 345 { 346 boolean usesDescendingSort = false; 347 348 String sortDir = this.sortDirections.get(page); 349 if (sortDir != null && sortDir.equalsIgnoreCase(SORT_DESCENDING)) 350 { 351 usesDescendingSort = true; 352 } 353 354 return usesDescendingSort; 355 } 356 357 362 Map <String , String > getSortDirections() 363 { 364 return this.sortDirections; 365 } 366 } 367 | Popular Tags |