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
.ICdmFormElement
;
21 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ToggleableTextElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.DetailType
;
23 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.EnumComboType
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.term
.NomenclaturalCodeComboElement
;
29 * <p>NonViralNameDetailElement class.</p>
32 * @created May 20, 2010
35 public class NonViralNameDetailElement
extends AbstractCdmDetailElement
<NonViralName
> {
37 private NameDetailSection section_name
;
38 private AuthorshipDetailSection section_author
;
39 private ToggleableTextElement toggleable_cache
;
40 private NomenclaturalCodeComboElement combo_nomenclaturalCode
;
43 * <p>Constructor for NonViralNameDetailElement.</p>
45 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
46 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
48 public NonViralNameDetailElement(CdmFormFactory formFactory
,
49 ICdmFormElement formElement
) {
50 super(formFactory
, formElement
);
54 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement, eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
58 protected void createControls(ICdmFormElement formElement
,
59 final NonViralName entity
, int style
) {
61 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
63 combo_nomenclaturalCode
= (NomenclaturalCodeComboElement
) formFactory
.createEnumComboElement(EnumComboType
.NOMENCLATURALCODE
, formElement
, style
);
64 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
66 section_name
= (NameDetailSection
) formFactory
.createCdmDetailSection(DetailType
.SCIENTIFICNAME
, getConversationHolder(), formElement
, null, Section
.TWISTIE
| Section
.EXPANDED
);
67 section_name
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY(2, 1));
68 addControl(section_name
);
69 addElement(section_name
);
70 section_author
= (AuthorshipDetailSection
) formFactory
.createCdmDetailSection(DetailType
.AUTHORSHIP
, getConversationHolder(), formElement
, null, Section
.TWISTIE
| Section
.EXPANDED
);
71 section_author
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY(2, 1));
72 addControl(section_author
);
73 addElement(section_author
);
79 protected void updateContent() {
80 super.updateContent();
82 // disable nomenclatural code, because changing of nom.code is not implemented on library side
83 combo_nomenclaturalCode
.setEnabled(false);
85 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
90 public void setEntity(NonViralName entity
) {
91 super.setEntity(entity
);
92 section_name
.setEntity(entity
);
93 section_author
.setEntity(entity
);
98 public void removeElements() {
99 super.removeElements();
100 if(section_name
!= null){
101 section_name
.removeElements();
102 removeControl(section_name
);
103 section_name
.dispose();
106 if(section_author
!= null){
107 section_author
.removeElements();
108 removeControl(section_author
);
109 section_author
.dispose();
110 section_author
= null;
115 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object)
119 public void handleEvent(Object eventSource
) {
120 if(eventSource
== toggleable_cache
){
121 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
122 // we never want the fullTitleCache to be protected since we only use it for
123 // initiating the free text name editor
124 getEntity().setProtectedFullTitleCache(false);
125 boolean irrelevant
= toggleable_cache
.getState();
126 List
<Object
> except
= Arrays
.asList(new Object
[]{toggleable_cache
});
127 setIrrelevant(irrelevant
, except
);
129 else if(eventSource
== section_name
|| eventSource
== section_author
){
130 if(getParentElement() instanceof AbstractCdmDetailSection
)
131 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
132 if(! toggleable_cache
.getState()){
133 toggleable_cache
.setText(getEntity().getTitleCache());
136 if(eventSource
== section_name
){
137 section_name
.setEntity(getEntity());
138 getLayoutComposite().layout();