Merge branch 'develop' of https://dev.e-taxonomy.eu/git/taxeditor into actualBranch
[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 * @author n.hoffmann
30 * @created May 20, 2010
31 * @version 1.0
32 */
33 public class NonViralNameDetailElement extends
34 AbstractIdentifiableEntityDetailElement<NonViralName> {
35
36 private NameDetailSection section_name;
37 private AuthorshipDetailSection section_author;
38 private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
39 private HybridDetailSection section_hybrid;
40
41 public NonViralNameDetailElement(CdmFormFactory formFactory,
42 ICdmFormElement formElement) {
43 super(formFactory, formElement);
44 }
45
46 /** {@inheritDoc} */
47 @Override
48 protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
49 toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
50
51 combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
52 combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
53
54 //TODO RL
55 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
56 toggleable_cache.setVisible(false);
57 combo_nomenclaturalCode.setVisible(false);
58 }
59
60 section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
61 section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
62 addControl(section_name);
63 addElement(section_name);
64 section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
65 section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
66 addControl(section_author);
67 addElement(section_author);
68
69 //TODO RL
70 if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
71 section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
72 section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
73 addControl(section_hybrid);
74 addElement(section_hybrid);
75 }
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 protected void updateContent() {
81 super.updateContent();
82
83 // disable nomenclatural code, because changing of nom.code is not
84 // implemented on library side
85 if(combo_nomenclaturalCode!=null){
86 combo_nomenclaturalCode.setEnabled(false);
87 }
88
89 if(toggleable_cache!=null){
90 setIrrelevant(toggleable_cache.getState(),
91 Arrays.asList(new Object[] { toggleable_cache }));
92 }
93 }
94
95 /** {@inheritDoc} */
96 @Override
97 public void setEntity(NonViralName entity) {
98 super.setEntity(entity);
99 if (section_name!=null) {
100 section_name.setEntity(entity);
101 }
102 if (section_author!=null) {
103 section_author.setEntity(entity);
104 }
105 if (section_hybrid!=null) {
106 section_hybrid.setEntity(entity);
107 }
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public void removeElements() {
113 super.removeElements();
114 if (section_name != null) {
115 section_name.removeElements();
116 removeControl(section_name);
117 section_name.dispose();
118 section_name = null;
119 }
120 if (section_author != null) {
121 section_author.removeElements();
122 removeControl(section_author);
123 section_author.dispose();
124 section_author = null;
125 }
126 }
127
128 /** {@inheritDoc} */
129 @Override
130 public void handleEvent(Object eventSource) {
131 if (eventSource == toggleable_cache) {
132 handleToggleableCacheField();
133 // we never want the fullTitleCache to be protected since we only
134 // use it for
135 // initiating the free text name editor
136 getEntity().setProtectedFullTitleCache(false);
137 } else if (eventSource == section_name || eventSource == section_author) {
138 if (getParentElement() instanceof AbstractCdmDetailSection) {
139 ((AbstractCdmDetailSection) getParentElement()).updateTitle();
140 }
141 if (!toggleable_cache.getState()) {
142 toggleable_cache.setText(getEntity().getTitleCache());
143 }
144 }
145 if (eventSource == section_name) {
146 section_name.setEntity(getEntity());
147 getLayoutComposite().layout();
148 }
149 }
150 }