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
.element
.LsidWithExceptionLabelElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
31 * @created May 20, 2010
34 public class NonViralNameDetailElement
extends
35 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
37 private NameDetailSection section_name
;
38 private AuthorshipDetailSection section_author
;
39 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
40 private HybridDetailSection section_hybrid
;
41 private LsidWithExceptionLabelElement textLsid
;
43 public NonViralNameDetailElement(CdmFormFactory formFactory
,
44 ICdmFormElement formElement
) {
45 super(formFactory
, formElement
);
50 protected void createControls(ICdmFormElement formElement
, final NonViralName entity
, int style
) {
51 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
53 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
54 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
57 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
58 toggleable_cache
.setVisible(false);
59 combo_nomenclaturalCode
.setVisible(false);
61 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
62 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
63 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
64 addControl(section_name
);
65 addElement(section_name
);
66 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
67 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
68 addControl(section_author
);
69 addElement(section_author
);
72 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
73 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
74 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
75 addControl(section_hybrid
);
76 addElement(section_hybrid
);
84 protected void updateContent() {
85 super.updateContent();
87 // disable nomenclatural code, because changing of nom.code is not
88 // implemented on library side
89 if(combo_nomenclaturalCode
!=null){
90 combo_nomenclaturalCode
.setEnabled(false);
93 if(toggleable_cache
!=null){
94 setIrrelevant(toggleable_cache
.getState(),
95 Arrays
.asList(new Object
[] { toggleable_cache
}));
101 public void setEntity(NonViralName entity
) {
102 super.setEntity(entity
);
103 if (section_name
!=null) {
104 section_name
.setEntity(entity
);
106 if (section_author
!=null) {
107 section_author
.setEntity(entity
);
109 if (section_hybrid
!=null) {
110 section_hybrid
.setEntity(entity
);
116 public void removeElements() {
117 super.removeElements();
118 if (section_name
!= null) {
119 section_name
.removeElements();
120 removeControl(section_name
);
121 section_name
.dispose();
124 if (section_author
!= null) {
125 section_author
.removeElements();
126 removeControl(section_author
);
127 section_author
.dispose();
128 section_author
= null;
134 public void handleEvent(Object eventSource
) {
135 if (eventSource
== toggleable_cache
) {
136 handleToggleableCacheField();
137 // we never want the fullTitleCache to be protected since we only
139 // initiating the free text name editor
140 getEntity().setProtectedFullTitleCache(false);
141 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
142 if (getParentElement() instanceof AbstractCdmDetailSection
) {
143 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
145 if (!toggleable_cache
.getState()) {
146 toggleable_cache
.setText(getEntity().getTitleCache());
149 if (eventSource
== section_name
) {
150 section_name
.setEntity(getEntity());
151 getLayoutComposite().layout();
153 else if(eventSource
==textLsid
){
154 getEntity().setLsid(textLsid
.parseText());