Project

General

Profile

Download (1.7 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
    private Class<? extends CDM> type;
31

    
32

    
33
    public ToOneRelatedEntityButtonUpdater(ToOneRelatedEntityField<CDM> toOneRelatedEntityField){
34
        this.toOneRelatedEntityField = toOneRelatedEntityField;
35
        this.type = toOneRelatedEntityField.getType();
36
    }
37

    
38
    /**
39
     * {@inheritDoc}
40
     */
41
    @Override
42
    public void valueChange(ValueChangeEvent event) {
43

    
44
        CdmBase value = (CdmBase)event.getProperty().getValue();
45

    
46
        boolean userIsAllowedToUpdate = value != null && UserHelper.fromSession().userHasPermission(value, CRUD.UPDATE);
47
        boolean userIsAllowedToCreate = UserHelper.fromSession().userHasPermission(type, CRUD.CREATE);
48

    
49
        toOneRelatedEntityField.setAddButtonEnabled(userIsAllowedToCreate);
50
        toOneRelatedEntityField.setEditButtonEnabled(userIsAllowedToUpdate);
51

    
52
    }
53

    
54
}
(15-15/18)