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 * @created May 20, 2010
33 public class NonViralNameDetailElement
extends
34 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
36 private NameDetailSection section_name
;
37 private AuthorshipDetailSection section_author
;
38 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
39 private HybridDetailSection section_hybrid
;
41 public NonViralNameDetailElement(CdmFormFactory formFactory
,
42 ICdmFormElement formElement
) {
43 super(formFactory
, formElement
);
48 protected void createControls(ICdmFormElement formElement
, final NonViralName entity
, int style
) {
49 //name can be null in rare cases. Temporary solution for #4221. May be obsolete when
50 //#4393 (Make changing name of a taxon possible in details view) is implemented.
52 formFactory
.createEmptyElement(formElement
, "No name associated with this taxon.");
55 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
57 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
58 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
61 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
62 toggleable_cache
.setVisible(false);
63 combo_nomenclaturalCode
.setVisible(false);
66 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
67 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
68 addControl(section_name
);
69 addElement(section_name
);
70 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
71 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
72 addControl(section_author
);
73 addElement(section_author
);
76 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
77 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
78 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
79 addControl(section_hybrid
);
80 addElement(section_hybrid
);
87 protected void updateContent() {
88 super.updateContent();
90 // disable nomenclatural code, because changing of nom.code is not
91 // implemented on library side
92 if(combo_nomenclaturalCode
!=null){
93 combo_nomenclaturalCode
.setEnabled(false);
96 if(toggleable_cache
!=null){
97 setIrrelevant(toggleable_cache
.getState(),
98 Arrays
.asList(new Object
[] { toggleable_cache
}));
104 public void setEntity(NonViralName entity
) {
105 super.setEntity(entity
);
106 if (section_name
!=null) {
107 section_name
.setEntity(entity
);
109 if (section_author
!=null) {
110 section_author
.setEntity(entity
);
112 if (section_hybrid
!=null) {
113 section_hybrid
.setEntity(entity
);
119 public void removeElements() {
120 super.removeElements();
121 if (section_name
!= null) {
122 section_name
.removeElements();
123 removeControl(section_name
);
124 section_name
.dispose();
127 if (section_author
!= null) {
128 section_author
.removeElements();
129 removeControl(section_author
);
130 section_author
.dispose();
131 section_author
= null;
137 public void handleEvent(Object eventSource
) {
138 if (eventSource
== toggleable_cache
) {
139 handleToggleableCacheField();
140 // we never want the fullTitleCache to be protected since we only
142 // initiating the free text name editor
143 getEntity().setProtectedFullTitleCache(false);
144 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
145 if (getParentElement() instanceof AbstractCdmDetailSection
) {
146 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
148 if (!toggleable_cache
.getState()) {
149 toggleable_cache
.setText(getEntity().getTitleCache());
152 if (eventSource
== section_name
) {
153 section_name
.setEntity(getEntity());
154 getLayoutComposite().layout();