1818import static de .symeda .sormas .ui .utils .LayoutUtil .fluidRowLocs ;
1919import static de .symeda .sormas .ui .utils .LayoutUtil .loc ;
2020
21- import java .util .Comparator ;
2221import java .util .Objects ;
23- import java .util .stream .Collectors ;
2422
2523import com .vaadin .ui .GridLayout ;
2624import com .vaadin .v7 .data .Validator ;
@@ -47,7 +45,6 @@ public class CampaignFormDataEditForm extends AbstractEditForm<CampaignFormDataD
4745 private AreaReferenceDto area ;
4846 public static final String AREA = "area" ;
4947
50-
5148 public AreaReferenceDto getArea () {
5249 return area ;
5350 }
@@ -95,43 +92,33 @@ protected void addFields() {
9592 addInfrastructureListeners (cbRegion , cbDistrict , cbCommunity );
9693 cbRegion .addItems (FacadeProvider .getRegionFacade ().getAllActiveAsReference ());
9794
98- if (FacadeProvider .getFeatureConfigurationFacade ().isFeatureEnabled (FeatureType .INFRASTRUCTURE_TYPE_AREA )){
99- ComboBox cbArea = addCustomField (CampaignFormDataEditForm .AREA ,AreaReferenceDto .class ,ComboBox .class );
95+ if (FacadeProvider .getFeatureConfigurationFacade ().isFeatureEnabled (FeatureType .INFRASTRUCTURE_TYPE_AREA )) {
96+ ComboBox cbArea = addCustomField (CampaignFormDataEditForm .AREA , AreaReferenceDto .class , ComboBox .class );
10097 cbArea .setCaption (I18nProperties .getCaption (Captions .CampaignFormData_area ));
101- setRequired (true ,CampaignFormDataEditForm .AREA );
98+ setRequired (true , CampaignFormDataEditForm .AREA );
10299 cbArea .addItems (FacadeProvider .getAreaFacade ().getAllActiveAsReference ());
103100 cbArea .addValueChangeListener (e -> {
104- AreaReferenceDto area =(AreaReferenceDto ) e .getProperty ().getValue ();
105-
106- if (Objects .nonNull (area ) && cbRegion .isEmpty ()) {
107- cbRegion .removeAllItems ();
108- cbRegion .addItems (
109- FacadeProvider .getRegionFacade ()
110- .getAllActiveByArea ((area .getUuid ()))
111- .stream ()
112- .sorted (Comparator .comparing (RegionReferenceDto ::getCaption ))
113- .collect (Collectors .toList ()));
114- } else if (Objects .isNull (area )){
115- cbRegion .addItems (FacadeProvider .getRegionFacade ().getAllActiveAsReference ());
116- } else {
101+ AreaReferenceDto area = (AreaReferenceDto ) e .getProperty ().getValue ();
102+
103+ if (area == null ) {
117104 cbRegion .setValue (null );
118- cbRegion .removeAllItems ();
119- cbRegion .addItems (
120- FacadeProvider .getRegionFacade ()
121- .getAllActiveByArea ((area .getUuid ()))
122- .stream ()
123- .sorted (Comparator .comparing (RegionReferenceDto ::getCaption ))
124- .collect (Collectors .toList ()));
125105 }
106+
107+ FieldHelper .updateItems (
108+ cbRegion ,
109+ area != null
110+ ? FacadeProvider .getRegionFacade ().getAllActiveByArea (area .getUuid ())
111+ : FacadeProvider .getRegionFacade ().getAllActiveAsReference ());
126112 });
127113 cbRegion .addValueChangeListener (e -> {
128114 RegionReferenceDto region = (RegionReferenceDto ) e .getProperty ().getValue ();
129- if (Objects .nonNull (region )){
115+ if (Objects .nonNull (region )) {
130116 cbArea .setValue (FacadeProvider .getRegionFacade ().getRegionByUuid (region .getUuid ()).getArea ());
131117 }
132118 });
133119 }
134120 }
121+
135122 private void addInfrastructureListeners (ComboBox cbRegion , ComboBox cbDistrict , ComboBox cbCommunity ) {
136123 cbRegion .addValueChangeListener (e -> {
137124 RegionReferenceDto region = (RegionReferenceDto ) e .getProperty ().getValue ();
0 commit comments