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