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
;
17 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
19 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
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
.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
.LayoutConstants
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
37 * TaxonBaseDetailElement class.
41 * @created Feb 26, 2010
44 public class TaxonBaseDetailElement
extends AbstractIdentifiableEntityDetailElement
<TaxonBase
> {
46 private CheckboxElement checkbox_doubtful
;
48 private CheckboxElement checkbox_useNameCache
;
50 private EntitySelectionElement
<Reference
> selection_secundum
;
52 private TextWithLabelElement text_secundum_microreference
;
54 private TextWithLabelElement text_appendedPhrase
;
56 private CheckboxElement checkbox_excluded
;
58 private CheckboxElement checkbox_unplaced
;
60 private CheckboxElement checkbox_published
;
62 // private SynonymRelationshipDetailSection sectionSynonymRelationship;
66 * Constructor for TaxonBaseDetailElement.
69 * @param cdmFormFactory
70 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
72 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
76 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
77 ICdmFormElement formElement
, int style
) {
78 super(cdmFormFactory
, formElement
);
83 protected void createControls(ICdmFormElement formElement
, TaxonBase entity
, int style
) {
84 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
85 "Title Cache", entity
.getTitleCache(),
86 entity
.isProtectedTitleCache(), style
);
90 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
91 toggleable_cache
.setVisible(false);
93 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
94 text_appendedPhrase
= formFactory
.createTextWithLabelElement(
95 formElement
, "Appended Phrase", entity
.getAppendedPhrase(),
100 selection_secundum
= formFactory
.createSelectionElement(Reference
.class,
101 getConversationHolder(), formElement
, "Secundum",
102 entity
.getSec(), EntitySelectionElement
.ALL
,
105 text_secundum_microreference
= formFactory
.createTextWithLabelElement(
106 formElement
, "Detail",
107 entity
.getSecMicroReference(),null,
111 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)) {
112 checkbox_useNameCache
= formFactory
.createCheckbox(formElement
,
113 "Exclude Authorship", entity
.isUseNameCache(), style
);
116 // if (entity instanceof Taxon) {
117 // checkbox_excluded = formFactory.createCheckbox(formElement,
118 // "Taxon is excluded", ((Taxon) entity).isExcluded(), style);
119 // checkbox_unplaced = formFactory.createCheckbox(formElement,
120 // "Taxon is unplaced", ((Taxon) entity).isUnplaced(), style);
123 checkbox_doubtful
= formFactory
.createCheckbox(formElement
,
124 entity
.getClass().getSimpleName() + " is doubtful", entity
.isDoubtful(), style
);
127 if (entity
instanceof Taxon
) {
128 checkbox_published
= formFactory
.createCheckbox(formElement
,
129 "Taxon is published", ((Taxon
) entity
).isPublish(), style
);
133 // if(entity instanceof Synonym){
134 // sectionSynonymRelationship = formFactory.createSynonymRelationshipDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
135 // sectionSynonymRelationship.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
136 // sectionSynonymRelationship.setEntity((Synonym) entity);
140 private void updateCheckboxPublish() {
141 if(getEntity() instanceof Taxon
){
142 checkbox_published
.setEnabled(
143 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
149 protected void updateControlStates() {
150 super.updateControlStates();
151 updateCheckboxPublish();
156 protected void updateContent() {
157 super.updateContent();
158 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
159 setIrrelevant(toggleable_cache
.getState(),
160 Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
, checkbox_unplaced
, checkbox_excluded
}));
164 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
165 String title
= getEntity().generateTitle();
166 getEntity().setTitleCache(title
);
167 super.handleTitleCacheRelevantChange(event
);
172 public void handleEvent(Object eventSource
) {
173 if (eventSource
== toggleable_cache
) {
174 handleToggleableCacheField();
175 } else if (eventSource
== checkbox_doubtful
) {
176 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
177 } else if (eventSource
== checkbox_useNameCache
) {
178 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
179 } else if (eventSource
== selection_secundum
) {
180 getEntity().setSec(selection_secundum
.getSelection());
181 } else if (eventSource
== text_appendedPhrase
) {
182 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
183 }else if (eventSource
== text_secundum_microreference
) {
184 getEntity().setSecMicroReference(text_secundum_microreference
.getText());
186 // }else if (eventSource == checkbox_excluded) {
187 // ((Taxon) getEntity()).setExcluded(checkbox_excluded.getSelection());
188 // } else if (eventSource == checkbox_unplaced) {
189 // ((Taxon) getEntity()).setUnplaced(checkbox_unplaced.getSelection());
190 } else if (eventSource
== checkbox_published
) {
191 ((Taxon
)getEntity()).setPublish(checkbox_published
.getSelection());
195 protected void handleToggleableCacheField() {
196 boolean pushedState
= toggleable_cache
.getState();
198 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
199 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
, checkbox_unplaced
, checkbox_excluded
}));
200 updateToggleableCacheField();