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
.common
.TermType
;
19 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
24 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.Role
;
25 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
26 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
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 TermComboElement
<SynonymType
> combo_relationshipType
;
56 private CheckboxElement checkProParte
;
57 private CheckboxElement checkPartial
;
59 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
60 ICdmFormElement formElement
, int style
) {
61 super(cdmFormFactory
, formElement
);
66 protected void createControls(ICdmFormElement formElement
, TaxonBase entity
, int style
) {
67 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
68 "Title Cache", entity
.getTitleCache(),
69 entity
.isProtectedTitleCache(), style
);
73 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
74 toggleable_cache
.setVisible(false);
76 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
77 text_appendedPhrase
= formFactory
.createTextWithLabelElement(
78 formElement
, "Appended Phrase", entity
.getAppendedPhrase(),
83 selection_secundum
= formFactory
.createSelectionElement(Reference
.class,
84 getConversationHolder(), formElement
, "Secundum",
85 entity
.getSec(), EntitySelectionElement
.ALL
,
88 text_secundum_microreference
= formFactory
.createTextWithLabelElement(
89 formElement
, "Detail",
90 entity
.getSecMicroReference(),null,
94 if (!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)) {
95 checkbox_useNameCache
= formFactory
.createCheckbox(formElement
,
96 "Exclude Authorship", entity
.isUseNameCache(), style
);
97 checkbox_doubtful
= formFactory
.createCheckbox(formElement
,
98 entity
.getClass().getSimpleName() + " is doubtful", entity
.isDoubtful(), style
);
101 if (entity
instanceof Taxon
) {
102 checkbox_published
= formFactory
.createCheckbox(formElement
,
103 "Taxon is published", ((Taxon
) entity
).isPublish(), style
);
106 if(entity
instanceof Synonym
){
107 combo_relationshipType
= formFactory
.createDefinedTermComboElement(TermType
.SynonymType
, formElement
, "Synonym Type", ((Synonym
) entity
).getType(), style
);
108 checkProParte
= formFactory
.createCheckbox(formElement
, "Pro Parte Synonym", ((Synonym
) entity
).isProParte(), style
);
109 checkPartial
= formFactory
.createCheckbox(formElement
, "Partial Synonym", ((Synonym
) entity
).isPartial(), style
);
113 private void updateCheckboxPublish() {
114 if(getEntity() instanceof Taxon
){
115 checkbox_published
.setEnabled(
116 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
122 protected void updateControlStates() {
123 super.updateControlStates();
124 updateCheckboxPublish();
129 protected void updateContent() {
130 super.updateContent();
131 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
132 setIrrelevant(toggleable_cache
.getState(),
133 Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
}));
137 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
138 String title
= getEntity().generateTitle();
139 getEntity().setTitleCache(title
);
140 super.handleTitleCacheRelevantChange(event
);
145 public void handleEvent(Object eventSource
) {
146 if (eventSource
== toggleable_cache
) {
147 handleToggleableCacheField();
148 } else if (eventSource
== checkbox_doubtful
) {
149 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
150 } else if (eventSource
== checkbox_useNameCache
) {
151 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
152 } else if (eventSource
== selection_secundum
) {
153 getEntity().setSec(selection_secundum
.getSelection());
154 } else if (eventSource
== text_appendedPhrase
) {
155 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
156 } else if (eventSource
== text_secundum_microreference
) {
157 getEntity().setSecMicroReference(text_secundum_microreference
.getText());
158 } else if (eventSource
== checkbox_published
) {
159 ((Taxon
)getEntity()).setPublish(checkbox_published
.getSelection());
160 } else if(eventSource
== combo_relationshipType
){
161 ((Synonym
) getEntity()).setType(combo_relationshipType
.getSelection());
162 } else if(eventSource
== checkPartial
){
163 ((Synonym
) getEntity()).setPartial(checkPartial
.getSelection());
164 } else if(eventSource
== checkProParte
){
165 ((Synonym
) getEntity()).setProParte(checkProParte
.getSelection());
169 protected void handleToggleableCacheField() {
170 boolean pushedState
= toggleable_cache
.getState();
172 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
173 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, checkbox_published
}));
174 updateToggleableCacheField();