3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
13 import java
.util
.Arrays
;
15 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
18 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
19 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
20 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
21 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
30 * NonViralNameDetailElement class.
34 * @created May 20, 2010
37 public class NonViralNameDetailElement
extends
38 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
40 private NameDetailSection section_name
;
41 private AuthorshipDetailSection section_author
;
42 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
43 private HybridDetailSection section_hybrid
;
47 * Constructor for NonViralNameDetailElement.
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
57 public NonViralNameDetailElement(CdmFormFactory formFactory
,
58 ICdmFormElement formElement
) {
59 super(formFactory
, formElement
);
66 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
67 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
68 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
72 protected void createControls(ICdmFormElement formElement
, final NonViralName entity
, int style
) {
73 //name can be null in rare cases. Temporary solution for #4221. May be obsolete when
74 //#4393 (Make changing name of a taxon possible in details view) is implemented.
76 formFactory
.createEmptyElement(formElement
, "No name associated with this taxon.");
79 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
81 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
82 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
85 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
86 toggleable_cache
.setVisible(false);
87 combo_nomenclaturalCode
.setVisible(false);
90 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
91 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
92 addControl(section_name
);
93 addElement(section_name
);
94 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
95 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
96 addControl(section_author
);
97 addElement(section_author
);
100 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
101 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
102 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
103 addControl(section_hybrid
);
104 addElement(section_hybrid
);
111 protected void updateContent() {
112 super.updateContent();
114 // disable nomenclatural code, because changing of nom.code is not
115 // implemented on library side
116 if(combo_nomenclaturalCode
!=null){
117 combo_nomenclaturalCode
.setEnabled(false);
120 if(toggleable_cache
!=null){
121 setIrrelevant(toggleable_cache
.getState(),
122 Arrays
.asList(new Object
[] { toggleable_cache
}));
128 public void setEntity(NonViralName entity
) {
129 super.setEntity(entity
);
130 if (section_name
!=null) {
131 section_name
.setEntity(entity
);
133 if (section_author
!=null) {
134 section_author
.setEntity(entity
);
136 if (section_hybrid
!=null) {
137 section_hybrid
.setEntity(entity
);
143 public void removeElements() {
144 super.removeElements();
145 if (section_name
!= null) {
146 section_name
.removeElements();
147 removeControl(section_name
);
148 section_name
.dispose();
151 if (section_author
!= null) {
152 section_author
.removeElements();
153 removeControl(section_author
);
154 section_author
.dispose();
155 section_author
= null;
163 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
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
.getState()) {
180 toggleable_cache
.setText(getEntity().getTitleCache());
183 if (eventSource
== section_name
) {
184 section_name
.setEntity(getEntity());
185 getLayoutComposite().layout();