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
.section
.name
.SynonymRelationshipDetailSection
;
34 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
38 * TaxonBaseDetailElement class.
42 * @created Feb 26, 2010
45 public class TaxonBaseDetailElement
extends AbstractIdentifiableEntityDetailElement
<TaxonBase
> {
47 private CheckboxElement checkbox_doubtful
;
49 private CheckboxElement checkbox_useNameCache
;
51 private EntitySelectionElement
<Reference
> selection_secundum
;
53 private TextWithLabelElement text_appendedPhrase
;
55 private CheckboxElement checkbox_excluded
;
57 private CheckboxElement checkbox_unplaced
;
59 private CheckboxElement checkbox_published
;
61 private SynonymRelationshipDetailSection sectionSynonymRelationship
;
65 * Constructor for TaxonBaseDetailElement.
68 * @param cdmFormFactory
69 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
71 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
75 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
76 ICdmFormElement formElement
, int style
) {
77 super(cdmFormFactory
, formElement
);
82 protected void createControls(ICdmFormElement formElement
, TaxonBase entity
, int style
) {
83 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
84 "Title Cache", entity
.getTitleCache(),
85 entity
.isProtectedTitleCache(), style
);
89 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
90 toggleable_cache
.setVisible(false);
92 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
93 text_appendedPhrase
= formFactory
.createTextWithLabelElement(
94 formElement
, "Appended Phrase", entity
.getAppendedPhrase(),
98 selection_secundum
= formFactory
.createSelectionElement(Reference
.class,
99 getConversationHolder(), formElement
, "Secundum",
100 entity
.getSec(), EntitySelectionElement
.ALL
,
104 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)) {
105 checkbox_useNameCache
= formFactory
.createCheckbox(formElement
,
106 "Exclude Authorship", entity
.isUseNameCache(), style
);
108 if (entity
instanceof Taxon
) {
109 checkbox_excluded
= formFactory
.createCheckbox(formElement
,
110 "Taxon is excluded", ((Taxon
) entity
).isExcluded(), style
);
111 checkbox_unplaced
= formFactory
.createCheckbox(formElement
,
112 "Taxon is unplaced", ((Taxon
) entity
).isUnplaced(), style
);
115 checkbox_doubtful
= formFactory
.createCheckbox(formElement
,
116 entity
.getClass().getSimpleName() + " is doubtful", entity
.isDoubtful(), style
);
119 if (entity
instanceof Taxon
) {
120 checkbox_published
= formFactory
.createCheckbox(formElement
,
121 "Taxon is published", ((Taxon
) entity
).isPublish(), style
);
125 if(entity
instanceof Synonym
){
126 sectionSynonymRelationship
= formFactory
.createSynonymRelationshipDetailSection(getConversationHolder(), formElement
, ExpandableComposite
.TWISTIE
);
127 sectionSynonymRelationship
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
128 sectionSynonymRelationship
.setEntity((Synonym
) entity
);
132 private void updateCheckboxPublish() {
133 if(getEntity() instanceof Taxon
){
134 checkbox_published
.setEnabled(
135 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
141 protected void updateControlStates() {
142 super.updateControlStates();
143 updateCheckboxPublish();
148 protected void updateContent() {
149 super.updateContent();
150 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
151 setIrrelevant(toggleable_cache
.getState(),
152 Arrays
.asList(new Object
[] { toggleable_cache
}));
156 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
157 String title
= getEntity().generateTitle();
158 getEntity().setTitleCache(title
);
159 super.handleTitleCacheRelevantChange(event
);
164 public void handleEvent(Object eventSource
) {
165 if (eventSource
== toggleable_cache
) {
166 handleToggleableCacheField();
167 } else if (eventSource
== checkbox_doubtful
) {
168 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
169 } else if (eventSource
== checkbox_useNameCache
) {
170 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
171 } else if (eventSource
== selection_secundum
) {
172 getEntity().setSec(selection_secundum
.getSelection());
173 } else if (eventSource
== text_appendedPhrase
) {
174 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
175 } else if (eventSource
== checkbox_excluded
) {
176 ((Taxon
) getEntity()).setExcluded(checkbox_excluded
.getSelection());
177 } else if (eventSource
== checkbox_unplaced
) {
178 ((Taxon
) getEntity()).setUnplaced(checkbox_unplaced
.getSelection());
179 } else if (eventSource
== checkbox_published
) {
180 ((Taxon
)getEntity()).setPublish(checkbox_published
.getSelection());
184 protected void handleToggleableCacheField() {
185 boolean pushedState
= toggleable_cache
.getState();
187 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
188 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, text_appendedPhrase
, checkbox_published
, checkbox_unplaced
, checkbox_excluded
}));
189 updateToggleableCacheField();