Project

General

Profile

Download (3.35 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.Arrays;
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.TextWithLabelElement;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
22

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

    
31
//	private EntitySelectionElement<FeatureTree> selection_featureTree;
32
    private TextWithLabelElement txtDescriptionTypes;
33

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

    
39
	@Override
40
	protected void createControls(ICdmFormElement formElement, DescriptionBase entity, int style) {
41
        toggleable_cache = formFactory.createToggleableTextField(this, "Label", entity.getTitleCache(), entity.isProtectedTitleCache(), style);
42
		// TODO I initially thought that we can handle the entity's descriptive system with a feature tree
43
		// Since descriptiveSystem is a Set of Features that are present or allowed for the current description,
44
		// it is similar to a FeatureTree (you can get this information from a feature tree) but not the same.
45
		// Please correct this once it is clear what descriptive system will be used for in CDM
46
//		selection_featureTree = formFactory.createSelectionElement(FeatureTree.class, getConversationHolder(), formElement, "Feature Tree", null, EntitySelectionElement.ALL, style);
47

    
48
        Object typesString = entity.getTypes().stream().filter(type->type instanceof DescriptionType)
49
        		.map(type->((DescriptionType)type).getLabel())
50
        		.collect(Collectors.joining(","));
51
        txtDescriptionTypes = formFactory.createTextWithLabelElement(formElement, "Types", typesString, style);
52
        txtDescriptionTypes.setEnabled(false);
53
	}
54

    
55
    @Override
56
    protected void updateContent() {
57
        super.updateContent();
58
        toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
59
        setIrrelevant(toggleable_cache.getState(),
60
                Arrays.asList(new Object[] { txtDescriptionTypes, toggleable_cache}));
61
    }
62

    
63
    @Override
64
    protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
65
        if(!getEntity().isProtectedTitleCache()){
66
            String title = getEntity().generateTitle();
67
            getEntity().setTitleCache(title, false);
68
        }
69
        super.updateToggleableCacheField();
70
    }
71

    
72
	@Override
73
	public void handleEvent(Object eventSource) {
74
        if (eventSource == toggleable_cache) {
75
            getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
76
            setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[] { toggleable_cache }));
77
        }
78
	}
79
}
(4-4/26)