819e6f6e3d7313180d446bf29e547dde44865788
[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 import java.util.List;
15
16 import org.eclipse.ui.forms.widgets.Section;
17
18 import eu.etaxonomy.cdm.model.name.NonViralName;
19 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
20 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
21 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EnumComboType;
22 import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
23 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
26 import eu.etaxonomy.taxeditor.ui.term.NomenclaturalCodeComboElement;
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 NomenclaturalCodeComboElement combo_nomenclaturalCode;
43
44 /**
45 * <p>
46 * Constructor for NonViralNameDetailElement.
47 * </p>
48 *
49 * @param formFactory
50 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
51 * object.
52 * @param formElement
53 * a {@link eu.etaxonomy.taxeditor.ui.forms.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 = (NomenclaturalCodeComboElement) formFactory
79 .createEnumComboElement(EnumComboType.NOMENCLATURALCODE,
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(CdmFormFactory.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(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
94 addControl(section_author);
95 addElement(section_author);
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 protected void updateContent() {
101 super.updateContent();
102
103 // disable nomenclatural code, because changing of nom.code is not
104 // implemented on library side
105 combo_nomenclaturalCode.setEnabled(false);
106
107 setIrrelevant(toggleable_cache.getState(),
108 Arrays.asList(new Object[] { toggleable_cache }));
109 }
110
111 /** {@inheritDoc} */
112 @Override
113 public void setEntity(NonViralName entity) {
114 super.setEntity(entity);
115 section_name.setEntity(entity);
116 section_author.setEntity(entity);
117 }
118
119 /** {@inheritDoc} */
120 @Override
121 public void removeElements() {
122 super.removeElements();
123 if (section_name != null) {
124 section_name.removeElements();
125 removeControl(section_name);
126 section_name.dispose();
127 section_name = null;
128 }
129 if (section_author != null) {
130 section_author.removeElements();
131 removeControl(section_author);
132 section_author.dispose();
133 section_author = null;
134 }
135 }
136
137 /*
138 * (non-Javadoc)
139 *
140 * @see
141 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
142 * .lang.Object)
143 */
144 /** {@inheritDoc} */
145 @Override
146 public void handleEvent(Object eventSource) {
147 if (eventSource == toggleable_cache) {
148 handleToggleableCacheField();
149 // we never want the fullTitleCache to be protected since we only
150 // use it for
151 // initiating the free text name editor
152 getEntity().setProtectedFullTitleCache(false);
153 } else if (eventSource == section_name || eventSource == section_author) {
154 if (getParentElement() instanceof AbstractCdmDetailSection)
155 ((AbstractCdmDetailSection) getParentElement()).updateTitle();
156 if (!toggleable_cache.getState()) {
157 toggleable_cache.setText(getEntity().getTitleCache());
158 }
159 }
160 if (eventSource == section_name) {
161 section_name.setEntity(getEntity());
162 getLayoutComposite().layout();
163 }
164 }
165 }