View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.docsearch;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  
23  /**
24   * Class to hold management capabilities for standard document search. 
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   *
28   */
29  public class StandardDocSearchCriteriaManager implements java.io.Serializable {
30  	
31  	private static final long serialVersionUID = -1898076444679158722L;
32  	
33      private List<List<StandardDocSearchCriteriaFieldContainer>> columnsPreSearchAttributes = new ArrayList<List<StandardDocSearchCriteriaFieldContainer>>();
34  	private List<List<StandardDocSearchCriteriaFieldContainer>> columnsPostSearchAttributes = new ArrayList<List<StandardDocSearchCriteriaFieldContainer>>();
35  	
36  	public StandardDocSearchCriteriaManager(int preSearchAttributeColumns, int postSearchAttributeColumns, boolean searchCriteriaDisplayed, boolean headerBarDisplayed) {
37  		setupColumns(preSearchAttributeColumns,postSearchAttributeColumns);
38  	}
39  	
40  	private void setupColumns(int preSearchAttributeColumns, int postSearchAttributeColumns) {
41  		for (int i = 0; i < preSearchAttributeColumns; i++) {
42  			columnsPreSearchAttributes.add(new ArrayList<StandardDocSearchCriteriaFieldContainer>());
43  		}
44  		for (int i = 0; i < postSearchAttributeColumns; i++) {
45  			columnsPostSearchAttributes.add(new ArrayList<StandardDocSearchCriteriaFieldContainer>());
46  		}
47  	}
48  	
49  	public List<StandardDocSearchCriteriaFieldContainer> getPreSearchAttributeMaxRows() {
50  		return getMaxRowsForList(columnsPreSearchAttributes);
51  	}
52  	
53  	public List<StandardDocSearchCriteriaFieldContainer> getPostSearchAttributeMaxRows() {
54  		return getMaxRowsForList(columnsPostSearchAttributes);
55  	}
56  	
57  	@SuppressWarnings("unchecked")
58  	private List<StandardDocSearchCriteriaFieldContainer> getMaxRowsForList(List<List<StandardDocSearchCriteriaFieldContainer>> columns) {
59  		List<StandardDocSearchCriteriaFieldContainer> biggestFieldContainerList = null;
60  		for (Iterator iter = columns.iterator(); iter.hasNext();) {
61  			List<StandardDocSearchCriteriaFieldContainer> fieldContainerList = (List<StandardDocSearchCriteriaFieldContainer>) iter.next();
62  			if (biggestFieldContainerList == null) {
63  				biggestFieldContainerList = fieldContainerList;
64  			} else {
65  				if (fieldContainerList.size() > biggestFieldContainerList.size()) {
66  					biggestFieldContainerList = fieldContainerList;
67  				}
68  			}
69  		}
70  		return biggestFieldContainerList;
71  	}
72  	
73  	public int getMaxColumnCount() {
74  		return Math.max(columnsPreSearchAttributes.size(), columnsPostSearchAttributes.size());
75  	}
76  
77      public List<List<StandardDocSearchCriteriaFieldContainer>> getColumnsPreSearchAttributes() {
78  		return this.columnsPreSearchAttributes;
79  	}
80  
81  	public void setColumnsPreSearchAttributes(List<List<StandardDocSearchCriteriaFieldContainer>> columnsPreSearchAttributes) {
82  		this.columnsPreSearchAttributes = columnsPreSearchAttributes;
83  	}
84  
85  	public List<List<StandardDocSearchCriteriaFieldContainer>> getColumnsPostSearchAttributes() {
86  		return this.columnsPostSearchAttributes;
87  	}
88  
89  	public void setColumnsPostSearchAttributes(List<List<StandardDocSearchCriteriaFieldContainer>> columnsPostSearchAttributes) {
90  		this.columnsPostSearchAttributes = columnsPostSearchAttributes;
91  	}
92  	
93  }