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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
11 import eu
.etaxonomy
.cdm
.model
.name
.IBacterialName
;
12 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
13 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
14 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
15 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
16 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
17 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
18 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
19 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.LsidWithExceptionLabelElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
30 * @created May 20, 2010
32 public class NonViralNameDetailElement
33 extends AbstractIdentifiableEntityDetailElement
<TaxonName
> {
35 private NameDetailSection section_name
;
36 private AuthorshipDetailSection section_author
;
37 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
38 private HybridDetailSection section_hybrid
;
39 private LsidWithExceptionLabelElement textLsid
;
40 private TextWithLabelElement text_nameApprobation
;
42 public NonViralNameDetailElement(CdmFormFactory formFactory
,
43 ICdmFormElement formElement
) {
44 super(formFactory
, formElement
);
48 protected void createControls(ICdmFormElement formElement
, final TaxonName entity
, int style
) {
49 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
52 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
54 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
, true);
55 combo_nomenclaturalCode
.setSelection(entity
.getNameType());
56 if (entity
.getNameType().equals(NomenclaturalCode
.ICNP
)){
57 text_nameApprobation
= formFactory
.createTextWithLabelElement(formElement
, "Name Approbation", entity
.getNameApprobation(),style
);
59 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
61 if (config
.isNameCacheActivated()){
62 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
64 if (config
.isNomenclaturalCodeActived()){
65 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
66 combo_nomenclaturalCode
.setSelection(entity
.getNameType());
68 if (entity
.getNameType().equals(NomenclaturalCode
.ICNP
)){
69 if (config
.isNameApprobiationActivated()){
70 text_nameApprobation
= formFactory
.createTextWithLabelElement(formElement
, "Name Approbation", entity
.getNameApprobation(),style
);
73 if (config
.isLSIDActivated()){
74 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
78 section_name
= formFactory
.createNameDetailSection(formElement
, null, StoreUtil
.getSectionStyle(NameDetailSection
.class, entity
.getClass().getCanonicalName(), true));
79 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
80 addControl(section_name
);
81 addElement(section_name
);
82 // if (isAdvancedView || PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
83 section_author
= formFactory
.createAuthorshipDetailSection(formElement
, null, StoreUtil
.getSectionStyle(AuthorshipDetailSection
.class, entity
.getClass().getCanonicalName(), true));
84 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
85 addControl(section_author
);
86 addElement(section_author
);
89 if (config
== null || config
.isHybridActivated()){
90 section_hybrid
= formFactory
.createHybridDetailSection(formElement
, null, StoreUtil
.getSectionStyle(HybridDetailSection
.class, entity
.getClass().getCanonicalName()));
91 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
92 addControl(section_hybrid
);
93 addElement(section_hybrid
);
97 registerCacheRelevance(section_name
);
98 registerCacheRelevance(section_author
);
99 registerCacheRelevance(combo_nomenclaturalCode
);
100 registerCacheRelevance(section_hybrid
);
104 protected void updateContent() {
105 super.updateContent();
107 if(toggleable_cache
!= null){
108 toggleable_cache
.setCacheEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
109 updateCacheRelevance();
114 public void setEntity(TaxonName entity
) {
115 super.setEntity(entity
);
116 if (section_name
!=null) {
117 section_name
.setEntity(entity
);
119 if (section_author
!=null) {
120 section_author
.setEntity(entity
);
122 if (section_hybrid
!=null) {
123 section_hybrid
.setEntity(entity
);
128 public void removeElements() {
129 super.removeElements();
130 if (section_name
!= null) {
131 section_name
.removeElements();
132 removeControl(section_name
);
133 section_name
.dispose();
136 if (section_author
!= null) {
137 section_author
.removeElements();
138 removeControl(section_author
);
139 section_author
.dispose();
140 section_author
= null;
145 public void handleEvent(Object eventSource
) {
146 if (eventSource
== toggleable_cache
) {
147 handleToggleableCacheField();
148 // we never want the fullTitleCache to be protected since we only
150 // initiating the free text name editor
151 getEntity().setProtectedFullTitleCache(false);
152 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
153 if (getParentElement() instanceof AbstractCdmDetailSection
) {
154 ((AbstractCdmDetailSection
<?
>) getParentElement()).updateTitle();
156 if (toggleable_cache
!= null){
157 if (!toggleable_cache
.getState()) {
158 toggleable_cache
.setText(getEntity().getTitleCache());
161 } else if (eventSource
== section_name
) {
162 section_name
.setEntity(getEntity());
163 getLayoutComposite().layout();
164 } else if(eventSource
==textLsid
){
165 getEntity().setLsid(textLsid
.parseText());
166 } else if (eventSource
== combo_nomenclaturalCode
){
167 boolean change
= checkForDeletableParts(combo_nomenclaturalCode
.getSelection());
169 getEntity().setNameType(combo_nomenclaturalCode
.getSelection());
171 this.updateContent();
172 //this is needed for the "new" wizards in order to redraw correctly
173 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
174 if (section_hybrid
!= null){
175 section_hybrid
.setEntity(getEntity());
177 if (section_author
!= null){
178 section_author
.setEntity(getEntity());
180 if (section_name
!= null){
181 section_name
.setEntity(getEntity());
184 combo_nomenclaturalCode
.setSelection(getEntity().getNameType());
186 } else if(eventSource
== this.text_nameApprobation
){
187 ((IBacterialName
)getEntity()).setNameApprobation(text_nameApprobation
.getText());
191 private boolean checkForDeletableParts(NomenclaturalCode selection
) {
192 NomenclaturalCode actualCode
= getEntity().getNameType();
193 if (selection
.equals(actualCode
)){
196 if (actualCode
.equals(NomenclaturalCode
.ICZN
) ){
197 if(getEntity().getOriginalPublicationYear() != null || getEntity().getPublicationYear() != null || getEntity().getBreed() != null){
198 if (MessagingUtils
.confirmDialog(Messages
.NonViralNameDetails_confirmDeleteOfZoologicalNameParts
, Messages
.NonViralNameDetails_descriptionDeleteZoologicalNameParts
)){
199 getEntity().setOriginalPublicationYear(null);
200 getEntity().setPublicationYear(null);
201 getEntity().setBreed(null);
208 if (actualCode
.equals(NomenclaturalCode
.ICNP
)){
209 if (getEntity().getNameApprobation() != null || getEntity().getSubGenusAuthorship() != null){
210 if (MessagingUtils
.confirmDialog(Messages
.NonViralNameDetails_confirmDeleteOfBacterialNameParts
, Messages
.NonViralNameDetails_desciptionDeleteOfBacterialNameParts
)){
211 getEntity().setNameApprobation(null);
212 getEntity().setSubGenusAuthorship(null);
219 if (actualCode
.equals(NomenclaturalCode
.NonViral
)){
222 if (actualCode
.equals(NomenclaturalCode
.Fungi
)){
223 if (getEntity().isAnamorphic() ){
224 if (MessagingUtils
.confirmDialog(Messages
.NonViralNameDetails_confirmDeleteOfFungiNameParts
, Messages
.NonViralNameDetails_descriptionDeleteOfFungiNameParts
)){
225 getEntity().setAnamorphic(false);
232 if (actualCode
.equals(NomenclaturalCode
.ICNCP
)){
233 if (getEntity().getCultivarEpithet() != null || getEntity().getCultivarGroupEpithet() != null){
234 if (MessagingUtils
.confirmDialog(Messages
.NonViralNameDetails_confirmDeleteOfCultivarNameParts
, Messages
.NonViralNameDetails_descriptionDeleteOfCultivarNameParts
)){
235 getEntity().setCultivarEpithet(null);
236 getEntity().setCultivarGroupEpithet(null);
243 if (actualCode
.equals(NomenclaturalCode
.ICNAFP
)){
250 protected void handleToggleableCacheField() {
251 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
252 updateCacheRelevance();
253 updateToggleableCacheField();
257 public void fillFields() {
260 section_name
.getDetailElement().fillFields();;
261 section_author
.getDetailElement().fillFields();
262 combo_nomenclaturalCode
.setSelection(getEntity().getNameType());
263 section_hybrid
.getDetailElement().fillFields();
264 textLsid
.setText(getEntity().getLsid()!= null?
getEntity().getLsid().toString():null);
265 if (text_nameApprobation
!= null) {
266 text_nameApprobation
.setText(getEntity().getNameApprobation());