2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Arrays
;
14 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
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
;
34 * @created May 20, 2010
36 public class NonViralNameDetailElement
37 extends AbstractIdentifiableEntityDetailElement
<TaxonName
> {
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
;
47 public NonViralNameDetailElement(CdmFormFactory formFactory
,
48 ICdmFormElement formElement
) {
49 super(formFactory
, formElement
);
50 initIsAdvancedDetailsView();
56 protected void createControls(ICdmFormElement formElement
, final TaxonName entity
, int style
) {
60 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
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
);
67 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
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
);
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());
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
);
85 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_LSID
)){
86 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
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
);
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
);
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);
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
}));
135 public void setEntity(TaxonName entity
) {
136 super.setEntity(entity
);
137 if (section_name
!=null) {
138 section_name
.setEntity(entity
);
140 if (section_author
!=null) {
141 section_author
.setEntity(entity
);
143 if (section_hybrid
!=null) {
144 section_hybrid
.setEntity(entity
);
150 public void removeElements() {
151 super.removeElements();
152 if (section_name
!= null) {
153 section_name
.removeElements();
154 removeControl(section_name
);
155 section_name
.dispose();
158 if (section_author
!= null) {
159 section_author
.removeElements();
160 removeControl(section_author
);
161 section_author
.dispose();
162 section_author
= null;
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
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();
179 if (toggleable_cache
!= null){
180 if (!toggleable_cache
.getState()) {
181 toggleable_cache
.setText(getEntity().getTitleCache());
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());
192 getEntity().setNameType(combo_nomenclaturalCode
.getSelection());
194 this.updateContent();
195 section_hybrid
.setEntity(getEntity());
196 section_author
.setEntity(getEntity());
197 section_name
.setEntity(getEntity());
199 combo_nomenclaturalCode
.setSelection(getEntity().getNameType());
201 } else if(eventSource
== this.text_nameApprobation
){
202 ((IBacterialName
)getEntity()).setNameApprobation(text_nameApprobation
.getText());
205 private boolean checkForDeletableParts(NomenclaturalCode selection
) {
206 NomenclaturalCode actualCode
= getEntity().getNameType();
207 if (selection
.equals(actualCode
)){
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);
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);
235 if (actualCode
.equals(NomenclaturalCode
.Fungi
)){
236 if (getEntity().isAnamorphic() ){
237 if (MessagingUtils
.confirmDialog(Messages
.NonViralNameDetails_confirmDeleteOfFungiNameParts
, Messages
.NonViralNameDetails_descriptionDeleteOfFungiNameParts
)){
238 getEntity().setAnamorphic(false);
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);
256 if (actualCode
.equals(NomenclaturalCode
.ICNAFP
)){
263 protected void handleToggleableCacheField() {
264 boolean pushedState
= toggleable_cache
.getState();
266 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
267 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, textLsid
, text_nameApprobation
}));
268 updateToggleableCacheField();
275 // public void toggleAdvancedMediaView(){
276 // mediaDetailElement.toggleAdvancedMediaView();