Project

General

Profile

« Previous | Next » 

Revision c8cf806c

Added by Andreas Kohlbecker almost 6 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

  

Also available in: Unified diff