simple name details: evaluation of author settings should be done only in authorship...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NonViralNameDetailElement.java
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.name;
11
12 import java.util.Arrays;
13
14 import org.eclipse.ui.forms.widgets.ExpandableComposite;
15
16 import eu.etaxonomy.cdm.model.name.IBacterialName;
17 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18 import eu.etaxonomy.cdm.model.name.TaxonName;
19 import eu.etaxonomy.taxeditor.l10n.Messages;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
22 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
24 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
27 import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
28 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
29 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
30 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
31
32 /**
33 * @author n.hoffmann
34 * @created May 20, 2010
35 */
36 public class NonViralNameDetailElement
37 extends AbstractIdentifiableEntityDetailElement<TaxonName> {
38
39 private NameDetailSection section_name;
40 private AuthorshipDetailSection section_author;
41 private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
42 private HybridDetailSection section_hybrid;
43 private LsidWithExceptionLabelElement textLsid;
44 private TextWithLabelElement text_nameApprobation;
45
46
47 public NonViralNameDetailElement(CdmFormFactory formFactory,
48 ICdmFormElement formElement) {
49 super(formFactory, formElement);
50 initIsAdvancedDetailsView();
51
52 }
53
54 /** {@inheritDoc} */
55 @Override
56 protected void createControls(ICdmFormElement formElement, final TaxonName entity, int style) {
57
58
59 if (isAdvancedView){
60 toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
61
62 combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
63 combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
64 if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
65 text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
66 }
67 textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
68
69
70 }else{
71 if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE)){
72 toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
73
74 }
75 if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE)){
76 combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
77 combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
78 }
79 if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
80 if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION)){
81 text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
82 }
83 }
84
85 if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
86 textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
87
88 }
89
90
91 }
92
93
94 section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
95 section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
96 addControl(section_name);
97 addElement(section_name);
98 // if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
99 section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
100 section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
101 addControl(section_author);
102 addElement(section_author);
103 // }
104 //TODO RL
105 if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
106 section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
107 section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
108 addControl(section_hybrid);
109 addElement(section_hybrid);
110
111 }
112
113
114 }
115
116 /** {@inheritDoc} */
117 @Override
118 protected void updateContent() {
119 super.updateContent();
120 // disable nomenclatural code, because changing of nom.code is not
121 // implemented on library side
122 // if(combo_nomenclaturalCode!=null){
123 // combo_nomenclaturalCode.setEnabled(false);
124 // }
125
126 if(toggleable_cache!=null){
127 toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
128 setIrrelevant(toggleable_cache.getState(),
129 Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
130 }
131 }
132
133 /** {@inheritDoc} */
134 @Override
135 public void setEntity(TaxonName entity) {
136 super.setEntity(entity);
137 if (section_name!=null) {
138 section_name.setEntity(entity);
139 }
140 if (section_author!=null) {
141 section_author.setEntity(entity);
142 }
143 if (section_hybrid!=null) {
144 section_hybrid.setEntity(entity);
145 }
146 }
147
148 /** {@inheritDoc} */
149 @Override
150 public void removeElements() {
151 super.removeElements();
152 if (section_name != null) {
153 section_name.removeElements();
154 removeControl(section_name);
155 section_name.dispose();
156 section_name = null;
157 }
158 if (section_author != null) {
159 section_author.removeElements();
160 removeControl(section_author);
161 section_author.dispose();
162 section_author = null;
163 }
164 }
165
166 /** {@inheritDoc} */
167 @Override
168 public void handleEvent(Object eventSource) {
169 if (eventSource == toggleable_cache) {
170 handleToggleableCacheField();
171 // we never want the fullTitleCache to be protected since we only
172 // use it for
173 // initiating the free text name editor
174 getEntity().setProtectedFullTitleCache(false);
175 } else if (eventSource == section_name || eventSource == section_author) {
176 if (getParentElement() instanceof AbstractCdmDetailSection) {
177 ((AbstractCdmDetailSection) getParentElement()).updateTitle();
178 }
179 if (toggleable_cache != null){
180 if (!toggleable_cache.getState()) {
181 toggleable_cache.setText(getEntity().getTitleCache());
182 }
183 }
184 } else if (eventSource == section_name) {
185 section_name.setEntity(getEntity());
186 getLayoutComposite().layout();
187 } else if(eventSource==textLsid){
188 getEntity().setLsid(textLsid.parseText());
189 } else if (eventSource == combo_nomenclaturalCode){
190 boolean change = checkForDeletableParts(combo_nomenclaturalCode.getSelection());
191 if (change){
192 getEntity().setNameType(combo_nomenclaturalCode.getSelection());
193
194 this.updateContent();
195 section_hybrid.setEntity(getEntity());
196 section_author.setEntity(getEntity());
197 section_name.setEntity(getEntity());
198 }else{
199 combo_nomenclaturalCode.setSelection(getEntity().getNameType());
200 }
201 } else if(eventSource == this.text_nameApprobation){
202 ((IBacterialName)getEntity()).setNameApprobation(text_nameApprobation.getText());
203 }
204 }
205 private boolean checkForDeletableParts(NomenclaturalCode selection) {
206 NomenclaturalCode actualCode = getEntity().getNameType();
207 if (selection.equals(actualCode)){
208 return true;
209 }
210 if (actualCode.equals(NomenclaturalCode.ICZN) ){
211 if(getEntity().getOriginalPublicationYear() != null || getEntity().getPublicationYear() != null || getEntity().getBreed() != null){
212 if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfZoologicalNameParts, Messages.NonViralNameDetails_descriptionDeleteZoologicalNameParts)){
213 getEntity().setOriginalPublicationYear(null);
214 getEntity().setPublicationYear(null);
215 getEntity().setBreed(null);
216 return true;
217 }
218 }else {
219 return true;
220 }
221
222 }
223 if (actualCode.equals(NomenclaturalCode.ICNB)){
224 if (getEntity().getNameApprobation() != null || getEntity().getSubGenusAuthorship() != null){
225 if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfBacterialNameParts, Messages.NonViralNameDetails_desciptionDeleteOfBacterialNameParts)){
226 getEntity().setNameApprobation(null);
227 getEntity().setSubGenusAuthorship(null);
228 return true;
229 }
230 }else{
231 return true;
232 }
233
234 }
235 if (actualCode.equals(NomenclaturalCode.Fungi)){
236 if (getEntity().isAnamorphic() ){
237 if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfFungiNameParts, Messages.NonViralNameDetails_descriptionDeleteOfFungiNameParts)){
238 getEntity().setAnamorphic(false);
239 return true;
240 }
241 }else{
242 return true;
243 }
244 }
245 if (actualCode.equals(NomenclaturalCode.ICNCP)){
246 if (getEntity().getCultivarName() != null){
247 if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfCultivarNameParts, Messages.NonViralNameDetails_descriptionDeleteOfCultivarNameParts)){
248 getEntity().setCultivarName(null);
249 return true;
250 }
251 }else{
252 return true;
253 }
254
255 }
256 if (actualCode.equals(NomenclaturalCode.ICNAFP)){
257 return true;
258 }
259 return false;
260 }
261
262 @Override
263 protected void handleToggleableCacheField() {
264 boolean pushedState = toggleable_cache.getState();
265
266 getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
267 setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
268 updateToggleableCacheField();
269 }
270
271
272
273
274 // @Override
275 // public void toggleAdvancedMediaView(){
276 // mediaDetailElement.toggleAdvancedMediaView();
277 // }
278 }