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
.section
.AbstractCdmDetailSection
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
28 * NonViralNameDetailElement class.
32 * @created May 20, 2010
35 public class NonViralNameDetailElement
extends
36 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
38 private NameDetailSection section_name
;
39 private AuthorshipDetailSection section_author
;
40 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
41 private HybridDetailSection section_hybrid
;
45 * Constructor for NonViralNameDetailElement.
49 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
52 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55 public NonViralNameDetailElement(CdmFormFactory formFactory
,
56 ICdmFormElement formElement
) {
57 super(formFactory
, formElement
);
64 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
65 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
66 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
70 protected void createControls(ICdmFormElement formElement
,
71 final NonViralName entity
, int style
) {
73 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
74 "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache()
75 || entity
.isProtectedFullTitleCache(), style
);
77 combo_nomenclaturalCode
= formFactory
78 .createEnumComboElement(NomenclaturalCode
.class,
80 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
82 section_name
= (NameDetailSection
) formFactory
.createCdmDetailSection(
83 DetailType
.SCIENTIFICNAME
, getConversationHolder(),
84 formElement
, null, Section
.TWISTIE
| Section
.EXPANDED
);
85 section_name
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY(2, 1));
86 addControl(section_name
);
87 addElement(section_name
);
88 section_author
= (AuthorshipDetailSection
) formFactory
89 .createCdmDetailSection(DetailType
.AUTHORSHIP
,
90 getConversationHolder(), formElement
, null,
91 Section
.TWISTIE
| Section
.EXPANDED
);
92 section_author
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY(2, 1));
93 addControl(section_author
);
94 addElement(section_author
);
96 section_hybrid
= (HybridDetailSection
) formFactory
.createCdmDetailSection(DetailType
.HYBRID
,
97 getConversationHolder(), formElement
, null,
99 section_hybrid
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY(2, 1));
100 addControl(section_hybrid
);
101 addElement(section_hybrid
);
106 protected void updateContent() {
107 super.updateContent();
109 // disable nomenclatural code, because changing of nom.code is not
110 // implemented on library side
111 combo_nomenclaturalCode
.setEnabled(false);
113 setIrrelevant(toggleable_cache
.getState(),
114 Arrays
.asList(new Object
[] { toggleable_cache
}));
119 public void setEntity(NonViralName entity
) {
120 super.setEntity(entity
);
121 section_name
.setEntity(entity
);
122 section_author
.setEntity(entity
);
123 section_hybrid
.setEntity(entity
);
128 public void removeElements() {
129 super.removeElements();
130 if (section_name
!= null) {
131 section_name
.removeElements();
132 removeControl(section_name
);
133 section_name
.dispose();
136 if (section_author
!= null) {
137 section_author
.removeElements();
138 removeControl(section_author
);
139 section_author
.dispose();
140 section_author
= null;
148 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
153 public void handleEvent(Object eventSource
) {
154 if (eventSource
== toggleable_cache
) {
155 handleToggleableCacheField();
156 // we never want the fullTitleCache to be protected since we only
158 // initiating the free text name editor
159 getEntity().setProtectedFullTitleCache(false);
160 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
161 if (getParentElement() instanceof AbstractCdmDetailSection
)
162 ((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();