2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Arrays
;
14 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
18 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
19 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
20 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.LsidWithExceptionLabelElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
30 * @created May 20, 2010
33 public class NonViralNameDetailElement
extends
34 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
36 private NameDetailSection section_name
;
37 private AuthorshipDetailSection section_author
;
38 private EnumComboElement
<NomenclaturalCode
> combo_nomenclaturalCode
;
39 private HybridDetailSection section_hybrid
;
40 private LsidWithExceptionLabelElement textLsid
;
43 public NonViralNameDetailElement(CdmFormFactory formFactory
,
44 ICdmFormElement formElement
) {
45 super(formFactory
, formElement
);
46 initIsAdvancedDetailsView();
52 protected void createControls(ICdmFormElement formElement
, final NonViralName entity
, int style
) {
56 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
58 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
59 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
60 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
63 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_CACHE
)){
64 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
67 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE
)){
68 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
69 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
71 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_LSID
)){
72 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
80 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
81 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
82 addControl(section_name
);
83 addElement(section_name
);
84 if (isAdvancedView
|| PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
)){
85 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
86 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
87 addControl(section_author
);
88 addElement(section_author
);
91 if (isAdvancedView
|| PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_HYBRID
)){
92 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
93 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
94 addControl(section_hybrid
);
95 addElement(section_hybrid
);
104 protected void updateContent() {
105 super.updateContent();
106 // disable nomenclatural code, because changing of nom.code is not
107 // implemented on library side
108 if(combo_nomenclaturalCode
!=null){
109 combo_nomenclaturalCode
.setEnabled(false);
112 if(toggleable_cache
!=null){
113 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
114 setIrrelevant(toggleable_cache
.getState(),
115 Arrays
.asList(new Object
[] { toggleable_cache
, textLsid
}));
121 public void setEntity(NonViralName entity
) {
122 super.setEntity(entity
);
123 if (section_name
!=null) {
124 section_name
.setEntity(entity
);
126 if (section_author
!=null) {
127 section_author
.setEntity(entity
);
129 if (section_hybrid
!=null) {
130 section_hybrid
.setEntity(entity
);
136 public void removeElements() {
137 super.removeElements();
138 if (section_name
!= null) {
139 section_name
.removeElements();
140 removeControl(section_name
);
141 section_name
.dispose();
144 if (section_author
!= null) {
145 section_author
.removeElements();
146 removeControl(section_author
);
147 section_author
.dispose();
148 section_author
= null;
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();
165 if (toggleable_cache
!= null){
166 if (!toggleable_cache
.getState()) {
167 toggleable_cache
.setText(getEntity().getTitleCache());
171 if (eventSource
== section_name
) {
172 section_name
.setEntity(getEntity());
173 getLayoutComposite().layout();
175 else if(eventSource
==textLsid
){
176 getEntity().setLsid(textLsid
.parseText());
180 protected void handleToggleableCacheField() {
181 boolean pushedState
= toggleable_cache
.getState();
183 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
184 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, textLsid
}));
185 updateToggleableCacheField();
192 // public void toggleAdvancedMediaView(){
193 // mediaDetailElement.toggleAdvancedMediaView();