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
.Section
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
18 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
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
.CdmFormFactory
.DetailType
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
29 * NonViralNameDetailElement class.
33 * @created May 20, 2010
36 public class NonViralNameDetailElement
extends
37 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
39 private NameDetailSection section_name
;
40 private AuthorshipDetailSection section_author
;
41 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
42 private HybridDetailSection section_hybrid
;
46 * Constructor for NonViralNameDetailElement.
50 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
53 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
56 public NonViralNameDetailElement(CdmFormFactory formFactory
,
57 ICdmFormElement formElement
) {
58 super(formFactory
, formElement
);
65 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
66 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
67 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
71 protected void createControls(ICdmFormElement formElement
,
72 final NonViralName entity
, int style
) {
74 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
75 "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache()
76 || entity
.isProtectedFullTitleCache(), style
);
78 combo_nomenclaturalCode
= formFactory
79 .createEnumComboElement(NomenclaturalCode
.class,
81 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
83 section_name
= (NameDetailSection
) formFactory
.createCdmDetailSection(
84 DetailType
.SCIENTIFICNAME
, getConversationHolder(),
85 formElement
, null, Section
.TWISTIE
| Section
.EXPANDED
);
86 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
87 addControl(section_name
);
88 addElement(section_name
);
89 section_author
= (AuthorshipDetailSection
) formFactory
90 .createCdmDetailSection(DetailType
.AUTHORSHIP
,
91 getConversationHolder(), formElement
, null,
92 Section
.TWISTIE
| Section
.EXPANDED
);
93 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
94 addControl(section_author
);
95 addElement(section_author
);
97 section_hybrid
= (HybridDetailSection
) formFactory
.createCdmDetailSection(DetailType
.HYBRID
,
98 getConversationHolder(), formElement
, null,
100 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
101 addControl(section_hybrid
);
102 addElement(section_hybrid
);
107 protected void updateContent() {
108 super.updateContent();
110 // disable nomenclatural code, because changing of nom.code is not
111 // implemented on library side
112 combo_nomenclaturalCode
.setEnabled(false);
114 setIrrelevant(toggleable_cache
.getState(),
115 Arrays
.asList(new Object
[] { toggleable_cache
}));
120 public void setEntity(NonViralName entity
) {
121 super.setEntity(entity
);
122 section_name
.setEntity(entity
);
123 section_author
.setEntity(entity
);
124 section_hybrid
.setEntity(entity
);
129 public void removeElements() {
130 super.removeElements();
131 if (section_name
!= null) {
132 section_name
.removeElements();
133 removeControl(section_name
);
134 section_name
.dispose();
137 if (section_author
!= null) {
138 section_author
.removeElements();
139 removeControl(section_author
);
140 section_author
.dispose();
141 section_author
= null;
149 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
154 public void handleEvent(Object eventSource
) {
155 if (eventSource
== toggleable_cache
) {
156 handleToggleableCacheField();
157 // we never want the fullTitleCache to be protected since we only
159 // initiating the free text name editor
160 getEntity().setProtectedFullTitleCache(false);
161 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
162 if (getParentElement() instanceof AbstractCdmDetailSection
)
163 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
164 if (!toggleable_cache
.getState()) {
165 toggleable_cache
.setText(getEntity().getTitleCache());
168 if (eventSource
== section_name
) {
169 section_name
.setEntity(getEntity());
170 getLayoutComposite().layout();