Project

General

Profile

Download (2.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.taxeditor.ui.section;
10

    
11
import java.util.EnumSet;
12

    
13
import eu.etaxonomy.cdm.model.common.CdmBase;
14
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
15
import eu.etaxonomy.cdm.model.permission.CRUD;
16
import eu.etaxonomy.taxeditor.store.CdmStore;
17
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
18
import eu.etaxonomy.taxeditor.ui.element.ICacheRelevantFormElement;
19
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
21

    
22
/**
23
 * @author n.hoffmann
24
 */
25
public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentifiableEntity>
26
		extends AbstractCdmDetailElement<T> {
27

    
28
    private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
29
    protected ToggleableTextElement toggleable_cache;
30

    
31
    public AbstractIdentifiableEntityDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
32
        super(formFactory, formElement);
33
        updateToggleableCacheState();
34
    }
35

    
36
    public void updateToggleableCacheField() {
37
        if (toggleable_cache != null){
38
            if (!getEntity().isProtectedTitleCache()) {
39
                toggleable_cache.setText(getEntity().generateTitle());
40
            }
41
        }
42
    }
43

    
44
    protected void handleToggleableCacheField() {
45
        getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
46
        updateCacheRelevance();
47
        updateToggleableCacheField();
48
    }
49

    
50
    @Override
51
    protected void updateControlStates(){
52
        updateToggleableCacheState();
53
        super.updateControlStates();
54
    }
55

    
56
    private void updateToggleableCacheState() {
57
        if(toggleable_cache != null){
58
            toggleable_cache.setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
59
        }
60
    }
61

    
62
    protected void registerCacheRelevance(ICacheRelevantFormElement element) {
63
        registerCacheRelevance(element, toggleable_cache);
64
    }
65
}
(5-5/9)