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.ui.section.name;
|
12
|
|
13
|
import java.util.Arrays;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
16
|
import eu.etaxonomy.taxeditor.model.AuthorHelper;
|
17
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
18
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
|
24
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
|
27
|
/**
|
28
|
* <p>
|
29
|
* AuthorshipDetailElement class.
|
30
|
* </p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Mar 4, 2010
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class AuthorshipDetailElement extends
|
37
|
AbstractIdentifiableEntityDetailElement<NonViralName> implements
|
38
|
IEnableableFormElement {
|
39
|
|
40
|
private NomenclaturalAuthorTeamSelectionElement selection_exBasionymAuthorTeam;
|
41
|
private NomenclaturalAuthorTeamSelectionElement selection_basionymAuthorTeam;
|
42
|
private NomenclaturalAuthorTeamSelectionElement selection_exCombinationAuthorTeam;
|
43
|
private NomenclaturalAuthorTeamSelectionElement selection_combinationAuthorTeam;
|
44
|
|
45
|
/**
|
46
|
* <p>
|
47
|
* Constructor for AuthorshipDetailElement.
|
48
|
* </p>
|
49
|
*
|
50
|
* @param cdmFormFactory
|
51
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
52
|
* object.
|
53
|
* @param formElement
|
54
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
55
|
* object.
|
56
|
* @param style
|
57
|
* a int.
|
58
|
*/
|
59
|
public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
|
60
|
ICdmFormElement formElement, int style) {
|
61
|
super(cdmFormFactory, formElement);
|
62
|
}
|
63
|
|
64
|
/** {@inheritDoc} */
|
65
|
@Override
|
66
|
protected void createControls(ICdmFormElement formElement,
|
67
|
NonViralName entity, int style) {
|
68
|
toggleable_cache = formFactory.createToggleableTextField(this,
|
69
|
"Authorship Cache", entity.getAuthorshipCache(),
|
70
|
entity.isProtectedAuthorshipCache(), style);
|
71
|
|
72
|
//TODO RL
|
73
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
74
|
toggleable_cache.setVisible(false);
|
75
|
}
|
76
|
selection_combinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
|
77
|
getConversationHolder(),
|
78
|
formElement, "Author",
|
79
|
AuthorHelper.getAuthor(entity.getCombinationAuthorTeam()),
|
80
|
EntitySelectionElement.ALL, style);
|
81
|
addElement(selection_combinationAuthorTeam);
|
82
|
selection_exCombinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
|
83
|
getConversationHolder(),
|
84
|
formElement, "Ex Author",
|
85
|
AuthorHelper.getAuthor(entity.getExCombinationAuthorTeam()),
|
86
|
EntitySelectionElement.ALL, style);
|
87
|
addElement(selection_exCombinationAuthorTeam);
|
88
|
selection_basionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
|
89
|
getConversationHolder(),
|
90
|
formElement, "Basionym Author",
|
91
|
AuthorHelper.getAuthor(entity.getBasionymAuthorTeam()),
|
92
|
EntitySelectionElement.ALL, style);
|
93
|
addElement(selection_basionymAuthorTeam);
|
94
|
selection_exBasionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
|
95
|
getConversationHolder(),
|
96
|
formElement, "Ex Basionym Author",
|
97
|
AuthorHelper.getAuthor(entity.getExBasionymAuthorTeam()),
|
98
|
EntitySelectionElement.ALL, style);
|
99
|
addElement(selection_exBasionymAuthorTeam);
|
100
|
}
|
101
|
|
102
|
/** {@inheritDoc} */
|
103
|
@Override
|
104
|
public void updateContent() {
|
105
|
if (getEntity() == null) {
|
106
|
setEntity(NonViralName.NewInstance(null));
|
107
|
}
|
108
|
|
109
|
super.updateContent();
|
110
|
toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
|
111
|
|
112
|
if (this.isIrrelevant()) {
|
113
|
setIrrelevant(isIrrelevant());
|
114
|
} else {
|
115
|
setIrrelevant(toggleable_cache.getState(),
|
116
|
Arrays.asList(new Object[] { toggleable_cache }));
|
117
|
}
|
118
|
}
|
119
|
|
120
|
/** {@inheritDoc} */
|
121
|
@Override
|
122
|
public void handleEvent(Object eventSource) {
|
123
|
if (eventSource == toggleable_cache) {
|
124
|
getEntity().setAuthorshipCache(toggleable_cache.getText(),
|
125
|
toggleable_cache.getState());
|
126
|
if (!isIrrelevant()){
|
127
|
setIrrelevant(toggleable_cache.getState(),
|
128
|
Arrays.asList(new Object[] { toggleable_cache }));
|
129
|
}
|
130
|
} else if (eventSource == selection_combinationAuthorTeam) {
|
131
|
getEntity().setCombinationAuthorTeam(
|
132
|
selection_combinationAuthorTeam.getSelection());
|
133
|
} else if (eventSource == selection_exCombinationAuthorTeam) {
|
134
|
getEntity().setExCombinationAuthorTeam(
|
135
|
selection_exCombinationAuthorTeam.getSelection());
|
136
|
} else if (eventSource == selection_basionymAuthorTeam) {
|
137
|
getEntity().setBasionymAuthorTeam(
|
138
|
selection_basionymAuthorTeam.getSelection());
|
139
|
} else if (eventSource == selection_exBasionymAuthorTeam) {
|
140
|
getEntity().setExBasionymAuthorTeam(
|
141
|
selection_exBasionymAuthorTeam.getSelection());
|
142
|
}
|
143
|
|
144
|
// if (eventSource != toggleable_cache) {
|
145
|
// toggleable_cache.setText(getEntity().getAuthorshipCache());
|
146
|
// }
|
147
|
|
148
|
// we have to notify the parent if this is embedded in the nonviral name
|
149
|
// section
|
150
|
// maybe we can handle this a little bit more elegant
|
151
|
// if (getParentElement() instanceof AbstractCdmDetailSection)
|
152
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(
|
153
|
getParentElement(), null));
|
154
|
}
|
155
|
|
156
|
@Override
|
157
|
public void updateToggleableCacheField() {
|
158
|
if(! getEntity().isProtectedAuthorshipCache()){
|
159
|
toggleable_cache.setText(getEntity().getAuthorshipCache());
|
160
|
}
|
161
|
}
|
162
|
}
|