001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.web.ui;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: /**
022: * This class represents a section (tab) in a maintenance document.
023: */
024: public class Section implements java.io.Serializable {
025: private static final long serialVersionUID = 390440643941774650L;
026: String sectionTitle;
027: String errorKey = "";
028: int numberOfColumns;
029: boolean isCollapsible;
030: String extraButtonSource;
031:
032: Class sectionClass;
033: List<Row> rows;
034: List<String> containedCollectionNames;
035:
036: /**
037: * Default constructor, initializes
038: */
039: public Section() {
040: isCollapsible = true;
041: containedCollectionNames = new ArrayList();
042: }
043:
044: /**
045: * Constructor which sets section rows
046: *
047: * @param rows the rows to be displayed in the section
048: */
049: public Section(List rows) {
050: this .rows = rows;
051: isCollapsible = true;
052: containedCollectionNames = new ArrayList();
053: }
054:
055: /**
056: * @return Returns the errorKey.
057: */
058: public String getErrorKey() {
059: return errorKey;
060: }
061:
062: /**
063: * @param errorKey The errorKey to set.
064: */
065: public void setErrorKey(String errorKey) {
066: this .errorKey = errorKey;
067: }
068:
069: /**
070: * @return Returns the rows.
071: */
072: public List<Row> getRows() {
073: return rows;
074: }
075:
076: /**
077: * @param rows The rows to set.
078: */
079: public void setRows(List<Row> rows) {
080: this .rows = rows;
081: }
082:
083: /**
084: * @return Returns the sectionTitle.
085: */
086: public String getSectionTitle() {
087: return sectionTitle;
088: }
089:
090: /**
091: * @param sectionTitle The sectionTitle to set.
092: */
093: public void setSectionTitle(String sectionTitle) {
094: this .sectionTitle = sectionTitle;
095: }
096:
097: /**
098: * @return Returns the isCollapsible.
099: */
100: public boolean isCollapsible() {
101: return isCollapsible;
102: }
103:
104: /**
105: * @param isCollapsible The isCollapsible to set.
106: */
107: public void setCollapsible(boolean isCollapsible) {
108: this .isCollapsible = isCollapsible;
109: }
110:
111: /**
112: * @return Returns the sectionClass.
113: */
114: public Class getSectionClass() {
115: return sectionClass;
116: }
117:
118: /**
119: * @param sectionClass The sectionClass to set.
120: */
121: public void setSectionClass(Class sectionClass) {
122: this .sectionClass = sectionClass;
123: }
124:
125: public int getNumberOfColumns() {
126: if (numberOfColumns != 0) {
127: return numberOfColumns;
128: } else {
129: //by default, return 1 if not specified in the maintenance document data dictionary
130: return 1;
131: }
132: }
133:
134: public void setNumberOfColumns(int numberOfColumns) {
135: this .numberOfColumns = numberOfColumns;
136: }
137:
138: /**
139: * Gets the containedCollectionNames attribute.
140: * @return Returns the containedCollectionNames.
141: */
142: public List<String> getContainedCollectionNames() {
143: return containedCollectionNames;
144: }
145:
146: /**
147: * Sets the containedCollectionNames attribute value.
148: * @param containedCollectionNames The containedCollectionNames to set.
149: */
150: public void setContainedCollectionNames(
151: List<String> containedCollectionNames) {
152: this .containedCollectionNames = containedCollectionNames;
153: }
154:
155: /**
156: * @return the extraButtonSource
157: */
158: public String getExtraButtonSource() {
159: return extraButtonSource;
160: }
161:
162: /**
163: * @param extraButtonSource the extraButtonSource to set
164: */
165: public void setExtraButtonSource(String extraButtonSource) {
166: this .extraButtonSource = extraButtonSource;
167: }
168:
169: /**
170: * @return Returns the fieldCnt.
171: */
172: public int getFieldCnt() {
173: if (rows != null && !rows.isEmpty()) {
174: Row firstRow = rows.get(0);
175: List<Field> rowFields = firstRow.getFields();
176: Field firstElement = rowFields.get(0);
177: //if the field is a container, set the rowFields to its containerRows.
178: if (Field.CONTAINER.equals(firstElement.getFieldType())) {
179: if (firstElement.getContainerRows().size() > 0) {
180: rowFields = firstElement.getContainerRows().get(0)
181: .getFields();
182: }
183: }
184: if (rowFields.size() == 1) {
185: int i = 1;
186: while (i < rows.size()
187: && (Field.SUB_SECTION_SEPARATOR
188: .equals(firstElement.getFieldType()) || Field.HIDDEN
189: .equals(firstElement.getFieldType()))) {
190: Row aRow = rows.get(i);
191: rowFields = aRow.getFields();
192: firstElement = rowFields.get(0);
193: i++;
194: }
195: }
196: int cnt = 0;
197: for (Field element : rowFields) {
198: // all fields except image type have a label and control cell
199: if (!Field.IMAGE_SUBMIT.equals(element.getFieldType())) {
200: cnt += 2;
201: }
202: }
203: return cnt;
204: } else {
205: return 0;
206: }
207: }
208: }
|