Project

General

Profile

Download (3.84 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.description;
10

    
11
import java.util.Collection;
12
import java.util.stream.Collectors;
13

    
14
import org.eclipse.jface.util.PropertyChangeEvent;
15

    
16
import eu.etaxonomy.cdm.model.description.DescriptionBase;
17
import eu.etaxonomy.cdm.model.description.DescriptionType;
18
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
21
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
22
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
23

    
24
/**
25
 * <p>DescriptionDetailElement class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @created Mar 5, 2010
29
 */
30
public class DescriptionDetailElement
31
        extends AbstractIdentifiableEntityDetailElement<DescriptionBase<?>> {
32

    
33
//	private EntitySelectionElement<FeatureTree> selection_featureTree;
34
    private TextWithLabelElement txtDescriptionTypes;
35

    
36
	public DescriptionDetailElement(CdmFormFactory cdmFormFactory,
37
			ICdmFormElement formElement, int style) {
38
		super(cdmFormFactory, formElement);
39

    
40
	}
41

    
42
	@Override
43
	protected void createControls(ICdmFormElement formElement, DescriptionBase entity, int style) {
44
        toggleable_cache = formFactory.createToggleableTextField(this, "Label",
45
                entity.getTitleCache(), entity.isProtectedTitleCache(), style);
46

    
47
		// TODO I initially thought that we can handle the entity's descriptive system with a feature tree
48
		// Since descriptiveSystem is a Set of Features that are present or allowed for the current description,
49
		// it is similar to a FeatureTree (you can get this information from a feature tree) but not the same.
50
		// Please correct this once it is clear what descriptive system will be used for in CDM
51
//		selection_featureTree = formFactory.createSelectionElement(FeatureTree.class, formElement, "Feature Tree", null, EntitySelectionElement.ALL, style);
52

    
53
        Object typesString = entity.getTypes().stream().filter(type->type instanceof DescriptionType)
54
        		.map(type->((DescriptionType)type).getLabel())
55
        		.collect(Collectors.joining(","));
56
        txtDescriptionTypes = formFactory.createTextWithLabelElement(formElement, "Types", typesString, style);
57
        txtDescriptionTypes.setEnabled(false);
58

    
59
	}
60

    
61
	@Override
62
    public void setEnabled(boolean enabled, Collection<Object> except) {
63
        this.enabled = enabled;
64
        for (ICdmFormElement element : getElements()) {
65
            if (element instanceof IEnableableFormElement) {
66
                IEnableableFormElement enableableElement = (IEnableableFormElement) element;
67
                enableableElement.setEnabled(enabled);
68
//                if (enableableElement instanceof ToggleableTextElement){
69
//                    ToggleableTextElement toggle = (ToggleableTextElement)enableableElement;
70
//                    toggle.getBtnToggleProtectTitleCache().setEnabled(enabled);
71
//                }
72

    
73
            }
74
        }
75
        txtDescriptionTypes.setEnabled(false);
76
    }
77

    
78

    
79

    
80
    @Override
81
    protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
82
        if(!getEntity().isProtectedTitleCache()){
83
            String title = getEntity().generateTitle();
84
            getEntity().setTitleCache(title, false);
85
        }
86
        super.updateToggleableCacheField();
87
    }
88

    
89
	@Override
90
	public void handleEvent(Object eventSource) {
91
        if (eventSource == toggleable_cache) {
92
            if (!this.enabled){
93
                return;
94
            }
95
            getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
96
            updateCacheRelevance();
97
        }
98
	}
99

    
100

    
101
}
(4-4/26)