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.kns.web.ui;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  /**
22   * This class represents a section (tab) in a maintenance document.
23   */
24  public class Section implements java.io.Serializable {
25      private static final long serialVersionUID = 390440643941774650L;
26      String sectionTitle;
27      String sectionId;
28      String errorKey = "";
29      int numberOfColumns;
30      boolean isCollapsible = true;
31      String extraButtonSource;
32      boolean hidden = false;
33      boolean readOnly = false;
34      String helpUrl="";
35  
36      boolean defaultOpen = true;
37      
38      Class sectionClass;
39      List<Row> rows;
40      List<String> containedCollectionNames = new ArrayList();
41  
42      /**
43       * Default constructor, initializes
44       */
45      public Section() {
46      }
47  
48      /**
49       * Constructor which sets section rows
50       * 
51       * @param rows the rows to be displayed in the section
52       */
53      public Section(List rows) {
54          this.rows = rows;
55      }
56  
57  
58      /**
59       * @return Returns the errorKey.
60       */
61      public String getErrorKey() {
62          return errorKey;
63      }
64  
65  
66      /**
67       * @param errorKey The errorKey to set.
68       */
69      public void setErrorKey(String errorKey) {
70          this.errorKey = errorKey;
71      }
72  
73  
74      /**
75       * @return Returns the rows.
76       */
77      public List<Row> getRows() {
78          return rows;
79      }
80  
81  
82      /**
83       * @param rows The rows to set.
84       */
85      public void setRows(List<Row> rows) {
86          this.rows = rows;
87      }
88  
89  
90      /**
91       * @return Returns the sectionTitle.
92       */
93      public String getSectionTitle() {
94          return sectionTitle;
95      }
96  
97  
98      /**
99       * @param sectionTitle The sectionTitle to set.
100      */
101     public void setSectionTitle(String sectionTitle) {
102         this.sectionTitle = sectionTitle;
103     }
104 
105 
106     /**
107      * @return Returns the isCollapsible.
108      */
109     public boolean isCollapsible() {
110         return isCollapsible;
111     }
112 
113 
114     /**
115      * @param isCollapsible The isCollapsible to set.
116      */
117     public void setCollapsible(boolean isCollapsible) {
118         this.isCollapsible = isCollapsible;
119     }
120 
121 
122     /**
123      * @return Returns the sectionClass.
124      */
125     public Class getSectionClass() {
126         return sectionClass;
127     }
128 
129 
130     /**
131      * @param sectionClass The sectionClass to set.
132      */
133     public void setSectionClass(Class sectionClass) {
134         this.sectionClass = sectionClass;
135     }
136 
137 
138     public int getNumberOfColumns() {
139         if (numberOfColumns != 0) {
140             return numberOfColumns;
141         } else {
142             //by default, return 1 if not specified in the maintenance document data dictionary
143             return 1;
144         }
145     }
146 
147     public void setNumberOfColumns(int numberOfColumns) {
148         this.numberOfColumns = numberOfColumns;
149     }
150     
151 
152     /**
153      * Gets the containedCollectionNames attribute. 
154      * @return Returns the containedCollectionNames.
155      */
156     public List<String> getContainedCollectionNames() {
157         return containedCollectionNames;
158     }
159 
160     /**
161      * Sets the containedCollectionNames attribute value.
162      * @param containedCollectionNames The containedCollectionNames to set.
163      */
164     public void setContainedCollectionNames(List<String> containedCollectionNames) {
165         this.containedCollectionNames = containedCollectionNames;
166     }
167     
168     /**
169      * @return the extraButtonSource
170      */
171     public String getExtraButtonSource() {
172         return extraButtonSource;
173     }
174 
175     /**
176      * @param extraButtonSource the extraButtonSource to set
177      */
178     public void setExtraButtonSource(String extraButtonSource) {
179         this.extraButtonSource = extraButtonSource;
180     }
181 
182     /**
183      * @return Returns the fieldCnt.
184      */
185     public int getFieldCnt() {
186         if (rows != null && !rows.isEmpty()) {
187             Row firstRow = rows.get(0);
188             List<Field> rowFields = firstRow.getFields();
189             Field firstElement = rowFields.get(0);
190             //if the field is a container, set the rowFields to its containerRows.
191             if (Field.CONTAINER.equals(firstElement.getFieldType())) {
192                 if (firstElement.getContainerRows().size() > 0) {
193                     rowFields = firstElement.getContainerRows().get(0).getFields();
194                 }
195             }
196             if (rowFields.size() == 1) {
197                 int i = 1;
198                 while (i < rows.size() &&(Field.SUB_SECTION_SEPARATOR.equals(firstElement.getFieldType()) ||
199                                           Field.HIDDEN.equals(firstElement.getFieldType()))) {
200                     Row aRow = rows.get(i);
201                     rowFields = aRow.getFields();
202                     firstElement = rowFields.get(0);
203                     i++;
204                 }
205             }
206             int cnt = 0;
207             for (Field element : rowFields ) {
208                 // all fields except image type have a label and control cell
209                 if (!Field.IMAGE_SUBMIT.equals(element.getFieldType())) {
210                     cnt += 2;
211                 }
212             }
213             return cnt;
214         }
215         else {
216             return 0;
217         }
218     }
219 
220     public String getSectionId() {
221         return this.sectionId;
222     }
223 
224     public void setSectionId(String sectionId) {
225         this.sectionId = sectionId;
226     }
227 
228     public boolean isHidden() {
229         return this.hidden;
230     }
231 
232     public void setHidden(boolean hidden) {
233         this.hidden = hidden;
234     }
235 
236 	/**
237 	 * @return the readOnly
238 	 */
239 	public boolean isReadOnly() {
240 		return this.readOnly;
241 	}
242 
243 	/**
244 	 * @param readOnly the readOnly to set
245 	 */
246 	public void setReadOnly(boolean readOnly) {
247 		this.readOnly = readOnly;
248 	}
249 
250 	/**
251 	 * @return whether the section should be open by default when rendered
252 	 */
253 	public boolean isDefaultOpen() {
254 		return this.defaultOpen;
255 	}
256 
257 	/**
258 	 * @param defaultOpen the defaultOpen to set
259 	 */
260 	public void setDefaultOpen(boolean defaultOpen) {
261 		this.defaultOpen = defaultOpen;
262 	}
263 
264 	public String getHelpUrl() {
265 		return helpUrl;
266 	}
267 
268 	public void setHelpUrl(String helpUrl) {
269 		this.helpUrl = helpUrl;
270 	}
271 	
272 }