1 /**
2 * Copyright 2005-2013 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.service;
17
18 import org.kuali.rice.krad.uif.container.CollectionGroup;
19 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
20 import org.kuali.rice.krad.uif.view.View;
21 import org.kuali.rice.krad.uif.component.Component;
22 import org.kuali.rice.krad.uif.widget.Inquiry;
23
24 import java.util.Map;
25
26 /**
27 * Provides methods for implementing the various phases of a <code>View</code>
28 *
29 * <ul>
30 * <li>Initialize Phase: Invoked when the view is first requested to setup
31 * necessary state</li>
32 * </ul>
33 *
34 * @author Kuali Rice Team (rice.collab@kuali.org)
35 */
36 public interface ViewHelperService {
37
38 /**
39 * Populates the <code>View</code> properties from the given request
40 * parameters
41 *
42 * <p>
43 * The <code>View</code> instance is inspected for fields that have the
44 * <code>RequestParameter</code> annotation and if corresponding parameters
45 * are found in the request parameter map, the request value is used to set
46 * the view property. The Map of parameter name/values that match are placed
47 * in the view so they can be later retrieved to rebuild the view. Custom
48 * <code>ViewServiceHelper</code> implementations can add additional
49 * parameter key/value pairs to the returned map if necessary.
50 * </p>
51 *
52 * @see org.kuali.rice.krad.uif.component.RequestParameter
53 */
54 public void populateViewFromRequestParameters(View view, Map<String, String> parameters);
55
56 /**
57 * Performs the Initialization phase for the <code>View</code>. During this
58 * phase each component of the tree is invoked to setup state based on the
59 * configuration and request options.
60 *
61 * <p>
62 * The initialize phase is only called once per <code>View</code> lifecycle
63 * </p>
64 *
65 * <p>
66 * Note the <code>View</code> instance also contains the context Map that
67 * was created based on the parameters sent to the view service
68 * </p>
69 *
70 * @param view View instance that should be initialized
71 * @param model object instance containing the view data
72 */
73 public void performInitialization(View view, Object model);
74
75 /**
76 * Performs the Initialization phase for the given <code>Component</code>
77 *
78 * <p>
79 * Can be called for component instances constructed via code or prototypes
80 * to initialize the constructed component
81 * </p>
82 *
83 * @param view view instance the component belongs to
84 * @param model object instance containing the view data
85 * @param component component instance that should be initialized
86 */
87 public void performComponentInitialization(View view, Object model, Component component);
88
89 /**
90 * Executes the ApplyModel phase. During this phase each component of the
91 * tree if invoked to setup any state based on the given model data
92 *
93 * <p>
94 * Part of the view lifecycle that applies the model data to the view.
95 * Should be called after the model has been populated before the view is
96 * rendered. The main things that occur during this phase are:
97 * <ul>
98 * <li>Generation of dynamic fields (such as collection rows)</li>
99 * <li>Execution of conditional logic (hidden, read-only, required settings
100 * based on model values)</li>
101 * </ul>
102 * </p>
103 *
104 * <p>
105 * The update phase can be called multiple times for the view's lifecycle
106 * (typically only once per request)
107 * </p>
108 *
109 * @param view View instance that the model should be applied to
110 * @param model Top level object containing the data (could be the form or a
111 * top level business object, dto)
112 */
113 public void performApplyModel(View view, Object model);
114
115 /**
116 * Gets global objects for the context map and pushes them to the context
117 * for the component
118 *
119 * @param view view instance for component
120 * @param component component instance to push context to
121 */
122 public Map<String, Object> getCommonContext(View view, Component component);
123
124 /**
125 * The last phase before the view is rendered. Here final preparations can
126 * be made based on the updated view state
127 *
128 * <p>
129 * The finalize phase runs after the apply model phase and can be called
130 * multiple times for the view's lifecylce (however typically only once per
131 * request)
132 * </p>
133 *
134 * @param view view instance that should be finalized for rendering
135 * @param model top level object containing the data
136 */
137 public void performFinalize(View view, Object model);
138
139 /**
140 * Invoked after the view has been rendered to clear out objects that are not necessary to keep around for
141 * the post, this helps reduce the view size and overall cost to store the form in session
142 *
143 * @param view view instance to be cleaned
144 */
145 public void cleanViewAfterRender(View view);
146
147 /**
148 * Performs the complete component lifecycle on the component passed in for use during a refresh process
149 *
150 * <p>
151 * Runs the three lifecycle phases on the component passed in. Some adjustments are made to account for the
152 * component being processed without its parent. The component within the view (contained on the form) is
153 * retrieved to obtain the context to use (such as parent). The created components id is then updated to match
154 * the current id within the view.
155 * </p>
156 *
157 * @param view view instance the component belongs to
158 * @param model object containing the full view data
159 * @param component component instance to perform lifecycle for
160 * @param origId id of the component within the view, used to pull the current component from the view
161 */
162 public void performComponentLifecycle(View view, Object model, Component component, String origId);
163
164 /**
165 * Runs the lifecycle process for the given component starting at the given start phase and ending with
166 * the given end phase
167 *
168 * <p>
169 * Start or end phase can be null to indicate the first phase or last phase respectively
170 * </p>
171 *
172 * @param view view instance the component belongs to
173 * @param model object providing the view data
174 * @param component component to run the lifecycle phases for
175 * @param parent parent component for the component being processed
176 * @param startPhase lifecycle phase to start with, or null to indicate the first phase
177 * @param endPhase lifecycle phase to end with, or null to indicate the last phase
178 */
179 public void spawnSubLifecyle(View view, Object model, Component component, Component parent, String startPhase,
180 String endPhase);
181
182 /**
183 * Update the reference objects listed in referencesToRefresh of the model
184 *
185 * <p>
186 * The the individual references in the referencesToRefresh string are separated by
187 * KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR).
188 * </p>
189 *
190 * @param model top level object containing the data
191 * @param referencesToRefresh list of references to refresh (
192 */
193 public void refreshReferences(Object model, String referencesToRefresh);
194
195 /**
196 * Invoked when the add line action is chosen for a collection. The
197 * collection path gives the full path to the collection that action was
198 * selected for. Here validation can be performed on the line as well as
199 * further processing on the line such as defaults. If the action is valid
200 * the line should be added to the collection, otherwise errors should be
201 * added to the global <code>MessageMap</code>
202 *
203 * @param view view instance that is being presented (the action was taken on)
204 * @param model Top level object containing the view data including the
205 * collection and new line
206 * @param collectionPath full path to the collection on the model
207 */
208 public void processCollectionAddLine(View view, Object model, String collectionPath);
209
210 /**
211 * Adds a blank line to the collection
212 *
213 * <p>
214 * Adds a new collection item to the collection and applies any default values.
215 * </p>
216 *
217 * @param view view instance that is being presented (the action was taken on)
218 * @param model Top level object containing the view data including the collection and new line
219 * @param collectionPath full path to the collection on the model
220 */
221 public void processCollectionAddBlankLine(View view, Object model, String collectionPath);
222
223 /**
224 * Invoked when the save line action is chosen for a collection. This method only does server side validation by
225 * default but creates hook for client applications to add additional logic like persisting data.
226 *
227 * @param view view instance that is being presented (the action was taken on)
228 * @param model Top level object containing the view data including the collection and new line
229 * @param collectionPath full path to the collection on the model
230 */
231 public void processCollectionSaveLine(View view, Object model, String collectionPath, int selectedLineIndex);
232
233 /**
234 * Invoked when the delete line action is chosen for a collection. The
235 * collection path gives the full path to the collection that action was
236 * selected for. Here validation can be performed to make sure the action is
237 * allowed. If the action is valid the line should be deleted from the
238 * collection, otherwise errors should be added to the global
239 * <code>MessageMap</code>
240 *
241 * @param view view instance that is being presented (the action was taken on)
242 * @param model Top level object containing the view data including the collection
243 * @param collectionPath full path to the collection on the model
244 * @param lineIndex index of the collection line that was selected for removal
245 */
246 public void processCollectionDeleteLine(View view, Object model, String collectionPath, int lineIndex);
247
248 /**
249 * Process the results returned from a multi-value lookup populating the lines for the collection given
250 * by the path
251 *
252 * @param view view instance the collection belongs to
253 * @param model object containing the view data
254 * @param collectionPath binding path to the collection to populated
255 * @param lookupResultValues String containing the selected line values
256 */
257 public void processMultipleValueLookupResults(View view, Object model, String collectionPath, String lookupResultValues);
258
259 /**
260 * Invoked by the <code>Inquiry</code> widget to build the inquiry link
261 *
262 * <p>
263 * Note this is used primarily for custom <code>Inquirable</code>
264 * implementations to customize the inquiry class or parameters for an
265 * inquiry. Instead of building the full inquiry link, implementations can
266 * make a callback to
267 * org.kuali.rice.krad.uif.widget.Inquiry.buildInquiryLink(Object, String,
268 * Class<?>, Map<String, String>) given an inquiry class and parameters to
269 * build the link field.
270 * </p>
271 *
272 * @param dataObject parent object for the inquiry property
273 * @param propertyName name of the property the inquiry is being built for
274 * @param inquiry instance of the inquiry widget being built for the property
275 */
276 public void buildInquiryLink(Object dataObject, String propertyName, Inquiry inquiry);
277
278 /**
279 * Applies configured default values for the line fields to the line
280 * instance
281 *
282 * @param view view instance the collection line belongs to
283 * @param model object containing the full view data
284 * @param collectionGroup collection group component the line belongs to
285 * @param line line instance to apply default values to
286 */
287 public void applyDefaultValuesForCollectionLine(View view, Object model, CollectionGroup collectionGroup, Object line);
288
289 /**
290 * Return an instance of {@link org.kuali.rice.krad.uif.view.ExpressionEvaluator} that can be used for evaluating
291 * expressions
292 * contained on the view
293 *
294 * <p>
295 * A ExpressionEvaluator must be initialized with a model for expression evaluation. One instance is
296 * constructed for the view lifecycle and made available to all components/helpers through this method
297 * </p>
298 *
299 * @return instance of ExpressionEvaluator
300 */
301 public ExpressionEvaluator getExpressionEvaluator();
302
303 /**
304 * Generates table formatted data based on data collected from the table model
305 *
306 * @param view view instance where the table is located
307 * @param model top level object containing the data
308 * @param tableId id of the table being generated
309 * @param formatType format which the table should be generated in
310 * @return
311 */
312 public String buildExportTableData(View view, Object model, String tableId, String formatType);
313
314 }