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 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
51 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
52 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
55 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
56 toggleable_cache
.setVisible(false);
57 combo_nomenclaturalCode
.setVisible(false);
60 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
61 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
62 addControl(section_name
);
63 addElement(section_name
);
64 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
65 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
66 addControl(section_author
);
67 addElement(section_author
);
70 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
71 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
72 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
73 addControl(section_hybrid
);
74 addElement(section_hybrid
);
80 protected void updateContent() {
81 super.updateContent();
83 // disable nomenclatural code, because changing of nom.code is not
84 // implemented on library side
85 if(combo_nomenclaturalCode
!=null){
86 combo_nomenclaturalCode
.setEnabled(false);
89 if(toggleable_cache
!=null){
90 setIrrelevant(toggleable_cache
.getState(),
91 Arrays
.asList(new Object
[] { toggleable_cache
}));
97 public void setEntity(NonViralName entity
) {
98 super.setEntity(entity
);
99 if (section_name
!=null) {
100 section_name
.setEntity(entity
);
102 if (section_author
!=null) {
103 section_author
.setEntity(entity
);
105 if (section_hybrid
!=null) {
106 section_hybrid
.setEntity(entity
);
112 public void removeElements() {
113 super.removeElements();
114 if (section_name
!= null) {
115 section_name
.removeElements();
116 removeControl(section_name
);
117 section_name
.dispose();
120 if (section_author
!= null) {
121 section_author
.removeElements();
122 removeControl(section_author
);
123 section_author
.dispose();
124 section_author
= null;
130 public void handleEvent(Object eventSource
) {
131 if (eventSource
== toggleable_cache
) {
132 handleToggleableCacheField();
133 // we never want the fullTitleCache to be protected since we only
135 // initiating the free text name editor
136 getEntity().setProtectedFullTitleCache(false);
137 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
138 if (getParentElement() instanceof AbstractCdmDetailSection
) {
139 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
141 if (!toggleable_cache
.getState()) {
142 toggleable_cache
.setText(getEntity().getTitleCache());
145 if (eventSource
== section_name
) {
146 section_name
.setEntity(getEntity());
147 getLayoutComposite().layout();