001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.rice.kns.web.ui;
017
018import java.util.ArrayList;
019import java.util.List;
020
021/**
022 * This class represents a section (tab) in a maintenance document.
023 *
024 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
025 */
026@Deprecated
027public class Section implements java.io.Serializable {
028    private static final long serialVersionUID = 390440643941774650L;
029    String sectionTitle;
030    String sectionId;
031    String errorKey = "";
032    int numberOfColumns;
033    boolean isCollapsible = true;
034    String extraButtonSource;
035    boolean hidden = false;
036    boolean readOnly = false;
037    String helpUrl="";
038
039    boolean defaultOpen = true;
040    
041    Class sectionClass;
042    List<Row> rows;
043    List<String> containedCollectionNames = new ArrayList();
044
045    /**
046     * Default constructor, initializes
047     */
048    public Section() {
049    }
050
051    /**
052     * Constructor which sets section rows
053     * 
054     * @param rows the rows to be displayed in the section
055     */
056    public Section(List rows) {
057        this.rows = rows;
058    }
059
060
061    /**
062     * @return Returns the errorKey.
063     */
064    public String getErrorKey() {
065        return errorKey;
066    }
067
068
069    /**
070     * @param errorKey The errorKey to set.
071     */
072    public void setErrorKey(String errorKey) {
073        this.errorKey = errorKey;
074    }
075
076
077    /**
078     * @return Returns the rows.
079     */
080    public List<Row> getRows() {
081        return rows;
082    }
083
084
085    /**
086     * @param rows The rows to set.
087     */
088    public void setRows(List<Row> rows) {
089        this.rows = rows;
090    }
091
092
093    /**
094     * @return Returns the sectionTitle.
095     */
096    public String getSectionTitle() {
097        return sectionTitle;
098    }
099
100
101    /**
102     * @param sectionTitle The sectionTitle to set.
103     */
104    public void setSectionTitle(String sectionTitle) {
105        this.sectionTitle = sectionTitle;
106    }
107
108
109    /**
110     * @return Returns the isCollapsible.
111     */
112    public boolean isCollapsible() {
113        return isCollapsible;
114    }
115
116
117    /**
118     * @param isCollapsible The isCollapsible to set.
119     */
120    public void setCollapsible(boolean isCollapsible) {
121        this.isCollapsible = isCollapsible;
122    }
123
124
125    /**
126     * @return Returns the sectionClass.
127     */
128    public Class getSectionClass() {
129        return sectionClass;
130    }
131
132
133    /**
134     * @param sectionClass The sectionClass to set.
135     */
136    public void setSectionClass(Class sectionClass) {
137        this.sectionClass = sectionClass;
138    }
139
140
141    public int getNumberOfColumns() {
142        if (numberOfColumns != 0) {
143            return numberOfColumns;
144        } else {
145            //by default, return 1 if not specified in the maintenance document data dictionary
146            return 1;
147        }
148    }
149
150    public void setNumberOfColumns(int numberOfColumns) {
151        this.numberOfColumns = numberOfColumns;
152    }
153    
154
155    /**
156     * Gets the containedCollectionNames attribute. 
157     * @return Returns the containedCollectionNames.
158     */
159    public List<String> getContainedCollectionNames() {
160        return containedCollectionNames;
161    }
162
163    /**
164     * Sets the containedCollectionNames attribute value.
165     * @param containedCollectionNames The containedCollectionNames to set.
166     */
167    public void setContainedCollectionNames(List<String> containedCollectionNames) {
168        this.containedCollectionNames = containedCollectionNames;
169    }
170    
171    /**
172     * @return the extraButtonSource
173     */
174    public String getExtraButtonSource() {
175        return extraButtonSource;
176    }
177
178    /**
179     * @param extraButtonSource the extraButtonSource to set
180     */
181    public void setExtraButtonSource(String extraButtonSource) {
182        this.extraButtonSource = extraButtonSource;
183    }
184
185    /**
186     * @return Returns the fieldCnt.
187     */
188    public int getFieldCnt() {
189        if (rows != null && !rows.isEmpty()) {
190            Row firstRow = rows.get(0);
191            List<Field> rowFields = firstRow.getFields();
192            Field firstElement = rowFields.get(0);
193            //if the field is a container, set the rowFields to its containerRows.
194            if (Field.CONTAINER.equals(firstElement.getFieldType())) {
195                if (firstElement.getContainerRows().size() > 0) {
196                    rowFields = firstElement.getContainerRows().get(0).getFields();
197                }
198            }
199            if (rowFields.size() == 1) {
200                int i = 1;
201                while (i < rows.size() &&(Field.SUB_SECTION_SEPARATOR.equals(firstElement.getFieldType()) ||
202                                          Field.HIDDEN.equals(firstElement.getFieldType()))) {
203                    Row aRow = rows.get(i);
204                    rowFields = aRow.getFields();
205                    firstElement = rowFields.get(0);
206                    i++;
207                }
208            }
209            int cnt = 0;
210            for (Field element : rowFields ) {
211                // all fields except image type have a label and control cell
212                if (!Field.IMAGE_SUBMIT.equals(element.getFieldType())) {
213                    cnt += 2;
214                }
215            }
216            return cnt;
217        }
218        else {
219            return 0;
220        }
221    }
222
223    public String getSectionId() {
224        return this.sectionId;
225    }
226
227    public void setSectionId(String sectionId) {
228        this.sectionId = sectionId;
229    }
230
231    public boolean isHidden() {
232        return this.hidden;
233    }
234
235    public void setHidden(boolean hidden) {
236        this.hidden = hidden;
237    }
238
239        /**
240         * @return the readOnly
241         */
242        public boolean isReadOnly() {
243                return this.readOnly;
244        }
245
246        /**
247         * @param readOnly the readOnly to set
248         */
249        public void setReadOnly(boolean readOnly) {
250                this.readOnly = readOnly;
251        }
252
253        /**
254         * @return whether the section should be open by default when rendered
255         */
256        public boolean isDefaultOpen() {
257                return this.defaultOpen;
258        }
259
260        /**
261         * @param defaultOpen the defaultOpen to set
262         */
263        public void setDefaultOpen(boolean defaultOpen) {
264                this.defaultOpen = defaultOpen;
265        }
266
267        public String getHelpUrl() {
268                return helpUrl;
269        }
270
271        public void setHelpUrl(String helpUrl) {
272                this.helpUrl = helpUrl;
273        }
274        
275}