Project

General

Profile

Download (2.12 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.Arrays;
12
import java.util.EnumSet;
13

    
14
import eu.etaxonomy.cdm.model.common.CdmBase;
15
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
16
import eu.etaxonomy.cdm.model.permission.CRUD;
17
import eu.etaxonomy.taxeditor.store.CdmStore;
18
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
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> extends
26
        AbstractCdmDetailElement<T> {
27

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

    
31

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

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

    
45
    protected void handleToggleableCacheField() {
46
        boolean pushedState = toggleable_cache.getState();
47

    
48
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
49
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache }));
50
        updateToggleableCacheField();
51
    }
52

    
53
    @Override
54
    protected void updateControlStates(){
55

    
56
        updateToggleableCacheState();
57
        super.updateControlStates();
58
    }
59

    
60
    private void updateToggleableCacheState() {
61
        if(toggleable_cache != null){
62
            toggleable_cache.setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
63
        }
64
    }
65
}
(5-5/9)