@@ -114,6 +114,7 @@ public void setFieldsRequirement(boolean required, String... fieldIds) {
114114 setRequired (required , fieldIds );
115115 }
116116
117+ @ SuppressWarnings ("deprecation" )
117118 @ Override
118119 protected void addFields () {
119120
@@ -141,7 +142,6 @@ protected void addFields() {
141142 facilityTypeGroup .addItems (FacilityTypeGroup .values ());
142143 getContent ().addComponent (facilityTypeGroup , FACILITY_TYPE_GROUP_LOC );
143144 ComboBox facilityType = addField (LocationDto .FACILITY_TYPE );
144- FieldHelper .removeItems (facilityType );
145145 ComboBox facility = addInfrastructureField (LocationDto .FACILITY );
146146 facility .setImmediate (true );
147147 TextField facilityDetails = addField (LocationDto .FACILITY_DETAILS , TextField .class );
@@ -180,7 +180,6 @@ protected void addFields() {
180180 .updateItems (district , regionDto != null ? FacadeProvider .getDistrictFacade ().getAllActiveByRegion (regionDto .getUuid ()) : null );
181181 });
182182 district .addValueChangeListener (e -> {
183- FieldHelper .removeItems (community );
184183 DistrictReferenceDto districtDto = (DistrictReferenceDto ) e .getProperty ().getValue ();
185184 FieldHelper .updateItems (
186185 community ,
@@ -215,9 +214,13 @@ protected void addFields() {
215214 facilityTypeGroup .addValueChangeListener (e -> {
216215 FieldHelper .removeItems (facility );
217216 FieldHelper .updateEnumData (facilityType , FacilityType .getTypes ((FacilityTypeGroup ) facilityTypeGroup .getValue ()));
217+ facilityType .setRequired (facilityTypeGroup .getValue () != null );
218218 });
219219 facilityType .addValueChangeListener (e -> {
220220 FieldHelper .removeItems (facility );
221+ if (facilityType .getValue () != null && facilityTypeGroup .getValue () == null ) {
222+ facilityTypeGroup .setValue (((FacilityType ) facilityType .getValue ()).getFacilityTypeGroup ());
223+ }
221224 if (facilityType .getValue () != null && district .getValue () != null ) {
222225 if (community .getValue () != null ) {
223226 FieldHelper .updateItems (
@@ -249,36 +252,20 @@ protected void addFields() {
249252
250253 if (!visibleAndRequired ) {
251254 facilityDetails .clear ();
255+ } else {
256+ facilityDetails .setValue (getValue ().getFacilityDetails ());
252257 }
253258 } else {
254259 facilityDetails .setVisible (false );
255260 facilityDetails .setRequired (false );
256261 facilityDetails .clear ();
257262 }
258- this .getValue ().setFacilityType ((FacilityType ) facilityType .getValue ());
259263 });
260264 region .addItems (FacadeProvider .getRegionFacade ().getAllActiveAsReference ());
261265
262266 Stream .of (LocationDto .LATITUDE , LocationDto .LONGITUDE )
263267 .<Field <?>> map (this ::getField )
264268 .forEach (f -> f .addValueChangeListener (e -> this .updateLeafletMapContent ()));
265-
266- addValueChangeListener (e -> {
267- if (getValue ().getFacility () != null ) {
268- boolean facilityTypeGroupReadOnly = facilityTypeGroup .isReadOnly ();
269- facilityTypeGroup .setReadOnly (false );
270-
271- FacilityType caseFacilityType = getValue ().getFacilityType ();
272- facilityTypeGroup .setValue (caseFacilityType .getFacilityTypeGroup ());
273- if (!facilityType .isReadOnly ()) {
274- facilityType .setValue (caseFacilityType );
275- }
276-
277- facilityTypeGroup .setReadOnly (facilityTypeGroupReadOnly );
278- facility .setValue (getValue ().getFacility ());
279- facilityDetails .setValue (getValue ().getFacilityDetails ());
280- }
281- });
282269 }
283270
284271 private HorizontalLayout createGeoButton () {
0 commit comments