Project

General

Profile

« Previous | Next » 

Revision 5003e7af

Added by Andreas Kohlbecker over 5 years ago

fix #7942 using required flag and validation to prevent from saving without typedesignations

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
15 15
import org.springframework.security.core.GrantedAuthority;
16 16
import org.vaadin.viritin.fields.ElementCollectionField;
17 17

  
18
import com.vaadin.data.Validator.InvalidValueException;
18 19
import com.vaadin.data.validator.DoubleRangeValidator;
20
import com.vaadin.server.ErrorMessage;
19 21
import com.vaadin.spring.annotation.SpringComponent;
20 22
import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
21 23
import com.vaadin.ui.Component;
......
84 86

  
85 87
    private GeoLocationField exactLocationField;
86 88

  
89
    private Panel typeDesignationsScrollPanel;
90

  
87 91
    /**
88 92
     * @return the countrySelectField
89 93
     */
......
183 187
        row++;
184 188

  
185 189
        // FIXME: can we use the Grid instead?
186
        typeDesignationsCollectionField = new ElementCollectionField<>(
190
        typeDesignationsCollectionField = new ElementCollectionField<SpecimenTypeDesignationDTO>(
187 191
                SpecimenTypeDesignationDTO.class,
188 192
                SpecimenTypeDesignationDTORow.class
189
                );
193
                ){
194

  
195
                    @Override
196
                    public void commit() throws SourceException, InvalidValueException {
197
                        validate(); // validate always so that empty rows are recognized
198
                        super.commit();
199
                    }
200

  
201
                    @Override
202
                    public boolean isEmpty() {
203
                        Collection value = getValue();
204
                        return value == null || value.isEmpty() ;
205
                    }
206

  
207
                    @Override
208
                    public void setComponentError(ErrorMessage componentError) {
209
                        typeDesignationsScrollPanel.setComponentError(componentError);
210
                    }
211

  
212
        };
190 213
        typeDesignationsCollectionField.withCaption("Types");
191 214
        typeDesignationsCollectionField.getLayout().setSpacing(false);
192 215
        typeDesignationsCollectionField.getLayout().setColumns(3);
193

  
216
        typeDesignationsCollectionField.setRequired(true); // only works with the above overwritten commit()
217
        typeDesignationsCollectionField.setRequiredError(CAN_T_SAVE_AS_LONG_AS_TYPE_DESIGNATIONS_ARE_MISSING);
194 218
        typeDesignationsCollectionField.setVisibleProperties(SpecimenTypeDesignationDTORow.visibleFields());
195 219

  
196 220
        typeDesignationsCollectionField.setPropertyHeader("accessionNumber", "Access. num.");
197 221
        typeDesignationsCollectionField.setPropertyHeader("preferredStableUri", "Stable URI");
198 222
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReference", "Image reference");
199 223
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReferenceDetail", "Reference detail");
200
        typeDesignationsCollectionField.addElementAddedListener( e -> updateAllowSave());
201
        typeDesignationsCollectionField.addElementRemovedListener( e -> updateAllowSave());
224
        typeDesignationsCollectionField.addElementAddedListener( e -> typeDesignationsCollectionField.setComponentError(null));
202 225

  
203 226
        // typeDesignationsCollectionField.getLayout().setMargin(false);
204 227
        // typeDesignationsCollectionField.addStyleName("composite-field-wrapper");
205 228
        // addField(typeDesignationsCollectionField, "specimenTypeDesignationDTOs", 0, row, 2, row);
206 229

  
207
        Panel scrollPanel = new Panel(typeDesignationsCollectionField.getLayout());
208
        scrollPanel.setCaption("Types");
209
        scrollPanel.setWidth(800, Unit.PIXELS);
230
        typeDesignationsScrollPanel = new Panel(typeDesignationsCollectionField.getLayout());
231
        typeDesignationsScrollPanel.setCaption("Types");
232
        typeDesignationsScrollPanel.setWidth(800, Unit.PIXELS);
210 233

  
211 234
        bindField(typeDesignationsCollectionField, "specimenTypeDesignationDTOs");
212
        addComponent(scrollPanel, 0, row, 2, row);
235
        addComponent(typeDesignationsScrollPanel, 0, row, 2, row);
213 236

  
214 237
        row++;
215 238
        annotationsListField = new FilterableAnnotationsField("Editorial notes");
......
303 326
            ((CollectionRowRepresentative)item).updateRowItemsEnabledStates();
304 327
        }
305 328
        updateAllowDelete();
306
        updateAllowSave();
307 329
    }
308 330

  
309 331
    /**
......
320 342
        }
321 343
    }
322 344

  
323
    public void updateAllowSave(){
324
        boolean hasTypeDesignations = getBean().getSpecimenTypeDesignationDTOs().size() > 0;
325
        setSaveButtonEnabled(hasTypeDesignations);
326
        if(!hasTypeDesignations){
327
            addStatusMessage(CAN_T_SAVE_AS_LONG_AS_TYPE_DESIGNATIONS_ARE_MISSING);
328
        } else {
329
            removeStatusMessage(CAN_T_SAVE_AS_LONG_AS_TYPE_DESIGNATIONS_ARE_MISSING);
330
        }
331

  
332
    }
333 345

  
334 346
    /**
335 347
     * {@inheritDoc}

Also available in: Unified diff