d913442dbe169b9969b31c31ad15e9a16dbd782f
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NonViralNameDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.section.name;
12
13 import java.util.Arrays;
14
15 import org.eclipse.ui.forms.widgets.ExpandableComposite;
16
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.section.AbstractCdmDetailSection;
26 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
27
28 /**
29 * <p>
30 * NonViralNameDetailElement class.
31 * </p>
32 *
33 * @author n.hoffmann
34 * @created May 20, 2010
35 * @version 1.0
36 */
37 public class NonViralNameDetailElement extends
38 AbstractIdentifiableEntityDetailElement<NonViralName> {
39
40 private NameDetailSection section_name;
41 private AuthorshipDetailSection section_author;
42 private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
43 private HybridDetailSection section_hybrid;
44
45 /**
46 * <p>
47 * Constructor for NonViralNameDetailElement.
48 * </p>
49 *
50 * @param formFactory
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
52 * object.
53 * @param formElement
54 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55 * object.
56 */
57 public NonViralNameDetailElement(CdmFormFactory formFactory,
58 ICdmFormElement formElement) {
59 super(formFactory, formElement);
60 }
61
62 /*
63 * (non-Javadoc)
64 *
65 * @see
66 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
67 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
68 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
69 */
70 /** {@inheritDoc} */
71 @Override
72 protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
73 //name can be null in rare cases. Temporary solution for #4221. May be obsolete when
74 //#4393 (Make changing name of a taxon possible in details view) is implemented.
75 if(entity==null){
76 formFactory.createEmptyElement(formElement, "No name associated with this taxon.");
77 }
78 else {
79 toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
80
81 combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
82 combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
83
84 //TODO RL
85 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
86 toggleable_cache.setVisible(false);
87 combo_nomenclaturalCode.setVisible(false);
88 }
89
90 section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
91 section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
92 addControl(section_name);
93 addElement(section_name);
94 section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
95 section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
96 addControl(section_author);
97 addElement(section_author);
98
99 //TODO RL
100 if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
101 section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
102 section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
103 addControl(section_hybrid);
104 addElement(section_hybrid);
105 }
106 }
107 }
108
109 /** {@inheritDoc} */
110 @Override
111 protected void updateContent() {
112 super.updateContent();
113
114 // disable nomenclatural code, because changing of nom.code is not
115 // implemented on library side
116 if(combo_nomenclaturalCode!=null){
117 combo_nomenclaturalCode.setEnabled(false);
118 }
119
120 if(toggleable_cache!=null){
121 setIrrelevant(toggleable_cache.getState(),
122 Arrays.asList(new Object[] { toggleable_cache }));
123 }
124 }
125
126 /** {@inheritDoc} */
127 @Override
128 public void setEntity(NonViralName entity) {
129 super.setEntity(entity);
130 if (section_name!=null) {
131 section_name.setEntity(entity);
132 }
133 if (section_author!=null) {
134 section_author.setEntity(entity);
135 }
136 if (section_hybrid!=null) {
137 section_hybrid.setEntity(entity);
138 }
139 }
140
141 /** {@inheritDoc} */
142 @Override
143 public void removeElements() {
144 super.removeElements();
145 if (section_name != null) {
146 section_name.removeElements();
147 removeControl(section_name);
148 section_name.dispose();
149 section_name = null;
150 }
151 if (section_author != null) {
152 section_author.removeElements();
153 removeControl(section_author);
154 section_author.dispose();
155 section_author = null;
156 }
157 }
158
159 /*
160 * (non-Javadoc)
161 *
162 * @see
163 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
164 * .lang.Object)
165 */
166 /** {@inheritDoc} */
167 @Override
168 public void handleEvent(Object eventSource) {
169 if (eventSource == toggleable_cache) {
170 handleToggleableCacheField();
171 // we never want the fullTitleCache to be protected since we only
172 // use it for
173 // initiating the free text name editor
174 getEntity().setProtectedFullTitleCache(false);
175 } else if (eventSource == section_name || eventSource == section_author) {
176 if (getParentElement() instanceof AbstractCdmDetailSection) {
177 ((AbstractCdmDetailSection) getParentElement()).updateTitle();
178 }
179 if (!toggleable_cache.getState()) {
180 toggleable_cache.setText(getEntity().getTitleCache());
181 }
182 }
183 if (eventSource == section_name) {
184 section_name.setEntity(getEntity());
185 getLayoutComposite().layout();
186 }
187 }
188 }