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
;
44 public NonViralNameDetailElement(CdmFormFactory formFactory
,
45 ICdmFormElement formElement
) {
46 super(formFactory
, formElement
);
47 initIsAdvancedDetailsView();
53 protected void createControls(ICdmFormElement formElement
, final NonViralName entity
, int style
) {
57 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache() || entity
.isProtectedFullTitleCache(), style
);
59 combo_nomenclaturalCode
= formFactory
.createEnumComboElement(NomenclaturalCode
.class, formElement
, style
);
60 combo_nomenclaturalCode
.setSelection(entity
.getNomenclaturalCode());
61 textLsid
= formFactory
.createLsidWithExceptionLabelElement(formElement
, "Lsid", entity
.getLsid(), style
);
63 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
64 toggleable_cache
.setVisible(false);
65 combo_nomenclaturalCode
.setVisible(false);
70 section_name
= formFactory
.createNameDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
71 section_name
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
72 addControl(section_name
);
73 addElement(section_name
);
74 section_author
= formFactory
.createAuthorshipDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
| ExpandableComposite
.EXPANDED
);
75 section_author
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
76 addControl(section_author
);
77 addElement(section_author
);
81 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
82 section_hybrid
= formFactory
.createHybridDetailSection(getConversationHolder(), formElement
, null, ExpandableComposite
.TWISTIE
);
83 section_hybrid
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
84 addControl(section_hybrid
);
85 addElement(section_hybrid
);
94 protected void updateContent() {
95 super.updateContent();
97 // disable nomenclatural code, because changing of nom.code is not
98 // implemented on library side
99 if(combo_nomenclaturalCode
!=null){
100 combo_nomenclaturalCode
.setEnabled(false);
103 if(toggleable_cache
!=null){
104 setIrrelevant(toggleable_cache
.getState(),
105 Arrays
.asList(new Object
[] { toggleable_cache
}));
111 public void setEntity(NonViralName entity
) {
112 super.setEntity(entity
);
113 if (section_name
!=null) {
114 section_name
.setEntity(entity
);
116 if (section_author
!=null) {
117 section_author
.setEntity(entity
);
119 if (section_hybrid
!=null) {
120 section_hybrid
.setEntity(entity
);
126 public void removeElements() {
127 super.removeElements();
128 if (section_name
!= null) {
129 section_name
.removeElements();
130 removeControl(section_name
);
131 section_name
.dispose();
134 if (section_author
!= null) {
135 section_author
.removeElements();
136 removeControl(section_author
);
137 section_author
.dispose();
138 section_author
= null;
144 public void handleEvent(Object eventSource
) {
145 if (eventSource
== toggleable_cache
) {
146 handleToggleableCacheField();
147 // we never want the fullTitleCache to be protected since we only
149 // initiating the free text name editor
150 getEntity().setProtectedFullTitleCache(false);
151 } else if (eventSource
== section_name
|| eventSource
== section_author
) {
152 if (getParentElement() instanceof AbstractCdmDetailSection
) {
153 ((AbstractCdmDetailSection
) getParentElement()).updateTitle();
155 if (toggleable_cache
!= null){
156 if (!toggleable_cache
.getState()) {
157 toggleable_cache
.setText(getEntity().getTitleCache());
161 if (eventSource
== section_name
) {
162 section_name
.setEntity(getEntity());
163 getLayoutComposite().layout();
165 else if(eventSource
==textLsid
){
166 getEntity().setLsid(textLsid
.parseText());
170 protected void handleToggleableCacheField() {
171 boolean pushedState
= toggleable_cache
.getState();
173 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
174 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, textLsid
}));
175 updateToggleableCacheField();
182 // public void toggleAdvancedMediaView(){
183 // mediaDetailElement.toggleAdvancedMediaView();