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