Project

General

Profile

Download (1.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.event;
10

    
11
import com.vaadin.data.Property.ValueChangeEvent;
12
import com.vaadin.data.Property.ValueChangeListener;
13

    
14
import eu.etaxonomy.cdm.model.common.CdmBase;
15
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
16
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
17
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityField;
18

    
19
/**
20
 * @author a.kohlbecker
21
 * @since 19.10.2017
22
 *
23
 */
24
public class ToOneRelatedEntityButtonUpdater<CDM extends CdmBase> implements ValueChangeListener {
25

    
26
    private static final long serialVersionUID = 4472031263172275012L;
27

    
28
    ToOneRelatedEntityField<CDM>  toOneRelatedEntityField;
29

    
30
    public ToOneRelatedEntityButtonUpdater(ToOneRelatedEntityField<CDM> toOneRelatedEntityField){
31
        this.toOneRelatedEntityField = toOneRelatedEntityField;
32
    }
33

    
34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    public void valueChange(ValueChangeEvent event) {
39

    
40
        CdmBase value = (CdmBase)event.getProperty().getValue();
41

    
42
        boolean userIsAllowedToUpdate = UserHelper.fromSession().userHasPermission(value, CRUD.UPDATE);
43
        boolean userIsAllowedToCreate = UserHelper.fromSession().userHasPermission(value.getClass(), CRUD.CREATE);
44

    
45
        toOneRelatedEntityField.setAddButtonEnabled(userIsAllowedToCreate);
46
        toOneRelatedEntityField.setEditButtonEnabled(userIsAllowedToUpdate);
47

    
48
    }
49

    
50
}
(15-15/17)