@@ -332,6 +332,7 @@ protected void addFields() {
332332 addField (ContactDto .FOLLOW_UP_STATUS , ComboBox .class );
333333 addField (ContactDto .FOLLOW_UP_COMMENT , TextArea .class ).setRows (1 );
334334 DateField dfFollowUpUntil = addDateField (ContactDto .FOLLOW_UP_UNTIL , DateField .class , -1 );
335+ dfFollowUpUntil .addValueChangeListener (v -> onFollowUpUntilChanged (v , quarantineTo , quarantineExtended , quarantineReduced ));
335336 quarantineTo .addValueChangeListener (e -> onQuarantineEndChange (e , quarantineExtended , quarantineReduced , dfFollowUpUntil ));
336337 this .addValueChangeListener (e -> onValueChange ());
337338
@@ -489,7 +490,6 @@ protected void addFields() {
489490 minimumFollowUpUntilDate ,
490491 null ,
491492 Resolution .DAY ));
492- dfFollowUpUntil .addValueChangeListener (v -> onFollowUpUntilChanged (v , quarantineTo , quarantineExtended ));
493493 }
494494
495495 // Overwrite visibility for quarantine fields
@@ -654,28 +654,41 @@ protected String createHtmlLayout() {
654654 return HTML_LAYOUT ;
655655 }
656656
657- private void onFollowUpUntilChanged (Property .ValueChangeEvent valueChangeEvent , DateField quarantineTo , CheckBox quarantineExtendedCheckBox ) {
657+ private void onFollowUpUntilChanged (Property .ValueChangeEvent valueChangeEvent , DateField quarantineTo , CheckBox quarantineExtendedCheckBox , CheckBox quarantineReducedCheckBox ) {
658658 Property <Date > followUpUntilField = valueChangeEvent .getProperty ();
659- Date followUpUntil = followUpUntilField .getValue ();
660- if (quarantineTo .getValue () != null && (followUpUntil == null || followUpUntil .compareTo (quarantineTo .getValue ()) != 0 )) {
659+ Date newFollowUpUntil = followUpUntilField .getValue ();
660+ ContactDto originalContact = getInternalValue ();
661+ Date oldFollowUpUntil = originalContact .getFollowUpUntil ();
662+ Date oldQuarantineEnd = originalContact .getQuarantineTo ();
663+ if (adjustQuarantine (quarantineTo , newFollowUpUntil , oldFollowUpUntil )) {
661664 VaadinUiUtil .showConfirmationPopup (
662- I18nProperties .getString (Strings .headingExtendQuarantine ),
663- new Label (I18nProperties .getString (Strings .confirmationAlsoExtendQuarantine )),
664- I18nProperties .getString (Strings .yes ),
665- I18nProperties .getString (Strings .no ),
666- 640 ,
667- confirmed -> {
668- if (confirmed ) {
669- quarantineChangedByFollowUpUntilChange = true ;
670- quarantineTo .setValue (followUpUntil );
671- if (followUpUntil .after (getInternalValue ().getFollowUpUntil ())) {
672- quarantineExtendedCheckBox .setValue (true );
673- }
665+ I18nProperties .getString (Strings .headingExtendQuarantine ),
666+ new Label (I18nProperties .getString (Strings .confirmationAlsoExtendQuarantine )),
667+ I18nProperties .getString (Strings .yes ),
668+ I18nProperties .getString (Strings .no ),
669+ 640 ,
670+ confirmed -> {
671+ if (confirmed ) {
672+ quarantineChangedByFollowUpUntilChange = true ;
673+ quarantineTo .setValue (newFollowUpUntil );
674+ if (oldQuarantineEnd != null ) {
675+ boolean quarantineExtended = newFollowUpUntil .after (oldQuarantineEnd );
676+ quarantineExtendedCheckBox .setValue (quarantineExtended );
677+ quarantineReducedCheckBox .setValue (!quarantineExtended );
678+ setVisible (quarantineExtended , ContactDto .QUARANTINE_EXTENDED );
679+ setVisible (!quarantineExtended , ContactDto .QUARANTINE_REDUCED );
674680 }
675- });
681+ }
682+ });
676683 }
677684 }
678685
686+ private boolean adjustQuarantine (DateField quarantineTo , Date newFollowUpUntil , Date oldFollowUpUntil ) {
687+ return newFollowUpUntil != null &&
688+ (oldFollowUpUntil == null || newFollowUpUntil .after (oldFollowUpUntil )) &&
689+ quarantineTo .getValue () != null && newFollowUpUntil .compareTo (quarantineTo .getValue ()) != 0 ;
690+ }
691+
679692 private void onQuarantineEndChange (Property .ValueChangeEvent valueChangeEvent , CheckBox quarantineExtendedCheckBox , CheckBox quarantineReducedCheckBox , DateField followUpUntilField ) {
680693 if (quarantineChangedByFollowUpUntilChange ) {
681694 quarantineChangedByFollowUpUntilChange = false ;
0 commit comments