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.taxon;
|
12
|
|
13
|
import java.util.Arrays;
|
14
|
|
15
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16
|
import org.eclipse.swt.SWT;
|
17
|
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
23
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
24
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.name.SynonymRelationshipDetailSection;
|
34
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
35
|
|
36
|
/**
|
37
|
* <p>
|
38
|
* TaxonBaseDetailElement class.
|
39
|
* </p>
|
40
|
*
|
41
|
* @author n.hoffmann
|
42
|
* @created Feb 26, 2010
|
43
|
* @version 1.0
|
44
|
*/
|
45
|
public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase> {
|
46
|
|
47
|
private CheckboxElement checkbox_doubtful;
|
48
|
|
49
|
private CheckboxElement checkbox_useNameCache;
|
50
|
|
51
|
private EntitySelectionElement<Reference> selection_secundum;
|
52
|
|
53
|
private TextWithLabelElement text_appendedPhrase;
|
54
|
|
55
|
private CheckboxElement checkbox_excluded;
|
56
|
|
57
|
private CheckboxElement checkbox_unplaced;
|
58
|
|
59
|
private CheckboxElement checkbox_published;
|
60
|
|
61
|
private SynonymRelationshipDetailSection sectionSynonymRelationship;
|
62
|
|
63
|
/**
|
64
|
* <p>
|
65
|
* Constructor for TaxonBaseDetailElement.
|
66
|
* </p>
|
67
|
*
|
68
|
* @param cdmFormFactory
|
69
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
70
|
* @param formElement
|
71
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
72
|
* @param style
|
73
|
* a int.
|
74
|
*/
|
75
|
public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
|
76
|
ICdmFormElement formElement, int style) {
|
77
|
super(cdmFormFactory, formElement);
|
78
|
}
|
79
|
|
80
|
/** {@inheritDoc} */
|
81
|
@Override
|
82
|
protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
|
83
|
toggleable_cache = formFactory.createToggleableTextField(formElement,
|
84
|
"Title Cache", entity.getTitleCache(),
|
85
|
entity.isProtectedTitleCache(), style);
|
86
|
|
87
|
//TODO RL
|
88
|
boolean rl=true;
|
89
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
90
|
toggleable_cache.setVisible(false);
|
91
|
}
|
92
|
if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
93
|
text_appendedPhrase = formFactory.createTextWithLabelElement(
|
94
|
formElement, "Appended Phrase", entity.getAppendedPhrase(),
|
95
|
SWT.NULL);
|
96
|
}
|
97
|
|
98
|
selection_secundum = formFactory.createSelectionElement(Reference.class,
|
99
|
getConversationHolder(), formElement, "Secundum",
|
100
|
entity.getSec(), EntitySelectionElement.ALL,
|
101
|
style);
|
102
|
|
103
|
// TODO RL
|
104
|
if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)) {
|
105
|
checkbox_useNameCache = formFactory.createCheckbox(formElement,
|
106
|
"Exclude Authorship", entity.isUseNameCache(), style);
|
107
|
|
108
|
if (entity instanceof Taxon) {
|
109
|
checkbox_excluded = formFactory.createCheckbox(formElement,
|
110
|
"Taxon is excluded", ((Taxon) entity).isExcluded(), style);
|
111
|
checkbox_unplaced = formFactory.createCheckbox(formElement,
|
112
|
"Taxon is unplaced", ((Taxon) entity).isUnplaced(), style);
|
113
|
}
|
114
|
|
115
|
checkbox_doubtful = formFactory.createCheckbox(formElement,
|
116
|
entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
|
117
|
}
|
118
|
|
119
|
if (entity instanceof Taxon) {
|
120
|
checkbox_published = formFactory.createCheckbox(formElement,
|
121
|
"Taxon is published", ((Taxon) entity).isPublish(), style);
|
122
|
}
|
123
|
|
124
|
|
125
|
if(entity instanceof Synonym){
|
126
|
sectionSynonymRelationship = formFactory.createSynonymRelationshipDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
|
127
|
sectionSynonymRelationship.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
128
|
sectionSynonymRelationship.setEntity((Synonym) entity);
|
129
|
}
|
130
|
}
|
131
|
|
132
|
private void updateCheckboxPublish() {
|
133
|
if(getEntity() instanceof Taxon){
|
134
|
checkbox_published.setEnabled(
|
135
|
CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
|
136
|
);
|
137
|
}
|
138
|
}
|
139
|
|
140
|
@Override
|
141
|
protected void updateControlStates() {
|
142
|
super.updateControlStates();
|
143
|
updateCheckboxPublish();
|
144
|
}
|
145
|
|
146
|
/** {@inheritDoc} */
|
147
|
@Override
|
148
|
protected void updateContent() {
|
149
|
super.updateContent();
|
150
|
toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
|
151
|
setIrrelevant(toggleable_cache.getState(),
|
152
|
Arrays.asList(new Object[] { toggleable_cache }));
|
153
|
}
|
154
|
|
155
|
@Override
|
156
|
protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
|
157
|
String title = getEntity().generateTitle();
|
158
|
getEntity().setTitleCache(title);
|
159
|
super.handleTitleCacheRelevantChange(event);
|
160
|
}
|
161
|
|
162
|
/** {@inheritDoc} */
|
163
|
@Override
|
164
|
public void handleEvent(Object eventSource) {
|
165
|
if (eventSource== toggleable_cache) {
|
166
|
handleToggleableCacheField();
|
167
|
} else if (eventSource == checkbox_doubtful) {
|
168
|
getEntity().setDoubtful(checkbox_doubtful.getSelection());
|
169
|
} else if (eventSource == checkbox_useNameCache) {
|
170
|
getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
|
171
|
} else if (eventSource == selection_secundum) {
|
172
|
getEntity().setSec(selection_secundum.getSelection());
|
173
|
} else if (eventSource == text_appendedPhrase) {
|
174
|
getEntity().setAppendedPhrase(text_appendedPhrase.getText());
|
175
|
} else if (eventSource == checkbox_excluded) {
|
176
|
((Taxon) getEntity()).setExcluded(checkbox_excluded.getSelection());
|
177
|
} else if (eventSource == checkbox_unplaced) {
|
178
|
((Taxon) getEntity()).setUnplaced(checkbox_unplaced.getSelection());
|
179
|
} else if (eventSource == checkbox_published) {
|
180
|
((Taxon)getEntity()).setPublish(checkbox_published.getSelection());
|
181
|
}
|
182
|
}
|
183
|
}
|