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
;
14 import java
.util
.List
;
16 import org
.eclipse
.ui
.forms
.widgets
.Section
;
18 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
19 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
20 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.DetailType
;
21 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.EnumComboType
;
22 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
23 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.term
.NomenclaturalCodeComboElement
;
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 NomenclaturalCodeComboElement combo_nomenclaturalCode
;
46 * Constructor for NonViralNameDetailElement.
50 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
53 * a {@link eu.etaxonomy.taxeditor.ui.forms.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
= (NomenclaturalCodeComboElement
) formFactory
79 .createEnumComboElement(EnumComboType
.NOMENCLATURALCODE
,
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(CdmFormFactory
.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(CdmFormFactory
.FILL_HORIZONTALLY(2, 1));
94 addControl(section_author
);
95 addElement(section_author
);
100 protected void updateContent() {
101 super.updateContent();
103 // disable nomenclatural code, because changing of nom.code is not
104 // implemented on library side
105 combo_nomenclaturalCode
.setEnabled(false);
107 setIrrelevant(toggleable_cache
.getState(),
108 Arrays
.asList(new Object
[] { toggleable_cache
}));
113 public void setEntity(NonViralName entity
) {
114 super.setEntity(entity
);
115 section_name
.setEntity(entity
);
116 section_author
.setEntity(entity
);
121 public void removeElements() {
122 super.removeElements();
123 if (section_name
!= null) {
124 section_name
.removeElements();
125 removeControl(section_name
);
126 section_name
.dispose();
129 if (section_author
!= null) {
130 section_author
.removeElements();
131 removeControl(section_author
);
132 section_author
.dispose();
133 section_author
= null;
141 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
146 public void handleEvent(Object eventSource
) {
147 if (eventSource
== toggleable_cache
) {
148 handleToggleableCacheField();
149 // we never want the fullTitleCache to be protected since we only
151 // initiating the free text name editor
152 getEntity().setProtectedFullTitleCache(false);
153 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
154 if (getParentElement() instanceof AbstractCdmDetailSection
)
155 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
156 if (!toggleable_cache
.getState()) {
157 toggleable_cache
.setText(getEntity().getTitleCache());
160 if (eventSource
== section_name
) {
161 section_name
.setEntity(getEntity());
162 getLayoutComposite().layout();