Project

General

Profile

Download (1.72 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

    
13
import eu.etaxonomy.cdm.model.common.CdmBase;
14
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
15
import eu.etaxonomy.cdm.service.UserHelperAccess;
16
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityField;
17

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

    
25
    private static final long serialVersionUID = 4472031263172275012L;
26

    
27
    ToOneRelatedEntityField<CDM>  toOneRelatedEntityField;
28

    
29
    private Class<? extends CDM> type;
30

    
31

    
32
    public ToOneRelatedEntityButtonUpdater(ToOneRelatedEntityField<CDM> toOneRelatedEntityField){
33
        this.toOneRelatedEntityField = toOneRelatedEntityField;
34
        this.type = toOneRelatedEntityField.getType();
35
        toOneRelatedEntityField.setEditButtonEnabled(false);
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 && UserHelperAccess.userHelper().userHasPermission(value, CRUD.UPDATE);
47
        boolean userIsAllowedToCreate = UserHelperAccess.userHelper().userHasPermission(type, CRUD.CREATE);
48

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

    
52
    }
53

    
54
}
(20-20/24)