File tree Expand file tree Collapse file tree
sormas-ui/src/main/java/de/symeda/sormas/ui/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -617,9 +617,68 @@ public void setHeading(String heading) {
617617
618618 /**
619619 * List of editable allowed fields,
620+ *
620621 * @return
621622 */
622- public List <Field <?>> editableAllowedFields (){
623+ public List <Field <?>> editableAllowedFields () {
623624 return Collections .unmodifiableList (editableAllowedFields );
624625 }
626+
627+ /**
628+ * Clears the field if it is not read-only.
629+ *
630+ * @param field
631+ */
632+ protected void safeClearField (Field <?> field ) {
633+ if (field .isReadOnly ()) {
634+ return ;
635+ }
636+ field .clear ();
637+ }
638+
639+ /**
640+ * Clears the field if it is not read-only.
641+ *
642+ * @param propertyId
643+ */
644+ protected void safeClearField (String propertyId ) {
645+ final Field <?> field = getField (propertyId );
646+ if (field == null ) {
647+ return ;
648+ }
649+ safeClearField (field );
650+ }
651+
652+ /**
653+ * Sets the field value if it is not read-only.
654+ *
655+ * @param <T>
656+ * @param field
657+ * @param value
658+ * @return
659+ */
660+ protected <T > T safeSetFieldValue (Field <T > field , T value ) {
661+ if (field .isReadOnly ()) {
662+ return field .getValue ();
663+ }
664+ final T oldValue = field .getValue ();
665+ field .setValue (value );
666+ return oldValue ;
667+ }
668+
669+ /**
670+ * Sets the field value if it is not read-only.
671+ *
672+ * @param <T>
673+ * @param propertyId
674+ * @param value
675+ * @return
676+ */
677+ protected <T > T safeSetFieldValue (String propertyId , T value ) {
678+ final Field <T > field = getField (propertyId );
679+ if (field == null ) {
680+ return null ;
681+ }
682+ return safeSetFieldValue (field , value );
683+ }
625684}
You can’t perform that action at this time.
0 commit comments