Project

General

Profile

« Previous | Next » 

Revision ea92bdaa

Added by Andreas Kohlbecker over 5 years ago

ref #7910 TeamOrPersonField adapting read only state handling to available teammebers setter

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
167 167
        boolean userCanCreate = UserHelperAccess.userHelper().userHasPermission(Person.class, "CREATE");
168 168

  
169 169
        teamOrPersonSelect.setVisible(val == null);
170
        removeButton.setVisible(val != null);
171
        personButton.setEnabled(userCanCreate && val == null);
172
        teamButton.setEnabled(userCanCreate && val == null);
170
        removeButton.setVisible(!isReadOnly() && val != null);
171
        personButton.setEnabled(!isReadOnly() && userCanCreate && val == null);
172
        teamButton.setEnabled(!isReadOnly() && userCanCreate && val == null);
173 173
    }
174 174

  
175 175
    /**
......
187 187
        compositeWrapper.addComponent(toolBar);
188 188

  
189 189
        if(newValue != null) {
190

  
191 190
            if(Person.class.isAssignableFrom(newValue.getClass())){
192 191
                // value is a Person
193 192
                compositeWrapper.addComponent(personField);
......
199 198
            else if(Team.class.isAssignableFrom(newValue.getClass())){
200 199
                // otherwise it a Team
201 200
                compositeWrapper.addComponents(titleField, nomenclaturalTitleField, personsListEditor);
202

  
203 201
                titleField.bindTo(fieldGroup, "titleCache", "protectedTitleCache");
204 202
                nomenclaturalTitleField.bindTo(fieldGroup, "nomenclaturalTitle", "protectedNomenclaturalTitleCache");
205 203
                fieldGroup.setItemDataSource(new BeanItem<Team>((Team)newValue));
206
                boolean readonlyState = personsListEditor.isReadOnly();
207
                fieldGroup.bind(personsListEditor, "teamMembers"); // here personField is set readonly since setTeamMembers does not exist
208
                personsListEditor.setReadOnly(readonlyState); // fixing the readonly state
209

  
204
                fieldGroup.bind(personsListEditor, "teamMembers");
210 205
                personsListEditor.registerParentFieldGroup(fieldGroup);
211

  
212 206
            } else {
213 207
                UserError usererror = new UserError("TeamOrPersonField Error: Unsupported value type: " + newValue.getClass().getName());
214 208
                setComponentError(usererror);
215 209
                logger.error(usererror.getMessage());
216 210
            }
217 211
        } else {
212
            // new value is null
218 213
            if(oldValue != null){
219
                // value is null --> clean up all nested fields
214
                // value is null --> clean up all nested fields from old value
220 215
                // allow replacing old content in the editor by null
221 216
                setReadOnlyComponents(false);
222 217
                if(Person.class.isAssignableFrom(oldValue.getClass())){
......
250 245
        boolean canEdit = teamOrPerson == null || !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
251 246
        if(!canEdit){
252 247
            setReadOnlyComponents(true);
248
            fieldGroup.setReadOnly(true); // really needed?
253 249
        }
254 250
    }
255 251

  
......
307 303
        }
308 304

  
309 305
        TeamOrPersonBase<?> bean = getValue();
310
        if(bean != null && bean instanceof Team){
306
        boolean isTeam = bean != null && bean instanceof Team;
307
        if(isTeam){
311 308
            boolean isUnsaved = bean.getId() == 0;
312 309
            if(isUnsaved){
313 310
                UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, EnumSet.of(CRUD.UPDATE, CRUD.DELETE), null);
......
428 425
     * @param readOnly
429 426
     */
430 427
    protected void setReadOnlyComponents(boolean readOnly) {
431
        setDeepReadOnly(readOnly, getContent(), editorComponents);
428

  
429
        // setDeepReadOnly(readOnly, getContent(), editorComponents);
430
        // editorComponents.forEach(c -> c.setEnabled(!readOnly));
431
//        personField.setReadOnly(readOnly);
432
//        personsListEditor.setReadOnly(readOnly);
433

  
432 434
        updateCaptionReadonlyNotice(readOnly);
433 435
    }
434 436

  

Also available in: Unified diff