55662b2d56b7870597dc735d34b92724ea0d3ebd
[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.Section;
16
17 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18 import eu.etaxonomy.cdm.model.name.NonViralName;
19 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
20 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType;
23 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
26
27 /**
28 * <p>
29 * NonViralNameDetailElement class.
30 * </p>
31 *
32 * @author n.hoffmann
33 * @created May 20, 2010
34 * @version 1.0
35 */
36 public class NonViralNameDetailElement extends
37 AbstractIdentifiableEntityDetailElement<NonViralName> {
38
39 private NameDetailSection section_name;
40 private AuthorshipDetailSection section_author;
41 private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
42 private HybridDetailSection section_hybrid;
43
44 /**
45 * <p>
46 * Constructor for NonViralNameDetailElement.
47 * </p>
48 *
49 * @param formFactory
50 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
51 * object.
52 * @param formElement
53 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
54 * object.
55 */
56 public NonViralNameDetailElement(CdmFormFactory formFactory,
57 ICdmFormElement formElement) {
58 super(formFactory, formElement);
59 }
60
61 /*
62 * (non-Javadoc)
63 *
64 * @see
65 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
66 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
67 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
68 */
69 /** {@inheritDoc} */
70 @Override
71 protected void createControls(ICdmFormElement formElement,
72 final NonViralName entity, int style) {
73
74 toggleable_cache = formFactory.createToggleableTextField(formElement,
75 "Cache", entity.getTitleCache(), entity.isProtectedTitleCache()
76 || entity.isProtectedFullTitleCache(), style);
77
78 combo_nomenclaturalCode = formFactory
79 .createEnumComboElement(NomenclaturalCode.class,
80 formElement, style);
81 combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
82
83 section_name = (NameDetailSection) formFactory.createCdmDetailSection(
84 DetailType.SCIENTIFICNAME, getConversationHolder(),
85 formElement, null, Section.TWISTIE | Section.EXPANDED);
86 section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
87 addControl(section_name);
88 addElement(section_name);
89 section_author = (AuthorshipDetailSection) formFactory
90 .createCdmDetailSection(DetailType.AUTHORSHIP,
91 getConversationHolder(), formElement, null,
92 Section.TWISTIE | Section.EXPANDED);
93 section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
94 addControl(section_author);
95 addElement(section_author);
96
97 section_hybrid = (HybridDetailSection) formFactory.createCdmDetailSection(DetailType.HYBRID,
98 getConversationHolder(), formElement, null,
99 Section.TWISTIE);
100 section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
101 addControl(section_hybrid);
102 addElement(section_hybrid);
103 }
104
105 /** {@inheritDoc} */
106 @Override
107 protected void updateContent() {
108 super.updateContent();
109
110 // disable nomenclatural code, because changing of nom.code is not
111 // implemented on library side
112 combo_nomenclaturalCode.setEnabled(false);
113
114 setIrrelevant(toggleable_cache.getState(),
115 Arrays.asList(new Object[] { toggleable_cache }));
116 }
117
118 /** {@inheritDoc} */
119 @Override
120 public void setEntity(NonViralName entity) {
121 super.setEntity(entity);
122 section_name.setEntity(entity);
123 section_author.setEntity(entity);
124 section_hybrid.setEntity(entity);
125 }
126
127 /** {@inheritDoc} */
128 @Override
129 public void removeElements() {
130 super.removeElements();
131 if (section_name != null) {
132 section_name.removeElements();
133 removeControl(section_name);
134 section_name.dispose();
135 section_name = null;
136 }
137 if (section_author != null) {
138 section_author.removeElements();
139 removeControl(section_author);
140 section_author.dispose();
141 section_author = null;
142 }
143 }
144
145 /*
146 * (non-Javadoc)
147 *
148 * @see
149 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
150 * .lang.Object)
151 */
152 /** {@inheritDoc} */
153 @Override
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
158 // use it for
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();
164 if (!toggleable_cache.getState()) {
165 toggleable_cache.setText(getEntity().getTitleCache());
166 }
167 }
168 if (eventSource == section_name) {
169 section_name.setEntity(getEntity());
170 getLayoutComposite().layout();
171 }
172 }
173 }