Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / taxon / TaxonBaseDetailElement.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.ui.section.taxon;
10
11 import org.eclipse.jface.util.PropertyChangeEvent;
12 import org.eclipse.swt.SWT;
13
14 import eu.etaxonomy.cdm.model.reference.Reference;
15 import eu.etaxonomy.cdm.model.taxon.Synonym;
16 import eu.etaxonomy.cdm.model.taxon.SynonymType;
17 import eu.etaxonomy.cdm.model.taxon.Taxon;
18 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
19 import eu.etaxonomy.cdm.persistence.permission.Role;
20 import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
21 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23 import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
24 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
26 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
29 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
30
31 /**
32 * @author n.hoffmann
33 * @created Feb 26, 2010
34 */
35 public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase<?>> {
36
37 private CheckboxElement checkbox_doubtful;
38
39 private CheckboxElement checkbox_useNameCache;
40
41 private EntitySelectionElement<Reference> selection_secundum;
42 private TextWithLabelElement text_secundum_microreference;
43
44 private TextWithLabelElement text_appendedPhrase;
45
46 private CheckboxElement checkbox_published;
47
48 private TermComboElement<SynonymType> combo_relationshipType;
49
50 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
51 ICdmFormElement formElement, int style) {
52 super(cdmFormFactory, formElement);
53 }
54
55 @Override
56 protected void createControls(ICdmFormElement formElement, TaxonBase<?> entity, int style) {
57
58 NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
59 toggleable_cache = formFactory.createToggleableTextField(formElement,
60 "Title Cache", entity.getTitleCache(),
61 entity.isProtectedTitleCache(), style);
62
63 text_appendedPhrase = formFactory.createTextWithLabelElement(
64 formElement, "Appended Phrase", entity.getAppendedPhrase(),
65 SWT.WRAP);
66
67 selection_secundum = formFactory.createSelectionElement(Reference.class,
68 formElement, "Secundum",
69 entity.getSec(), EntitySelectionElement.ALL,
70 style);
71 if (config != null && !config.isSecEnabled()){
72 selection_secundum.setEnabled(false);
73 }
74 if (config != null && config.isSecDetailsActivated()){
75 text_secundum_microreference = formFactory.createTextWithLabelElement(
76 formElement, "Detail",
77 entity.getSecMicroReference(),null,
78 SWT.WRAP);
79 }
80
81 checkbox_useNameCache = formFactory.createCheckbox(formElement,
82 "Exclude Authorship", entity.isUseNameCache(), style);
83 checkbox_doubtful = formFactory.createCheckbox(formElement,
84 entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
85
86
87 checkbox_published = formFactory.createCheckbox(formElement,
88 entity.getClass().getSimpleName()+" is published", entity.isPublish(), style);
89
90 if(entity instanceof Synonym){
91 //#6198 removed type as it is currently not handled correctly in the editor
92 // combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.SynonymType, formElement, "Synonym Type", ((Synonym) entity).getType(), style);
93 }
94
95 //cache relevance
96 registerCacheRelevance(checkbox_doubtful);
97 registerCacheRelevance(checkbox_useNameCache);
98 registerCacheRelevance(selection_secundum);
99 registerCacheRelevance(text_secundum_microreference);
100 registerCacheRelevance(text_appendedPhrase);
101 registerCacheRelevance(combo_relationshipType);
102 }
103
104 private void updateCheckboxPublish() {
105 if(getEntity() instanceof Taxon){
106 checkbox_published.setEnabled(
107 CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
108 );
109 }
110 }
111
112 @Override
113 protected void updateControlStates() {
114 super.updateControlStates();
115 updateCheckboxPublish();
116 }
117
118 @Override
119 protected void updateContent() {
120 super.updateContent();
121 toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
122 updateCacheRelevance();
123 }
124
125 @Override
126 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
127 String title = getEntity().generateTitle();
128 getEntity().setTitleCache(title);
129 super.handleTitleCacheRelevantChange(event);
130 }
131
132 @Override
133 public void handleEvent(Object eventSource) {
134 if (eventSource== toggleable_cache) {
135 handleToggleableCacheField();
136 } else if (eventSource == checkbox_doubtful) {
137 getEntity().setDoubtful(checkbox_doubtful.getSelection());
138 } else if (eventSource == checkbox_useNameCache) {
139 getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
140 } else if (eventSource == selection_secundum) {
141 getEntity().setSec(selection_secundum.getSelection());
142 } else if (eventSource == text_appendedPhrase) {
143 getEntity().setAppendedPhrase(text_appendedPhrase.getText());
144 } else if (eventSource == text_secundum_microreference) {
145 getEntity().setSecMicroReference(text_secundum_microreference.getText());
146 } else if (eventSource == checkbox_published) {
147 getEntity().setPublish(checkbox_published.getSelection());
148 } else if(eventSource == combo_relationshipType){
149 ((Synonym) getEntity()).setType(combo_relationshipType.getSelection());
150 //#7334/5 removed pro parte and partial as they are handled as concept relationships now
151 // } else if(eventSource == checkPartial){
152 // ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
153 // } else if(eventSource == checkProParte){
154 // ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
155 }
156 }
157
158 @Override
159 protected void handleToggleableCacheField() {
160 getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
161 updateCacheRelevance();
162 updateToggleableCacheField();
163 }
164 }