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
) {
74 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
76 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
77 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
80 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
81 toggleable_cache
.setVisible(false);
82 combo_nomenclaturalCode
.setVisible(false);
85 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
86 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
87 addControl(section_name
);
88 addElement(section_name
);
89 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
90 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
91 addControl(section_author
);
92 addElement(section_author
);
95 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
96 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
97 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
98 addControl(section_hybrid
);
99 addElement(section_hybrid
);
105 protected void updateContent() {
106 super.updateContent();
108 // disable nomenclatural code, because changing of nom.code is not
109 // implemented on library side
110 combo_nomenclaturalCode
.setEnabled(false);
112 setIrrelevant(toggleable_cache
.getState(),
113 Arrays
.asList(new Object
[] { toggleable_cache
}));
118 public void setEntity(NonViralName entity
) {
119 super.setEntity(entity
);
120 if (section_name
!=null) section_name
.setEntity(entity
);
121 if (section_author
!=null) section_author
.setEntity(entity
);
122 if (section_hybrid
!=null) section_hybrid
.setEntity(entity
);
127 public void removeElements() {
128 super.removeElements();
129 if (section_name
!= null) {
130 section_name
.removeElements();
131 removeControl(section_name
);
132 section_name
.dispose();
135 if (section_author
!= null) {
136 section_author
.removeElements();
137 removeControl(section_author
);
138 section_author
.dispose();
139 section_author
= null;
147 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
152 public void handleEvent(Object eventSource
) {
153 if (eventSource
== toggleable_cache
) {
154 handleToggleableCacheField();
155 // we never want the fullTitleCache to be protected since we only
157 // initiating the free text name editor
158 getEntity().setProtectedFullTitleCache(false);
159 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
160 if (getParentElement() instanceof AbstractCdmDetailSection
) {
161 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
163 if (!toggleable_cache
.getState()) {
164 toggleable_cache
.setText(getEntity().getTitleCache());
167 if (eventSource
== section_name
) {
168 section_name
.setEntity(getEntity());
169 getLayoutComposite().layout();