Project

General

Profile

« Previous | Next » 

Revision caf42d50

Added by Andreas Kohlbecker over 5 years ago

fixing inconsistent nomenclaturalTitleCacheField behavior

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/TextFieldNFix.java
45 45
     */
46 46
    public TextFieldNFix() {
47 47
        super();
48
        setNullSettingAllowed(true);
48 49
    }
49 50

  
50 51

  
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/PersonField.java
10 10

  
11 11
import java.util.EnumSet;
12 12
import java.util.List;
13
import java.util.regex.Pattern;
13 14

  
14 15
import org.vaadin.teemu.switchui.Switch;
15 16
import org.vaadin.viritin.fields.LazyComboBox;
......
43 44

  
44 45
    private static final String PRIMARY_STYLE = "v-person-field";
45 46

  
47
    private static final Pattern EMPTY_ENTITY_TITLE_CACHE_PATTERN = Pattern.compile("[a-zA-Z]+#[0-9]+<[a-f0-9\\-]+>");
48

  
46 49
    /**
47 50
     * do not allow entities which are having only <code>null</code> values in all fields
48 51
     * {@link #getValue()} would return <code>null</code> in this case.
......
202 205
        });
203 206
        // nomenclaturalTitleField.setCaption("Nomenclatural title");
204 207
        nomenclaturalTitleField.setWidth(100, Unit.PERCENTAGE);
208
//        nomenclaturalTitleField.addValueChangeListener( e -> {
209
//            if(e.getProperty().getValue() != null && ((String)e.getProperty().getValue()).isEmpty()){
210
//
211
//            }
212
//        });
205 213

  
206 214
        root.addComponent(nomenclaturalTitleField);
207 215
        root.addComponent(nomenclaturalTitleButton);
......
304 312
        unlockSwitch.setVisible(person != null);
305 313
        titleCacheField.setVisible(person != null);
306 314
        String nomTitle = nomenclaturalTitleField.getValue();
307
        nomenclaturalTitleField.setVisible(nomTitle != null && nomTitle.equals(titleCacheField.getValue()));
315
        boolean isEmptyItemTitle = nomTitle == null || EMPTY_ENTITY_TITLE_CACHE_PATTERN.matcher(nomTitle).matches();
316
        boolean nomTitleEqualsTitleCache = nomTitle != null && nomTitle.equals(titleCacheField.getValue());
317
        nomenclaturalTitleField.setVisible( !isEmptyItemTitle && !nomTitleEqualsTitleCache);
308 318
        nomenclaturalTitleButtonChooseIcon();
309 319

  
310 320
    }
......
355 365
        super.commit();
356 366

  
357 367
        Person bean =  getValue();
368
        String nomTitle = nomenclaturalTitleField.getValue();
369
        if(nomTitle != null && nomTitle.equals(titleCacheField.getValue())){
370
            // no point having a nomenclaturalTitle if it is equal to the titleCache
371
            bean.setNomenclaturalTitle(null);
372
        }
358 373
        if(bean != null){
359 374
            boolean isUnsaved = bean.getId() == 0;
360 375
            if(isUnsaved && !(hasNullContent() && !allowNewEmptyEntity)){

Also available in: Unified diff