2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
;
12 import java
.util
.Arrays
;
14 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
15 import org
.eclipse
.swt
.SWT
;
17 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
22 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.Role
;
23 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
24 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
36 * @created Feb 26, 2010
39 public class TaxonBaseDetailElement
extends AbstractIdentifiableEntityDetailElement
<TaxonBase
> {
41 private CheckboxElement checkbox_doubtful
;
43 private CheckboxElement checkbox_useNameCache
;
45 private EntitySelectionElement
<Reference
> selection_secundum
;
47 private TextWithLabelElement text_secundum_microreference
;
49 private TextWithLabelElement text_appendedPhrase
;
51 private CheckboxElement checkbox_published
;
53 private TermComboElement
<SynonymType
> combo_relationshipType
;
54 private CheckboxElement checkProParte
;
55 private CheckboxElement checkPartial
;
57 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
58 ICdmFormElement formElement
, int style
) {
59 super(cdmFormFactory
, formElement
);
64 protected void createControls(ICdmFormElement formElement
, TaxonBase entity
, int style
) {
65 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
66 "Title Cache", entity
.getTitleCache(),
67 entity
.isProtectedTitleCache(), style
);
71 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
72 toggleable_cache
.setVisible(false);
74 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
75 text_appendedPhrase
= formFactory
.createTextWithLabelElement(
76 formElement
, "Appended Phrase", entity
.getAppendedPhrase(),
81 selection_secundum
= formFactory
.createSelectionElement(Reference
.class,
82 getConversationHolder(), formElement
, "Secundum",
83 entity
.getSec(), EntitySelectionElement
.ALL
,
86 text_secundum_microreference
= formFactory
.createTextWithLabelElement(
87 formElement
, "Detail",
88 entity
.getSecMicroReference(),null,
92 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)) {
93 checkbox_useNameCache
= formFactory
.createCheckbox(formElement
,
94 "Exclude Authorship", entity
.isUseNameCache(), style
);
95 checkbox_doubtful
= formFactory
.createCheckbox(formElement
,
96 entity
.getClass().getSimpleName() + " is doubtful", entity
.isDoubtful(), style
);
99 if (entity
instanceof Taxon
) {
100 checkbox_published
= formFactory
.createCheckbox(formElement
,
101 "Taxon is published", ((Taxon
) entity
).isPublish(), style
);
104 if(entity
instanceof Synonym
){
105 //#6198 removed type as it is currently not handled correctly in the editor
106 // combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.SynonymType, formElement, "Synonym Type", ((Synonym) entity).getType(), style);
107 checkProParte
= formFactory
.createCheckbox(formElement
, "Pro Parte Synonym", ((Synonym
) entity
).isProParte(), style
);
108 checkPartial
= formFactory
.createCheckbox(formElement
, "Partial Synonym", ((Synonym
) entity
).isPartial(), style
);
112 private void updateCheckboxPublish() {
113 if(getEntity() instanceof Taxon
){
114 checkbox_published
.setEnabled(
115 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
121 protected void updateControlStates() {
122 super.updateControlStates();
123 updateCheckboxPublish();
128 protected void updateContent() {
129 super.updateContent();
130 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
131 setIrrelevant(toggleable_cache
.getState(),
132 Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
}));
136 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
137 String title
= getEntity().generateTitle();
138 getEntity().setTitleCache(title
);
139 super.handleTitleCacheRelevantChange(event
);
144 public void handleEvent(Object eventSource
) {
145 if (eventSource
== toggleable_cache
) {
146 handleToggleableCacheField();
147 } else if (eventSource
== checkbox_doubtful
) {
148 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
149 } else if (eventSource
== checkbox_useNameCache
) {
150 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
151 } else if (eventSource
== selection_secundum
) {
152 getEntity().setSec(selection_secundum
.getSelection());
153 } else if (eventSource
== text_appendedPhrase
) {
154 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
155 } else if (eventSource
== text_secundum_microreference
) {
156 getEntity().setSecMicroReference(text_secundum_microreference
.getText());
157 } else if (eventSource
== checkbox_published
) {
158 ((Taxon
)getEntity()).setPublish(checkbox_published
.getSelection());
159 } else if(eventSource
== combo_relationshipType
){
160 ((Synonym
) getEntity()).setType(combo_relationshipType
.getSelection());
161 } else if(eventSource
== checkPartial
){
162 ((Synonym
) getEntity()).setPartial(checkPartial
.getSelection());
163 } else if(eventSource
== checkProParte
){
164 ((Synonym
) getEntity()).setProParte(checkProParte
.getSelection());
168 protected void handleToggleableCacheField() {
169 boolean pushedState
= toggleable_cache
.getState();
171 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
172 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
}));
173 updateToggleableCacheField();