001/**
002 * Copyright 2005-2018 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.krad.uif.field;
017
018import java.beans.PropertyEditor;
019import java.util.List;
020
021import org.kuali.rice.krad.datadictionary.AttributeDefinition;
022import org.kuali.rice.krad.datadictionary.mask.MaskFormatter;
023import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
024import org.kuali.rice.krad.uif.component.ComponentSecurity;
025import org.kuali.rice.krad.uif.component.DataBinding;
026import org.kuali.rice.krad.uif.widget.Helpable;
027import org.kuali.rice.krad.uif.widget.Inquiry;
028import org.kuali.rice.krad.valuefinder.ValueFinder;
029
030/**
031 * Component interface for data fields. 
032 * 
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035public interface DataField extends DataBinding, Helpable, Field {
036
037    /**
038     * Defaults the properties of the <code>DataField</code> to the
039     * corresponding properties of its <code>AttributeDefinition</code>
040     * retrieved from the dictionary (if such an entry exists). If the field
041     * already contains a value for a property, the definitions value is not
042     * used.
043     *
044     * @param attributeDefinition AttributeDefinition instance the property values should be
045     * copied from
046     */
047    void copyFromAttributeDefinition(AttributeDefinition attributeDefinition);
048
049    /**
050     * Indicates whether the data field instance allows input, subclasses should override and set to
051     * true if input is allowed
052     *
053     * @return true if input is allowed, false if read only
054     */
055    boolean isInputAllowed();
056
057    /**
058     * Setter for the component's property name
059     *
060     * @param propertyName
061     */
062    void setPropertyName(String propertyName);
063
064    /**
065     * Performs formatting of the field value for display and then converting the value back to its
066     * expected type from a string
067     *
068     * <p>
069     * Note property editors exist and are already registered for the basic Java types and the
070     * common Kuali types such as [@link KualiDecimal}. Registration with this property is only
071     * needed for custom property editors
072     * </p>
073     *
074     * @return PropertyEditor property editor instance to use for this field
075     */
076    PropertyEditor getPropertyEditor();
077
078    /**
079     * Setter for the custom property editor to use for the field
080     *
081     * @param propertyEditor
082     */
083    void setPropertyEditor(PropertyEditor propertyEditor);
084
085    /**
086     * Convenience setter for configuring a property editor by class
087     *
088     * @param propertyEditorClass
089     */
090    void setPropertyEditorClass(Class<? extends PropertyEditor> propertyEditorClass);
091
092    /**
093     * Returns the full binding path (the path used in the name attribute of the input).
094     * This differs from propertyName in that it uses BindingInfo to determine the path.
095     *
096     * @return full binding path name
097     */
098    String getName();
099
100    /**
101     * Name of the attribute within the data dictionary the attribute field is
102     * associated with
103     *
104     * <p>
105     * During the initialize phase for the <code>View</code>, properties for
106     * attribute fields are defaulted from a corresponding
107     * <code>AttributeDefinition</code> in the data dictionary. Based on the
108     * propertyName and parent object class the framework attempts will
109     * determine the attribute definition that is associated with the field and
110     * set this property. However this property can also be set in the fields
111     * configuration to use another dictionary attribute.
112     * </p>
113     *
114     * <p>
115     * The attribute name is used along with the dictionary object entry to find
116     * the <code>AttributeDefinition</code>
117     * </p>
118     *
119     * @return attribute name
120     */
121    String getDictionaryAttributeName();
122
123    /**
124     * Setter for the dictionary attribute name
125     *
126     * @param dictionaryAttributeName
127     */
128    void setDictionaryAttributeName(String dictionaryAttributeName);
129
130    /**
131     * Object entry name in the data dictionary the associated attribute is
132     * apart of
133     *
134     * <p>
135     * During the initialize phase for the <code>View</code>, properties for
136     * attribute fields are defaulted from a corresponding
137     * <code>AttributeDefinition</code> in the data dictionary. Based on the
138     * parent object class the framework will determine the object entry for the
139     * associated attribute. However the object entry can be set in the field's
140     * configuration to use another object entry for the attribute
141     * </p>
142     *
143     * <p>
144     * The attribute name is used along with the dictionary object entry to find
145     * the <code>AttributeDefinition</code>
146     * </p>
147     *
148     * @return String
149     */
150    String getDictionaryObjectEntry();
151
152    /**
153     * Setter for the dictionary object entry
154     *
155     * @param dictionaryObjectEntry
156     */
157    void setDictionaryObjectEntry(String dictionaryObjectEntry);
158
159    /**
160     * Default value for the model property the field points to
161     *
162     * <p>
163     * When a new <code>View</code> instance is requested, the corresponding
164     * model will be newly created. During this initialization process the value
165     * for the model property will be set to the given default value, if it was null.
166     * This will only work on properties which can be determined to be null.
167     * Therefore a String property with an empty string value will
168     * not be ovewritten with the defaultValue set here.
169     * </p>
170     *
171     * <p>
172     * In addition, int, boolean, and other primitive types
173     * will not use this default value because they inherently have a value in Java (0 for int, false for boolean, etc).
174     * To use such types either using a primitive wrapper type (Integer, Boolean, etc) so an unset variable can
175     * be determined to be null, or explicitly set the default value on the form/object itself for these types and
176     * not through this property.
177     * </p>
178     *
179     * @return default value
180     */
181    Object getDefaultValue();
182
183    /**
184     * Setter for the fields default value
185     *
186     * @param defaultValue
187     */
188    void setDefaultValue(Object defaultValue);
189
190    /**
191     * Gives Class that should be invoked to produce the default value for the
192     * field
193     *
194     * @return default value finder class
195     */
196    Class<? extends ValueFinder> getDefaultValueFinderClass();
197
198    /**
199     * Setter for the default value finder class
200     *
201     * @param defaultValueFinderClass
202     */
203    void setDefaultValueFinderClass(Class<? extends ValueFinder> defaultValueFinderClass);
204
205    /**
206     * Array of default values for the model property the field points to
207     *
208     * <p>
209     * When a new <code>View</code> instance is requested, the corresponding
210     * model will be newly created. During this initialization process the value
211     * for the model property will be set to the given default values (if set)
212     * </p>
213     *
214     * @return default value
215     */
216    List<Object> getDefaultValues();
217
218    /**
219     * Setter for the fields default values
220     *
221     * @param defaultValues
222     */
223    void setDefaultValues(List<Object> defaultValues);
224
225    /**
226     * For read only DataFields, if forcedValue has a value, the value of it will be used instead of the value
227     * received from the propertyName specified for this field;
228     * this can be combined with SpringEL to format a property value in some way, for example.
229     *
230     * @return the forced value
231     */
232    String getForcedValue();
233
234    /**
235     * @see org.kuali.rice.krad.uif.field.DataField#setForcedValue(String)
236     */
237    void setForcedValue(String forcedValue);
238
239    /**
240     * Summary help text for the field
241     *
242     * @return summary help text
243     */
244    String getHelpSummary();
245
246    /**
247     * Setter for the summary help text
248     *
249     * @param helpSummary
250     */
251    void setHelpSummary(String helpSummary);
252
253    /**
254     * Data Field Security object that indicates what authorization (permissions) exist for the field
255     *
256     * @return DataFieldSecurity instance
257     */
258    DataFieldSecurity getDataFieldSecurity();
259
260    /**
261     * Override to assert a {@link DataFieldSecurity} instance is set
262     *
263     * @param componentSecurity instance of DataFieldSecurity
264     */
265    void setComponentSecurity(ComponentSecurity componentSecurity);
266
267    /**
268     * Indicates the field should be read-only but also a hidden should be generated for the field
269     *
270     * <p>
271     * Useful for when a value is just displayed but is needed by script
272     * </p>
273     *
274     * @return true if field should be readOnly hidden, false if not
275     */
276    boolean isAddHiddenWhenReadOnly();
277
278    /**
279     * Setter for the read-only hidden indicator
280     *
281     * @param addHiddenWhenReadOnly
282     */
283    void setAddHiddenWhenReadOnly(boolean addHiddenWhenReadOnly);
284
285    /**
286     * Inquiry widget for the field
287     *
288     * <p>
289     * The inquiry widget will render a link for the field value when read-only
290     * that points to the associated inquiry view for the field. The inquiry can
291     * be configured to point to a certain <code>InquiryView</code>, or the
292     * framework will attempt to associate the field with a inquiry based on its
293     * metadata (in particular its relationships in the model)
294     * </p>
295     *
296     * @return Inquiry field inquiry
297     */
298    Inquiry getInquiry();
299
300    /**
301     * Setter for the inquiry widget
302     *
303     * @param inquiry
304     */
305    void setInquiry(Inquiry inquiry);
306
307    /**
308     * Indicates whether inquiries should be automatically set when a relationship for the field's property
309     * is found
310     *
311     * <p>
312     * Note this only applies when the {@link #getInquiry()} widget has not been configured (is null)
313     * and is set to true by default
314     * </p>
315     *
316     * @return true if auto inquiries are enabled, false if not
317     */
318    boolean isEnableAutoInquiry();
319
320    /**
321     * Setter for enabling automatic inquiries
322     *
323     * @param enableAutoInquiry
324     */
325    void setEnableAutoInquiry(boolean enableAutoInquiry);
326
327    /**
328     * When true, render the info message span which contains can contain additional information
329     * about the field (used by Field Query functionality)
330     *
331     * @return true if the span will be rendered, false otherwise
332     */
333    boolean isRenderInfoMessageSpan();
334
335    /**
336     * @see org.kuali.rice.krad.uif.field.DataField#isRenderInfoMessageSpan()
337     * @param renderInfoMessageSpan
338     */
339    void setRenderInfoMessageSpan(boolean renderInfoMessageSpan);
340
341    /**
342     * When true, render the marker icon span to show icons related to the field (used by CompareFieldCreateModifier on
343     * maintenance documetnts to mark editted fields)
344     *
345     * @return true if the the marker icon span will be rendered, false otherwise
346     */
347    boolean isRenderMarkerIconSpan();
348
349    /**
350     * @see org.kuali.rice.krad.uif.field.DataField#isRenderMarkerIconSpan()
351     * @param renderMarkerIconSpan
352     */
353    void setRenderMarkerIconSpan(boolean renderMarkerIconSpan);
354
355    /**
356     * Additional display attribute name, which will be displayed next to the actual field value
357     * when the field is readonly with hyphen in between like PropertyValue - AdditionalPropertyValue
358     *
359     * @param readOnlyDisplaySuffixPropertyName name of the additional display property
360     */
361    void setReadOnlyDisplaySuffixPropertyName(String readOnlyDisplaySuffixPropertyName);
362
363    /**
364     * Returns the additional display attribute name to be displayed when the field is readonly
365     *
366     * @return additional display attribute name
367     */
368    String getReadOnlyDisplaySuffixPropertyName();
369
370    /**
371     * Sets the alternate display attribute name to be displayed when the field is readonly.
372     * This properties value will be displayed instead of actual fields value when the field is readonly.
373     *
374     * @param readOnlyDisplayReplacementPropertyName alternate display property name
375     */
376    void setReadOnlyDisplayReplacementPropertyName(String readOnlyDisplayReplacementPropertyName);
377
378    /**
379     * Returns the alternate display attribute name to be displayed when the field is readonly.
380     *
381     * @return alternate Display Property Name
382     */
383    String getReadOnlyDisplayReplacementPropertyName();
384
385    /**
386     * Returns the alternate display value
387     *
388     * @return the alternate display value set for this field
389     */
390    String getReadOnlyDisplayReplacement();
391
392    /**
393     * Setter for the alternative display value
394     *
395     * @param value
396     */
397    void setReadOnlyDisplayReplacement(String value);
398
399    /**
400     * Returns the additional display value.
401     *
402     * @return the additional display value set for this field
403     */
404    String getReadOnlyDisplaySuffix();
405
406    /**
407     * Setter for the additional display value
408     *
409     * @param value
410     */
411    void setReadOnlyDisplaySuffix(String value);
412
413    /**
414     * Gets the readOnlyListDisplayType.
415     *
416     * <p>When this is not set, the list will default to the delimited list display with a default of comma and space
417     * (", ") - if readOnlyListDelimiter is not set as well.  The type can be set as the following:
418     * <ul>
419     * <li>"DELIMITED" - list will be output with delimiters between each item defined by readOnlyListDelimiter</li>
420     * <li>"BREAK" - list will be output with breaks between each item</li>
421     * <li>"OL" - list will be output in ordered list format (numbered)</li>
422     * <li>"UL" - list will be output in unordered list format (bulleted)</li>
423     * </ul>
424     * </p>
425     *
426     * @return the display type to use
427     */
428    String getReadOnlyListDisplayType();
429
430    /**
431     * Set the readOnlyListDisplayType
432     *
433     * @param readOnlyListDisplayType
434     */
435    void setReadOnlyListDisplayType(String readOnlyListDisplayType);
436
437    /**
438     * The readOnlyListDelimiter is used to set the delimiter used when "DELIMITED" type is set for
439     * readOnlyListDisplayType
440     *
441     * @return the delimiter to use in readOnly list output with "DELIMITED" type set
442     */
443    String getReadOnlyListDelimiter();
444
445    /**
446     * Set the readOnlyListDelimiter
447     *
448     * @param readOnlyListDelimiter
449     */
450    void setReadOnlyListDelimiter(String readOnlyListDelimiter);
451
452    /**
453     * Indicates whether the value for the field should be masked (or partially masked) on display
454     *
455     * <p>
456     * If set to true, the field value will be masked by applying the configured {@link #getMaskFormatter()}
457     * </p>
458     *
459     * <p>
460     * If a KIM permission exists that should be checked to determine whether the value should be masked or not,
461     * this value should not be set but instead the mask or partialMask property on {@link #getComponentSecurity()}
462     * should be set to true. This indicates there is a mask permission that should be consulted. If the user
463     * does not have the permission, this flag will be set to true by the framework and the value masked using
464     * the mask formatter configured on the security object
465     * </p>
466     *
467     * @return true if the field value should be masked, false if not
468     */
469    boolean isApplyMask();
470
471    /**
472     * Setter for the apply value mask flag
473     *
474     * @param applyMask
475     */
476    void setApplyMask(boolean applyMask);
477
478    /**
479     * MaskFormatter instance that will be used to mask the field value when {@link #isApplyMask()} is true
480     *
481     * <p>
482     * Note in cases where the mask is applied due to security (KIM permissions), the mask or partial mask formatter
483     * configured on {@link #getComponentSecurity()} will be used instead of this mask formatter
484     * </p>
485     *
486     * @return MaskFormatter instance
487     */
488    MaskFormatter getMaskFormatter();
489
490    /**
491     * Setter for the MaskFormatter instance to apply when the value is masked
492     *
493     * @param maskFormatter
494     */
495    void setMaskFormatter(MaskFormatter maskFormatter);
496
497    /**
498     * Allows specifying hidden property names without having to specify as a
499     * field in the group config (that might impact layout)
500     *
501     * @return hidden property names
502     */
503    List<String> getAdditionalHiddenPropertyNames();
504
505    /**
506     * Setter for the hidden property names
507     *
508     * @param additionalHiddenPropertyNames
509     */
510    void setAdditionalHiddenPropertyNames(List<String> additionalHiddenPropertyNames);
511
512    /**
513     * List of property names whose values should be displayed read-only under this field
514     *
515     * <p>
516     * In the attribute field template for each information property name given its values is
517     * outputted read-only. Informational property values can also be updated dynamically with
518     * the use of field attribute query
519     * </p>
520     *
521     * <p>
522     * Simple property names can be given if the property has the same binding parent as this
523     * field, in which case the binding path will be adjusted by the framework. If the property
524     * names starts with org.kuali.rice.krad.uif.UifConstants#NO_BIND_ADJUST_PREFIX, no binding
525     * prefix will be added.
526     * </p>
527     *
528     * @return informational property names
529     */
530    List<String> getPropertyNamesForAdditionalDisplay();
531
532    /**
533     * Setter for the list of informational property names
534     *
535     * @param propertyNamesForAdditionalDisplay
536     */
537    void setPropertyNamesForAdditionalDisplay(List<String> propertyNamesForAdditionalDisplay);
538
539    /**
540     * Sets HTML escaping for this property value. HTML escaping will be handled in alternate and additional fields
541     * also.
542     */
543    void setEscapeHtmlInPropertyValue(boolean escapeHtmlInPropertyValue);
544
545    /**
546     * Returns true if HTML escape allowed for this field
547     *
548     * @return true if escaping allowed
549     */
550    boolean isEscapeHtmlInPropertyValue();
551
552    /**
553     * Returns true if this field is of type {@code TextAreaControl}.
554     *
555     * <p>
556     * Used to preserve text formatting in a textarea when the view
557     * is readOnly by enclosing the text in a </pre> tag.
558     * </p>
559     *
560     * @return true if the field is of type {@code TextAreaControl}
561     */
562    boolean isMultiLineReadOnlyDisplay();
563
564    /**
565     * Setter for multiLineReadOnlyDisplay
566     *
567     * @param multiLineReadOnlyDisplay
568     */
569    void setMultiLineReadOnlyDisplay(boolean multiLineReadOnlyDisplay);
570
571    /**
572     * Indicates whether the value for the field is secure.
573     *
574     * <p>
575     * A value will be secured if masking has been applied (by configuration or a failed KIM permission) or the field
576     * has been marked as hidden due to a required KIM permission check failing.
577     * </p>
578     *
579     * @return true if value is secure, false if not
580     */
581    boolean hasSecureValue();
582
583    boolean isRenderFieldset();
584
585    /**
586     * Sets the sort type if this field is used within a collection
587     *
588     * <p>
589     * The default sort type is the Java class of the
590     * property being referenced. Since a String property may actually contain numeric or date values only this property
591     * can be used to better set the sort type.
592     * </p>
593     *
594     * @return string representation of the sort type
595     */
596    public String getSortAs();
597
598    public void setSortAs(String sortAs);
599
600    /**
601     * @see org.kuali.rice.krad.uif.component.Component#completeValidation
602     */
603    void completeValidation(ValidationTrace tracer);
604
605}