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