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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.section.description;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.stream.Collectors;
|
14
|
|
15
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
18
|
import eu.etaxonomy.cdm.model.description.DescriptionType;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
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 extends AbstractIdentifiableEntityDetailElement<DescriptionBase<?>> {
|
31
|
|
32
|
// private EntitySelectionElement<FeatureTree> selection_featureTree;
|
33
|
private TextWithLabelElement txtDescriptionTypes;
|
34
|
|
35
|
public DescriptionDetailElement(CdmFormFactory cdmFormFactory,
|
36
|
ICdmFormElement formElement, int style) {
|
37
|
super(cdmFormFactory, formElement);
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
protected void createControls(ICdmFormElement formElement, DescriptionBase entity, int style) {
|
42
|
toggleable_cache = formFactory.createToggleableTextField(this, "Label", entity.getTitleCache(), entity.isProtectedTitleCache(), style);
|
43
|
// TODO I initially thought that we can handle the entity's descriptive system with a feature tree
|
44
|
// Since descriptiveSystem is a Set of Features that are present or allowed for the current description,
|
45
|
// it is similar to a FeatureTree (you can get this information from a feature tree) but not the same.
|
46
|
// Please correct this once it is clear what descriptive system will be used for in CDM
|
47
|
// selection_featureTree = formFactory.createSelectionElement(FeatureTree.class, getConversationHolder(), formElement, "Feature Tree", null, EntitySelectionElement.ALL, style);
|
48
|
|
49
|
Object typesString = entity.getTypes().stream().filter(type->type instanceof DescriptionType)
|
50
|
.map(type->((DescriptionType)type).getLabel())
|
51
|
.collect(Collectors.joining(","));
|
52
|
txtDescriptionTypes = formFactory.createTextWithLabelElement(formElement, "Types", typesString, style);
|
53
|
txtDescriptionTypes.setEnabled(false);
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
protected void updateContent() {
|
58
|
super.updateContent();
|
59
|
toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
|
60
|
setIrrelevant(toggleable_cache.getState(),
|
61
|
Arrays.asList(new Object[] { txtDescriptionTypes, toggleable_cache}));
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
|
66
|
if(!getEntity().isProtectedTitleCache()){
|
67
|
String title = getEntity().generateTitle();
|
68
|
getEntity().setTitleCache(title, false);
|
69
|
}
|
70
|
super.updateToggleableCacheField();
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public void handleEvent(Object eventSource) {
|
75
|
if (eventSource == toggleable_cache) {
|
76
|
getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
|
77
|
setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[] { toggleable_cache }));
|
78
|
}
|
79
|
}
|
80
|
}
|