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