1 /**
2 * Copyright 2005-2014 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.krad.uif.container.collections;
17
18 import org.kuali.rice.krad.uif.UifConstants;
19 import org.kuali.rice.krad.uif.component.Component;
20 import org.kuali.rice.krad.uif.container.CollectionGroup;
21 import org.kuali.rice.krad.uif.container.DialogGroup;
22 import org.kuali.rice.krad.uif.field.Field;
23 import org.kuali.rice.krad.uif.field.FieldGroup;
24 import org.kuali.rice.krad.uif.layout.CollectionLayoutManager;
25 import org.kuali.rice.krad.uif.view.ViewModel;
26
27 import java.io.Serializable;
28 import java.util.Collections;
29 import java.util.List;
30
31 /**
32 * Holds components and configuration for a line during the build process.
33 *
34 * @author Kuali Rice Team (rice.collab@kuali.org)
35 * @see org.kuali.rice.krad.uif.container.CollectionGroupBuilder
36 * @see org.kuali.rice.krad.uif.container.CollectionGroupLineBuilder
37 */
38 public class LineBuilderContext implements Serializable {
39 private static final long serialVersionUID = -2025777471407211781L;
40
41 private int lineIndex;
42 private Object currentLine;
43 private String bindingPath;
44 private boolean bindToForm;
45
46 private ViewModel model;
47 private CollectionGroup collectionGroup;
48
49 private List<? extends Component> lineActions;
50 private List<Field> lineFields;
51 private List<FieldGroup> subCollectionFields;
52 private List<DialogGroup> lineDialogs;
53
54 /**
55 * Empty constructor.
56 */
57 public LineBuilderContext() {
58
59 }
60
61 /**
62 * Constructor.
63 *
64 * @param lineIndex index of line
65 * @param currentLine object containing the line data
66 * @param bindingPath path to the line in the model
67 * @param bindToForm indicates if the line fields bind to the form (not the default object path)
68 * @param model object containing the views data
69 * @param collectionGroup collection group instance the line is being built for
70 * @param lineActions list of components for the lines action column
71 */
72 public LineBuilderContext(int lineIndex, Object currentLine, String bindingPath, boolean bindToForm, ViewModel model,
73 CollectionGroup collectionGroup, List<? extends Component> lineActions) {
74 this.lineIndex = lineIndex;
75 this.currentLine = currentLine;
76 this.bindingPath = bindingPath;
77 this.bindToForm = bindToForm;
78 this.model = model;
79 this.collectionGroup = collectionGroup;
80 this.lineActions = lineActions;
81 this.lineDialogs = Collections.emptyList();
82 }
83
84 /**
85 * Constructor.
86 *
87 * @param lineIndex index of line
88 * @param currentLine object containing the line data
89 * @param bindingPath path to the line in the model
90 * @param bindToForm indicates if the line fields bind to the form (not the default object path)
91 * @param model object containing the views data
92 * @param collectionGroup collection group instance the line is being built for
93 * @param lineActions list of components for the lines action column
94 * @param lineDialogs list of dialogs configured on the line
95 */
96 public LineBuilderContext(int lineIndex, Object currentLine, String bindingPath, boolean bindToForm, ViewModel model,
97 CollectionGroup collectionGroup, List<? extends Component> lineActions, List<DialogGroup> lineDialogs) {
98 this.lineIndex = lineIndex;
99 this.currentLine = currentLine;
100 this.bindingPath = bindingPath;
101 this.bindToForm = bindToForm;
102 this.model = model;
103 this.collectionGroup = collectionGroup;
104 this.lineActions = lineActions;
105 this.lineDialogs = lineDialogs;
106 }
107
108 /**
109 * Suffix to use for adjusting the ids on components within the line.
110 *
111 * @return String id suffix
112 */
113 public String getIdSuffix() {
114 String idSuffix;
115
116 if (isAddLine()) {
117 idSuffix = UifConstants.IdSuffixes.ADD_LINE;
118 } else {
119 idSuffix = UifConstants.IdSuffixes.LINE + Integer.toString(lineIndex);
120 }
121
122 return idSuffix;
123 }
124
125 /**
126 * Indicates whether the line is the add line, or an existing collection line.
127 *
128 * @return boolean true if the line is the add line, false if not
129 */
130 public boolean isAddLine() {
131 return this.lineIndex == -1;
132 }
133
134 /**
135 * Returns the {@link org.kuali.rice.krad.uif.layout.CollectionLayoutManager} configured on the collection
136 * group.
137 *
138 * @return collection layout manager instance
139 */
140 public CollectionLayoutManager getLayoutManager() {
141 if (this.collectionGroup != null) {
142 return (CollectionLayoutManager) this.collectionGroup.getLayoutManager();
143 }
144
145 return null;
146 }
147
148 /**
149 * Index for the line within the collection, or -1 for the add line.
150 *
151 * @return line index
152 */
153 public int getLineIndex() {
154 return lineIndex;
155 }
156
157 /**
158 * @see LineBuilderContext#getLineIndex()
159 */
160 public void setLineIndex(int lineIndex) {
161 this.lineIndex = lineIndex;
162 }
163
164 /**
165 * Object containing the line's data.
166 *
167 * @return object instance
168 */
169 public Object getCurrentLine() {
170 return currentLine;
171 }
172
173 /**
174 * @see LineBuilderContext#getCurrentLine()
175 */
176 public void setCurrentLine(Object currentLine) {
177 this.currentLine = currentLine;
178 }
179
180 /**
181 * Path to the line in the full model.
182 *
183 * @return binding path
184 */
185 public String getBindingPath() {
186 return bindingPath;
187 }
188
189 /**
190 * @see LineBuilderContext#getBindingPath()
191 */
192 public void setBindingPath(String bindingPath) {
193 this.bindingPath = bindingPath;
194 }
195
196 /**
197 * Indicates if the line fields bind to the form (not the default object path).
198 *
199 * @return boolean true if line fields bindi to the form, false if not
200 */
201 public boolean isBindToForm() {
202 return bindToForm;
203 }
204
205 /**
206 * @see LineBuilderContext#isBindToForm()
207 */
208 public void setBindToForm(boolean bindToForm) {
209 this.bindToForm = bindToForm;
210 }
211
212 /**
213 * Object containing the view's data.
214 *
215 * @return model instance
216 */
217 public ViewModel getModel() {
218 return model;
219 }
220
221 /**
222 * @see LineBuilderContext#getModel()
223 */
224 public void setModel(ViewModel model) {
225 this.model = model;
226 }
227
228 /**
229 * Collection group the line is being built for.
230 *
231 * @return collection group instance
232 */
233 public CollectionGroup getCollectionGroup() {
234 return collectionGroup;
235 }
236
237 /**
238 * @see LineBuilderContext#getCollectionGroup()
239 */
240 public void setCollectionGroup(CollectionGroup collectionGroup) {
241 this.collectionGroup = collectionGroup;
242 }
243
244 /**
245 * List of components to render in the lines action column.
246 *
247 * @return list of component instances
248 */
249 public List<? extends Component> getLineActions() {
250 return lineActions;
251 }
252
253 /**
254 * @see LineBuilderContext#getLineActions()
255 */
256 public void setLineActions(List<? extends Component> lineActions) {
257 this.lineActions = lineActions;
258 }
259
260 /**
261 * List of field instances that make up the lines columns.
262 *
263 * @return list of field instances.
264 */
265 public List<Field> getLineFields() {
266 return lineFields;
267 }
268
269 /**
270 * @see LineBuilderContext#getLineFields()
271 */
272 public void setLineFields(List<Field> lineFields) {
273 this.lineFields = lineFields;
274 }
275
276 /**
277 * List of field groups that wrap the sub-collections for the line.
278 *
279 * @return list of field groups instances
280 */
281 public List<FieldGroup> getSubCollectionFields() {
282 return subCollectionFields;
283 }
284
285 /**
286 * @see LineBuilderContext#getSubCollectionFields()
287 */
288 public void setSubCollectionFields(List<FieldGroup> subCollectionFields) {
289 this.subCollectionFields = subCollectionFields;
290 }
291
292 /**
293 * List of dialog groups that make up the lines dialogs.
294 *
295 * @return list of field instances.
296 */
297 public List<DialogGroup> getLineDialogs() {
298 return lineDialogs;
299 }
300
301 /**
302 * @see org.kuali.rice.krad.uif.container.collections.LineBuilderContext#getDialogGroups()
303 */
304 public void setLineDialogs(List<DialogGroup> dialogGroups) {
305 this.lineDialogs = dialogGroups;
306 }
307 }