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
);
115 if (entity
instanceof Taxon
) {
116 checkbox_excluded
= formFactory
.createCheckbox(formElement
,
117 "Taxon is excluded", ((Taxon
) entity
).isExcluded(), style
);
118 checkbox_unplaced
= formFactory
.createCheckbox(formElement
,
119 "Taxon is unplaced", ((Taxon
) entity
).isUnplaced(), style
);
122 checkbox_doubtful
= formFactory
.createCheckbox(formElement
,
123 entity
.getClass().getSimpleName() + " is doubtful", entity
.isDoubtful(), style
);
126 if (entity
instanceof Taxon
) {
127 checkbox_published
= formFactory
.createCheckbox(formElement
,
128 "Taxon is published", ((Taxon
) entity
).isPublish(), style
);
132 // if(entity instanceof Synonym){
133 // sectionSynonymRelationship = formFactory.createSynonymRelationshipDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
134 // sectionSynonymRelationship.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
135 // sectionSynonymRelationship.setEntity((Synonym) entity);
139 private void updateCheckboxPublish() {
140 if(getEntity() instanceof Taxon
){
141 checkbox_published
.setEnabled(
142 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
148 protected void updateControlStates() {
149 super.updateControlStates();
150 updateCheckboxPublish();
155 protected void updateContent() {
156 super.updateContent();
157 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
158 setIrrelevant(toggleable_cache
.getState(),
159 Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
, checkbox_unplaced
, checkbox_excluded
}));
163 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
164 String title
= getEntity().generateTitle();
165 getEntity().setTitleCache(title
);
166 super.handleTitleCacheRelevantChange(event
);
171 public void handleEvent(Object eventSource
) {
172 if (eventSource
== toggleable_cache
) {
173 handleToggleableCacheField();
174 } else if (eventSource
== checkbox_doubtful
) {
175 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
176 } else if (eventSource
== checkbox_useNameCache
) {
177 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
178 } else if (eventSource
== selection_secundum
) {
179 getEntity().setSec(selection_secundum
.getSelection());
180 } else if (eventSource
== text_appendedPhrase
) {
181 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
182 }else if (eventSource
== text_secundum_microreference
) {
183 getEntity().setSecMicroReference(text_secundum_microreference
.getText());
184 }else if (eventSource
== checkbox_excluded
) {
185 ((Taxon
) getEntity()).setExcluded(checkbox_excluded
.getSelection());
186 } else if (eventSource
== checkbox_unplaced
) {
187 ((Taxon
) getEntity()).setUnplaced(checkbox_unplaced
.getSelection());
188 } else if (eventSource
== checkbox_published
) {
189 ((Taxon
)getEntity()).setPublish(checkbox_published
.getSelection());
193 protected void handleToggleableCacheField() {
194 boolean pushedState
= toggleable_cache
.getState();
196 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
197 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
, checkbox_unplaced
, checkbox_excluded
}));
198 updateToggleableCacheField();