3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
;
13 import java
.util
.Arrays
;
15 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
16 import org
.eclipse
.swt
.SWT
;
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
;
34 * TaxonBaseDetailElement class.
38 * @created Feb 26, 2010
41 public class TaxonBaseDetailElement
extends AbstractIdentifiableEntityDetailElement
<TaxonBase
> {
43 private CheckboxElement checkbox_doubtful
;
45 private CheckboxElement checkbox_useNameCache
;
47 private EntitySelectionElement
<Reference
> selection_secundum
;
49 private TextWithLabelElement text_secundum_microreference
;
51 private TextWithLabelElement text_appendedPhrase
;
53 private CheckboxElement checkbox_published
;
55 // private SynonymRelationshipDetailSection sectionSynonymRelationship;
59 * Constructor for TaxonBaseDetailElement.
62 * @param cdmFormFactory
63 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
65 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
69 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
70 ICdmFormElement formElement
, int style
) {
71 super(cdmFormFactory
, formElement
);
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
);
83 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
84 toggleable_cache
.setVisible(false);
86 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
87 text_appendedPhrase
= formFactory
.createTextWithLabelElement(
88 formElement
, "Appended Phrase", entity
.getAppendedPhrase(),
93 selection_secundum
= formFactory
.createSelectionElement(Reference
.class,
94 getConversationHolder(), formElement
, "Secundum",
95 entity
.getSec(), EntitySelectionElement
.ALL
,
98 text_secundum_microreference
= formFactory
.createTextWithLabelElement(
99 formElement
, "Detail",
100 entity
.getSecMicroReference(),null,
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
);
111 if (entity
instanceof Taxon
) {
112 checkbox_published
= formFactory
.createCheckbox(formElement
,
113 "Taxon is published", ((Taxon
) entity
).isPublish(), style
);
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);
124 private void updateCheckboxPublish() {
125 if(getEntity() instanceof Taxon
){
126 checkbox_published
.setEnabled(
127 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
133 protected void updateControlStates() {
134 super.updateControlStates();
135 updateCheckboxPublish();
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
}));
148 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
149 String title
= getEntity().generateTitle();
150 getEntity().setTitleCache(title
);
151 super.handleTitleCacheRelevantChange(event
);
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());
174 protected void handleToggleableCacheField() {
175 boolean pushedState
= toggleable_cache
.getState();
177 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
178 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
}));
179 updateToggleableCacheField();