8c956f1111db6679aecb39feee13ea2ab2b34856
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / taxon / TaxonBaseDetailElement.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.taxon;
12
13 import java.util.Arrays;
14
15 import org.eclipse.jface.util.PropertyChangeEvent;
16 import org.eclipse.swt.SWT;
17
18 import eu.etaxonomy.cdm.model.reference.Reference;
19 import eu.etaxonomy.cdm.model.taxon.Taxon;
20 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21 import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
22 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
23 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
27 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
28 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
29 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
30 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
31
32 /**
33 * <p>
34 * TaxonBaseDetailElement class.
35 * </p>
36 *
37 * @author n.hoffmann
38 * @created Feb 26, 2010
39 * @version 1.0
40 */
41 public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase> {
42
43 private CheckboxElement checkbox_doubtful;
44
45 private CheckboxElement checkbox_useNameCache;
46
47 private EntitySelectionElement<Reference> selection_secundum;
48
49 private TextWithLabelElement text_secundum_microreference;
50
51 private TextWithLabelElement text_appendedPhrase;
52
53 private CheckboxElement checkbox_published;
54
55 // private SynonymRelationshipDetailSection sectionSynonymRelationship;
56
57 /**
58 * <p>
59 * Constructor for TaxonBaseDetailElement.
60 * </p>
61 *
62 * @param cdmFormFactory
63 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
64 * @param formElement
65 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
66 * @param style
67 * a int.
68 */
69 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
70 ICdmFormElement formElement, int style) {
71 super(cdmFormFactory, formElement);
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
77 toggleable_cache = formFactory.createToggleableTextField(formElement,
78 "Title Cache", entity.getTitleCache(),
79 entity.isProtectedTitleCache(), style);
80
81 //TODO RL
82 boolean rl=true;
83 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
84 toggleable_cache.setVisible(false);
85 }
86 if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
87 text_appendedPhrase = formFactory.createTextWithLabelElement(
88 formElement, "Appended Phrase", entity.getAppendedPhrase(),
89 SWT.WRAP);
90
91 }
92
93 selection_secundum = formFactory.createSelectionElement(Reference.class,
94 getConversationHolder(), formElement, "Secundum",
95 entity.getSec(), EntitySelectionElement.ALL,
96 style);
97
98 text_secundum_microreference = formFactory.createTextWithLabelElement(
99 formElement, "Detail",
100 entity.getSecMicroReference(),null,
101 SWT.WRAP);
102
103 // TODO RL
104 if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)) {
105 checkbox_useNameCache = formFactory.createCheckbox(formElement,
106 "Exclude Authorship", entity.isUseNameCache(), style);
107 checkbox_doubtful = formFactory.createCheckbox(formElement,
108 entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
109 }
110
111 if (entity instanceof Taxon) {
112 checkbox_published = formFactory.createCheckbox(formElement,
113 "Taxon is published", ((Taxon) entity).isPublish(), style);
114 }
115
116 //#5974
117 // if(entity instanceof Synonym){
118 // sectionSynonymRelationship = formFactory.createSynonymRelationshipDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
119 // sectionSynonymRelationship.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
120 // sectionSynonymRelationship.setEntity((Synonym) entity);
121 // }
122 }
123
124 private void updateCheckboxPublish() {
125 if(getEntity() instanceof Taxon){
126 checkbox_published.setEnabled(
127 CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
128 );
129 }
130 }
131
132 @Override
133 protected void updateControlStates() {
134 super.updateControlStates();
135 updateCheckboxPublish();
136 }
137
138 /** {@inheritDoc} */
139 @Override
140 protected void updateContent() {
141 super.updateContent();
142 toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
143 setIrrelevant(toggleable_cache.getState(),
144 Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
145 }
146
147 @Override
148 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
149 String title = getEntity().generateTitle();
150 getEntity().setTitleCache(title);
151 super.handleTitleCacheRelevantChange(event);
152 }
153
154 /** {@inheritDoc} */
155 @Override
156 public void handleEvent(Object eventSource) {
157 if (eventSource== toggleable_cache) {
158 handleToggleableCacheField();
159 } else if (eventSource == checkbox_doubtful) {
160 getEntity().setDoubtful(checkbox_doubtful.getSelection());
161 } else if (eventSource == checkbox_useNameCache) {
162 getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
163 } else if (eventSource == selection_secundum) {
164 getEntity().setSec(selection_secundum.getSelection());
165 } else if (eventSource == text_appendedPhrase) {
166 getEntity().setAppendedPhrase(text_appendedPhrase.getText());
167 }else if (eventSource == text_secundum_microreference) {
168 getEntity().setSecMicroReference(text_secundum_microreference.getText());
169 } else if (eventSource == checkbox_published) {
170 ((Taxon)getEntity()).setPublish(checkbox_published.getSelection());
171 }
172 }
173 @Override
174 protected void handleToggleableCacheField() {
175 boolean pushedState = toggleable_cache.getState();
176
177 getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
178 setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
179 updateToggleableCacheField();
180 }
181 }