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.service;
17
18 import java.util.Map;
19
20 import org.kuali.rice.krad.uif.component.Component;
21 import org.kuali.rice.krad.uif.container.CollectionGroup;
22 import org.kuali.rice.krad.uif.container.Container;
23 import org.kuali.rice.krad.uif.field.DataField;
24 import org.kuali.rice.krad.uif.util.ComponentFactory;
25 import org.kuali.rice.krad.uif.util.LifecycleElement;
26 import org.kuali.rice.krad.uif.view.ExpressionEvaluatorFactory;
27 import org.kuali.rice.krad.uif.view.ViewModel;
28 import org.kuali.rice.krad.uif.widget.Inquiry;
29 import org.kuali.rice.krad.web.service.impl.CollectionControllerServiceImpl.CollectionActionParameters;
30
31 /**
32 * Provides customization methods at various points of the view lifecycle.
33 *
34 * <p>Custom view helpers can be configured with view property
35 * {@link org.kuali.rice.krad.uif.view.View#getViewHelperServiceClass()}</p>
36 *
37 * @author Kuali Rice Team (rice.collab@kuali.org)
38 */
39 public interface ViewHelperService {
40
41 /**
42 * Uses reflection to find all fields defined on the <code>View</code> instance that have the
43 * <code>RequestParameter</code> annotation (which indicates the field may be populated by the
44 * request).
45 *
46 * <p>
47 * The <code>View</code> instance is inspected for fields that have the
48 * <code>RequestParameter</code> annotation and if corresponding parameters are found in the
49 * request parameter map, the request value is used to set the view property. The Map of
50 * parameter name/values that match are placed in the view so they can be later retrieved to
51 * rebuild the view. Custom <code>ViewServiceHelper</code> implementations can add additional
52 * parameter key/value pairs to the returned map if necessary.
53 * </p>
54 *
55 * <p>
56 * For each field found, if there is a corresponding key/value pair in the request parameters,
57 * the value is used to populate the field. In addition, any conditional properties of
58 * <code>PropertyReplacers</code> configured for the field are cleared so that the request
59 * parameter value does not get overridden by the dictionary conditional logic
60 * </p>
61 *
62 * @param parameters The request parameters that apply to the view.
63 * @see org.kuali.rice.krad.uif.component.RequestParameter
64 */
65 void populateViewFromRequestParameters(Map<String, String> parameters);
66
67 /**
68 * Hook for service overrides to perform custom initialization prior to view initialization.
69 *
70 * @param model The model.
71 */
72 void performCustomViewInitialization(Object model);
73
74 /**
75 * Hook for service overrides to perform custom initialization on the component
76 *
77 * @param component component instance to initialize
78 */
79 void performCustomInitialization(LifecycleElement component);
80
81 /**
82 * Hook for service overrides to perform custom apply model logic on the component
83 *
84 * @param component component instance to apply model to
85 * @param model Top level object containing the data (could be the model or a top level business
86 * object, dto)
87 */
88 void performCustomApplyModel(LifecycleElement component, Object model);
89
90 /**
91 * Hook for service overrides to perform custom component finalization
92 *
93 * @param component component instance to update
94 * @param model Top level object containing the data
95 * @param parent Parent component for the component being finalized
96 */
97 void performCustomFinalize(LifecycleElement component, Object model, LifecycleElement parent);
98
99 /**
100 * Hook for service overrides to perform view component finalization
101 *
102 * @param model Top level object containing the data
103 */
104 void performCustomViewFinalize(Object model);
105
106 /**
107 * Hook for service overrides to process the new collection line before it is added to the
108 * collection
109 *
110 * @param model object instance that contain's the view's data
111 * @param addLine the new line instance to be processed
112 * @param collectionId the id of the collection being added to
113 * @param collectionPath the path to the collection being modified
114 */
115 void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath);
116
117 /**
118 * Hook for service overrides to process the new collection line after it has been added to the
119 * collection
120 *
121 * @param model object instance that contain's the views data
122 * @param addLine the new line that was added
123 * @param collectionId the id of the collection being added to
124 * @param collectionPath the path to the collection being modified
125 * @param isValidLine indicates if the line is valid
126 */
127 void processAfterAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath,
128 boolean isValidLine);
129
130 /**
131 * Hook for service overrides to process the edit collection line before it is validated
132 *
133 * @param model object instance that contain's the views data
134 * @param lineObject the line instance to be processed
135 * @param collectionId the id of the collection being edited from
136 * @param collectionPath the path to the collection being modified
137 */
138 void processBeforeEditLine(ViewModel model, Object lineObject, String collectionId, String collectionPath);
139
140 /**
141 * Hook for service overrides to process the edit collection line after it has been validated
142 *
143 * @param model object instance that contains the views data
144 * @param lineObject the line instance to be processed
145 * @param collectionId the id of the collection being edited from
146 * @param collectionPath the path to the collection being modified
147 */
148 void processAfterEditLine(ViewModel model, Object lineObject, String collectionId, String collectionPath);
149
150 /**
151 * Hook for service overrides to process the save collection line before it is validated
152 *
153 * @param model object instance that contain's the views data
154 * @param lineObject the line instance to be processed
155 * @param collectionId the id of the collection being added to
156 * @param collectionPath the path to the collection being modified
157 */
158 void processBeforeSaveLine(ViewModel model, Object lineObject, String collectionId, String collectionPath);
159
160 /**
161 * Hook for service overrides to process the save collection line after it has been validated
162 *
163 * @param model object instance that contains the views data
164 * @param lineObject the line instance to be processed
165 * @param collectionId the id of the collection being added to
166 * @param collectionPath the path to the collection being modified
167 */
168 void processAfterSaveLine(ViewModel model, Object lineObject, String collectionId, String collectionPath);
169
170 /**
171 * Hook for service overrides to process the collection line after it has been deleted
172 *
173 * @param model object instance that contains the views data
174 * @param collectionId the id of the collection being added to
175 * @param collectionPath the path to the collection being modified
176 * @param lineIndex index of the line that was deleted
177 */
178 void processAfterDeleteLine(ViewModel model, String collectionId, String collectionPath, int lineIndex);
179
180 /**
181 * Hook for creating new components with code and adding them to a container
182 *
183 * <p>
184 * Subclasses can override this method to check for one or more containers by id and then adding
185 * components created in code. This is invoked before the initialize method on the container
186 * component, so the full lifecycle will be run on the components returned.
187 * </p>
188 *
189 * <p>
190 * New components instances can be retrieved using {@link ComponentFactory}
191 * </p>
192 *
193 * @param model object containing the view data
194 * @param container container instance to add components to
195 */
196 void addCustomContainerComponents(ViewModel model, Container container);
197
198 /**
199 * Invoked when the add line action is chosen for a collection. The
200 * collection path gives the full path to the collection that action was
201 * selected for. Here validation can be performed on the line as well as
202 * further processing on the line such as defaults. If the action is valid
203 * the line should be added to the collection, otherwise errors should be
204 * added to the global <code>MessageMap</code>
205 *
206 * @param model Top level object containing the view data including the
207 * collection and new line
208 * @param collectionId the id of the collection being added to
209 * @param collectionPath the path to the collection being modified
210 */
211 void processCollectionAddLine(ViewModel model, String collectionId, String collectionPath);
212
213 void processAndAddLineObject(ViewModel viewModel, Object newLine, String collectionId,
214 String collectionPath);
215
216 /**
217 * Adds a blank line to the collection
218 *
219 * <p>
220 * Adds a new collection item to the collection and applies any default values.
221 * </p>
222 *
223 * @param model Top level object containing the view data including the collection and new line
224 * @param collectionId the id of the collection being added to
225 * @param collectionPath the path to the collection being modified
226 */
227 void processCollectionAddBlankLine(ViewModel model, String collectionId, String collectionPath);
228
229 /**
230 * Invoked when the edit line action is chosen for a collection. This method only does server side validation by
231 * default but creates hook for client applications to add additional logic like persisting data.
232 *
233 * @param model Top level object containing the view data including the collection and new line
234 * @param collectionId the id of the collection being added to
235 * @param collectionPath the path to the collection being modified
236 * @param selectedLineIndex The index within the collection of the line to edit.
237 */
238 void processCollectionEditLine(ViewModel model, String collectionId, String collectionPath, int selectedLineIndex);
239
240 /**
241 * Invoked when the save line action is chosen for a collection. This method only does server side validation by
242 * default but creates hook for client applications to add additional logic like persisting data.
243 *
244 * @param model Top level object containing the view data including the collection and new line
245 * @param parameters the parameters for save line request
246 */
247 void processCollectionSaveLine(ViewModel model, CollectionActionParameters parameters);
248
249 /**
250 * Invoked when the delete line action is chosen for a collection. The
251 * collection path gives the full path to the collection that action was
252 * selected for. Here validation can be performed to make sure the action is
253 * allowed. If the action is valid the line should be deleted from the
254 * collection, otherwise errors should be added to the global
255 * <code>MessageMap</code>
256 *
257 * @param model Top level object containing the view data including the collection
258 * @param collectionId the id of the collection being added to
259 * @param collectionPath the path to the collection being modified
260 * @param lineIndex index of the collection line that was selected for removal
261 */
262 void processCollectionDeleteLine(ViewModel model, String collectionId, String collectionPath, int lineIndex);
263
264 /**
265 * Process the results returned from a multi-value lookup populating the lines for the collection given
266 * by the path
267 *
268 * @param model object containing the view data
269 * @param collectionId the id of the collection being added to
270 * @param collectionPath the path to the collection being modified
271 * @param multiValueReturnFields String containing the selected line field names
272 * @param lookupResultValues String containing the selected line values
273 */
274 void processMultipleValueLookupResults(ViewModel model, String collectionId, String collectionPath,
275 String multiValueReturnFields, String lookupResultValues);
276
277 /**
278 * Invoked by the <code>Inquiry</code> widget to build the inquiry link
279 *
280 * <p>
281 * Note this is used primarily for custom <code>Inquirable</code>
282 * implementations to customize the inquiry class or parameters for an
283 * inquiry. Instead of building the full inquiry link, implementations can
284 * make a callback to
285 * org.kuali.rice.krad.uif.widget.Inquiry.buildInquiryLink(Object, String,
286 * Class<?>, Map<String, String>) given an inquiry class and parameters to
287 * build the link field.
288 * </p>
289 *
290 * @param dataObject parent object for the inquiry property
291 * @param propertyName name of the property the inquiry is being built for
292 * @param inquiry instance of the inquiry widget being built for the property
293 */
294 void buildInquiryLink(Object dataObject, String propertyName, Inquiry inquiry);
295
296 /**
297 * Sets up the view context which will be available to other components through their context
298 * for conditional logic evaluation.
299 */
300 void setViewContext();
301
302 /**
303 * Invoked to set up the context for an element.
304 *
305 * <p>Context is primarily used for expression evaluation. Any object in the context for a component
306 * will be available as a variable within expressions.</p>
307 *
308 * @param element element to setup context for
309 * @param parent parent of the given element
310 */
311 void setElementContext(LifecycleElement element, LifecycleElement parent);
312
313 /**
314 * Invokes the configured <code>PresentationController</code> and </code>Authorizer</code> for
315 * the view to get the exported action flags and edit modes that can be used in conditional
316 * logic
317 */
318 void retrieveEditModesAndActionFlags();
319
320 /**
321 * Perform a database or data dictionary based refresh of a specific property object
322 *
323 * <p>
324 * The object needs to be of type PersistableBusinessObject.
325 * </p>
326 *
327 * @param parentObject parent object that references the object to be refreshed
328 * @param referenceObjectName property name of the parent object to be refreshed
329 */
330 void refreshReference(Object parentObject, String referenceObjectName);
331
332 /**
333 * Update the reference objects listed in referencesToRefresh of the model
334 *
335 * <p>
336 * The the individual references in the referencesToRefresh string are separated by
337 * KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR).
338 * </p>
339 *
340 * @param referencesToRefresh list of references to refresh (
341 */
342 void refreshReferences(String referencesToRefresh);
343
344 /**
345 * Retrieves the default value that is configured for the given data field
346 *
347 * <p>
348 * The field's default value is determined in the following order:
349 *
350 * <ol>
351 * <li>If default value on field is non-blank</li>
352 * <li>If expression is found for default value</li>
353 * <li>If default value finder class is configured for field</li>
354 * <li>If an expression is found for default values</li>
355 * <li>If default values on field is not null</li>
356 * </ol>
357 * </p>
358 *
359 * @param object object that should be populated
360 * @param dataField field to retrieve default value for
361 * @return Object default value for field or null if value was not found
362 */
363 Object getDefaultValueForField(Object object, DataField dataField);
364
365 /**
366 * Applies the default value configured for the given field (if any) to the line given object
367 * property that is determined by the given binding path
368 *
369 * @param object object that should be populated
370 * @param dataField field to check for configured default value
371 * @param bindingPath path to the property on the object that should be populated
372 */
373 void populateDefaultValueForField(Object object, DataField dataField, String bindingPath);
374
375 /**
376 * Builds JS script that will invoke the show growl method to display a growl message when the
377 * page is rendered
378 *
379 * <p>
380 * A growl call will be created for any explicit growl messages added to the message map.
381 * </p>
382 *
383 * <p>
384 * Growls are only generated if @{link
385 * org.kuali.rice.krad.uif.view.View#isGrowlMessagingEnabled()} is enabled. If not, the growl
386 * messages are set as info messages for the page
387 * </p>
388 *
389 * @return JS script string for generated growl messages
390 */
391 String buildGrowlScript();
392
393 /**
394 * Iterates through the view components picking up data fields and applying an default value
395 * configured
396 *
397 * @param component component that should be checked for default values
398 */
399 void applyDefaultValues(Component component);
400
401 /**
402 * Populate default values the model backing a line in a collection group.
403 *
404 * @param collectionGroup The collection group.
405 * @param line The model object backing the line.
406 */
407 void applyDefaultValuesForCollectionLine(CollectionGroup collectionGroup, Object line);
408
409 /**
410 * Gets an expression evaluator factory for use with the current view.
411 *
412 * @return expression evaluator factory
413 */
414 ExpressionEvaluatorFactory getExpressionEvaluatorFactory();
415
416 }