1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.section.name;
|
12
|
|
13
|
import java.util.Arrays;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.eclipse.ui.forms.widgets.Section;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
20
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
|
21
|
import eu.etaxonomy.taxeditor.forms.ICdmFormElement;
|
22
|
import eu.etaxonomy.taxeditor.forms.ToggleableTextElement;
|
23
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType;
|
24
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.EnumComboType;
|
25
|
import eu.etaxonomy.taxeditor.forms.term.NomenclaturalCodeComboElement;
|
26
|
import eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement;
|
27
|
import eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection;
|
28
|
|
29
|
/**
|
30
|
* <p>NonViralNameDetailElement class.</p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created May 20, 2010
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class NonViralNameDetailElement extends AbstractCdmDetailElement<NonViralName> {
|
37
|
|
38
|
|
39
|
private static final Logger logger = Logger
|
40
|
.getLogger(NonViralNameDetailElement.class);
|
41
|
private NameDetailSection section_name;
|
42
|
private AuthorshipDetailSection section_author;
|
43
|
private ToggleableTextElement toggleable_cache;
|
44
|
private NomenclaturalCodeComboElement combo_nomenclaturalCode;
|
45
|
|
46
|
/**
|
47
|
* <p>Constructor for NonViralNameDetailElement.</p>
|
48
|
*
|
49
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
|
50
|
* @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
|
51
|
*/
|
52
|
public NonViralNameDetailElement(CdmFormFactory formFactory,
|
53
|
ICdmFormElement formElement) {
|
54
|
super(formFactory, formElement);
|
55
|
}
|
56
|
|
57
|
/* (non-Javadoc)
|
58
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
|
59
|
*/
|
60
|
/** {@inheritDoc} */
|
61
|
@Override
|
62
|
protected void createControls(ICdmFormElement formElement,
|
63
|
NonViralName entity, int style) {
|
64
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
|
65
|
|
66
|
combo_nomenclaturalCode = (NomenclaturalCodeComboElement) formFactory.createEnumComboElement(EnumComboType.NOMENCLATURALCODE, formElement, style);
|
67
|
combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
|
68
|
|
69
|
section_name = (NameDetailSection) formFactory.createCdmDetailSection(DetailType.SCIENTIFICNAME, getConversationHolder(), formElement, null, Section.TWISTIE | Section.EXPANDED);
|
70
|
section_name.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
|
71
|
addControl(section_name);
|
72
|
addElement(section_name);
|
73
|
section_author = (AuthorshipDetailSection) formFactory.createCdmDetailSection(DetailType.AUTHORSHIP, getConversationHolder(), formElement, null, Section.TWISTIE | Section.EXPANDED);
|
74
|
section_author.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
|
75
|
addControl(section_author);
|
76
|
addElement(section_author);
|
77
|
}
|
78
|
|
79
|
/** {@inheritDoc} */
|
80
|
@Override
|
81
|
protected void updateContent() {
|
82
|
super.updateContent();
|
83
|
|
84
|
// disable nomenclatural code, because changing of nom.code is not implemented on library side
|
85
|
combo_nomenclaturalCode.setEnabled(false);
|
86
|
|
87
|
setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
|
88
|
}
|
89
|
|
90
|
/** {@inheritDoc} */
|
91
|
@Override
|
92
|
public void setEntity(NonViralName entity) {
|
93
|
super.setEntity(entity);
|
94
|
section_name.setEntity(entity);
|
95
|
section_author.setEntity(entity);
|
96
|
}
|
97
|
|
98
|
/** {@inheritDoc} */
|
99
|
@Override
|
100
|
public void removeElements() {
|
101
|
super.removeElements();
|
102
|
if(section_name != null){
|
103
|
section_name.removeElements();
|
104
|
removeControl(section_name);
|
105
|
section_name.dispose();
|
106
|
section_name = null;
|
107
|
}
|
108
|
if(section_author != null){
|
109
|
section_author.removeElements();
|
110
|
removeControl(section_author);
|
111
|
section_author.dispose();
|
112
|
section_author = null;
|
113
|
}
|
114
|
}
|
115
|
|
116
|
/* (non-Javadoc)
|
117
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
|
118
|
*/
|
119
|
/** {@inheritDoc} */
|
120
|
@Override
|
121
|
public void handleEvent(Object eventSource) {
|
122
|
if(eventSource == toggleable_cache){
|
123
|
getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
|
124
|
// we never want the fullTitleCache to be protected since we only use it for
|
125
|
// initiating the free text name editor
|
126
|
getEntity().setProtectedFullTitleCache(false);
|
127
|
boolean irrelevant = toggleable_cache.getState();
|
128
|
List<Object> except = Arrays.asList(new Object[]{toggleable_cache});
|
129
|
setIrrelevant(irrelevant, except);
|
130
|
}
|
131
|
else if(eventSource == section_name || eventSource == section_author){
|
132
|
if(getParentElement() instanceof AbstractCdmDetailSection)
|
133
|
((AbstractCdmDetailSection) getParentElement()).updateTitle();
|
134
|
if(! toggleable_cache.getState()){
|
135
|
toggleable_cache.setText(getEntity().getTitleCache());
|
136
|
}
|
137
|
}
|
138
|
}
|
139
|
}
|