Project

General

Profile

Revision c8cf806c

IDc8cf806c6f86514a56af30050045d28d25289f2c
Parent 851d4dc2
Child e04ffd41

Added by Andreas Kohlbecker over 2 years ago

ref #7366 fixing problems with readonly states while setting values

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
80 80

  
81 81
    private TeamOrPersonBaseCaptionGenerator.CacheType cacheType;
82 82

  
83
    protected List<Component> editorComponents = Arrays.asList(removeButton, personButton, teamButton, teamOrPersonSelect);
84

  
83 85
    public TeamOrPersonField(String caption, TeamOrPersonBaseCaptionGenerator.CacheType cacheType){
84 86

  
85 87
        setCaption(caption);
......
123 125
        selectConfirmButton.setEnabled(teamOrPersonSelect.getValue() != null);
124 126
        selectConfirmButton.addClickListener(e -> {
125 127
            // new entitiy being set, reset the readonly state
126
            resetReadOnlyComponents();
127
            setValue(teamOrPersonSelect.getValue());
128
//            resetReadOnlyComponents();
129
//            getPropertyDataSource().setReadOnly(false);
130
            setValue(teamOrPersonSelect.getValue(), false, true);
128 131
            teamOrPersonSelect.clear();
129 132
            updateToolBarButtonStates();
130 133
        });
131 134
        removeButton.addClickListener(e -> {
132
            resetReadOnlyComponents();
133
            setValue(null);
135
//            resetReadOnlyComponents();
136
//            getPropertyDataSource().setReadOnly(false);
137
            setValue(null, false, true);
134 138
            updateToolBarButtonStates();
135 139
        });
136 140
        removeButton.setDescription("Remove");
137 141

  
138 142
        personButton.addClickListener(e -> {
139
            setValue(Person.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
143
            setValue(Person.NewInstance(), false, true); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
140 144

  
141 145
        });
142 146
        personButton.setDescription("Add person");
143 147
        teamButton.addClickListener(e -> {
144
            setValue(Team.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
148
            setValue(Team.NewInstance(), false, true); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
145 149
        });
146 150
        teamButton.setDescription("Add team");
147 151

  
......
243 247

  
244 248
    private void adaptToUserPermissions(TeamOrPersonBase teamOrPerson) {
245 249

  
246
        if(teamOrPerson == null){
247
            return;
248
        }
249

  
250 250
        UserHelper userHelper = UserHelper.fromSession();
251
        boolean canEdit = !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
251
        boolean canEdit = teamOrPerson == null || !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
252 252
        if(!canEdit){
253
            setReadOnlyComponents(true);
253
            getPropertyDataSource().setReadOnly(true);
254
            //setReadOnlyComponents(true); will be set later on automatically by vaadin
254 255
        }
255 256
    }
256 257

  
......
382 383
     */
383 384
    @Override
384 385
    public void setReadOnly(boolean readOnly) {
385
        super.setReadOnly(readOnly);
386
//        super.setReadOnly(readOnly); // moved into setEditorReadOnly()
386 387
        setReadOnlyComponents(readOnly);
387 388
    }
388 389

  
390
    public void setEditorReadOnly(boolean readOnly) {
391
        super.setReadOnly(readOnly);
392
        for(Component c : editorComponents){
393
            c.setReadOnly(readOnly);
394
        }
395

  
396
    }
397

  
389 398
    /**
390 399
     * Reset the readonly state of nested components to <code>false</code>.
391 400
     */
......
403 412
     *
404 413
     * @param readOnly
405 414
     */
406
    public void setReadOnlyComponents(boolean readOnly) {
407
        setDeepReadOnly(readOnly, getContent(), Arrays.asList(removeButton, personButton, teamButton, teamOrPersonSelect));
408
        updateCaptionReadonlyNotice();
415
    protected void setReadOnlyComponents(boolean readOnly) {
416
        setDeepReadOnly(readOnly, getContent(), editorComponents);
417
        updateCaptionReadonlyNotice(readOnly);
409 418
    }
410 419

  
411 420

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
668 668
        boolean basionymToggleReadonly = basionymToggle.isReadOnly();
669 669
        boolean validationToggleReadonly = validationToggle.isReadOnly();
670 670
        super.setReadOnly(readOnly);
671
        combinationAuthorshipField.setEditorReadOnly(readOnly);
672
        exCombinationAuthorshipField.setEditorReadOnly(readOnly);
673
        basionymAuthorshipField.setEditorReadOnly(readOnly);
674
        exBasionymAuthorshipField.setEditorReadOnly(readOnly);
671 675
        // preserve old readonly states if they were true
672 676
        if(basionymToggleReadonly){
673 677
            basionymToggle.setReadOnly(true);
src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java
214 214
    }
215 215

  
216 216
    /**
217
     * {@inheritDoc}
218
     */
219
    @Override
220
    public void setReadOnly(boolean readOnly) {
221
        super.setReadOnly(readOnly);
222
        // setDeepReadOnly(readOnly, getContent());
223
    }
224

  
225
    /**
226 217
     * @param readOnly
227 218
     */
228 219
    protected void setDeepReadOnly(boolean readOnly, Component component, Collection<Component> ignore) {
......
248 239
                ( getValue() != null ? getValue() : "null");
249 240
    }
250 241

  
251
    protected void updateCaptionReadonlyNotice() {
252
        if(isReadOnly()){
242
    protected void updateCaptionReadonlyNotice(boolean readOnly) {
243
        if(readOnly){
253 244
            setCaption(getCaption() + READ_ONLY_CAPTION_SUFFIX);
254 245
        } else {
255 246
            setCaption(getCaption().replace(READ_ONLY_CAPTION_SUFFIX, ""));

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)