2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
;
11 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
12 import org
.eclipse
.swt
.SWT
;
14 import eu
.etaxonomy
.cdm
.model
.taxon
.SecundumSource
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
18 import eu
.etaxonomy
.cdm
.persistence
.permission
.Role
;
19 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
20 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
21 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
22 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.SecundumSourceElement
;
32 * @created Feb 26, 2010
34 public class TaxonBaseDetailElement
extends AbstractIdentifiableEntityDetailElement
<TaxonBase
<?
>> {
36 private CheckboxElement checkbox_doubtful
;
38 private CheckboxElement checkbox_useNameCache
;
40 // private EntitySelectionElement<Reference> selection_secundum;
41 private SecundumSourceElement secElement
;
44 private TextWithLabelElement text_appendedPhrase
;
46 private CheckboxElement checkbox_published
;
48 private TermComboElement
<SynonymType
> combo_relationshipType
;
50 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
51 ICdmFormElement formElement
, int style
) {
52 super(cdmFormFactory
, formElement
);
56 protected void createControls(ICdmFormElement formElement
, TaxonBase
<?
> entity
, int style
) {
58 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
59 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
60 "Title Cache", entity
.getTitleCache(),
61 entity
.isProtectedTitleCache(), style
);
63 text_appendedPhrase
= formFactory
.createTextWithLabelElement(
64 formElement
, "Appended Phrase", entity
.getAppendedPhrase(),
67 secElement
= formFactory
.createSecundumSourceElement(formElement
, null, "Secundum");
69 secElement
.setCdmEntity(entity
);
70 if (entity
.getSecSource() == null){
71 SecundumSource source
= SecundumSource
.NewSecundumInstance(entity
);
72 entity
.setSecSource(source
);
73 secElement
.setEntity(source
);
75 secElement
.setEntity(entity
.getSecSource());
78 if (config
!= null && !config
.isSecEnabled()){
79 secElement
.setEnabled(false);
83 checkbox_useNameCache
= formFactory
.createCheckbox(formElement
,
84 "Exclude Authorship", entity
.isUseNameCache(), style
);
85 checkbox_doubtful
= formFactory
.createCheckbox(formElement
,
86 entity
.getClass().getSimpleName() + " is doubtful", entity
.isDoubtful(), style
);
89 checkbox_published
= formFactory
.createCheckbox(formElement
,
90 entity
.getClass().getSimpleName()+" is published", entity
.isPublish(), style
);
94 registerCacheRelevance(checkbox_doubtful
);
95 registerCacheRelevance(checkbox_useNameCache
);
96 registerCacheRelevance(secElement
);
97 registerCacheRelevance(text_appendedPhrase
);
98 registerCacheRelevance(combo_relationshipType
);
101 private void updateCheckboxPublish() {
102 checkbox_published
.setEnabled(
103 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
109 protected void updateControlStates() {
110 super.updateControlStates();
111 updateCheckboxPublish();
115 protected void updateContent() {
116 super.updateContent();
117 toggleable_cache
.setCacheEnabled(getEntity().isProtectedTitleCache());
118 updateCacheRelevance();
122 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
123 String title
= getEntity().generateTitle();
124 getEntity().setTitleCache(title
);
125 super.handleTitleCacheRelevantChange(event
);
129 public void handleEvent(Object eventSource
) {
130 if (eventSource
== toggleable_cache
) {
131 handleToggleableCacheField();
132 } else if (eventSource
== checkbox_doubtful
) {
133 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
134 } else if (eventSource
== checkbox_useNameCache
) {
135 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
136 } else if (eventSource
== secElement
) {
137 getEntity().setSecSource(secElement
.getEntity());
138 } else if (eventSource
== text_appendedPhrase
) {
139 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
140 } else if (eventSource
== checkbox_published
) {
141 getEntity().setPublish(checkbox_published
.getSelection());
142 } else if(eventSource
== combo_relationshipType
){
143 ((Synonym
) getEntity()).setType(combo_relationshipType
.getSelection());
144 //#7334/5 removed pro parte and partial as they are handled as concept relationships now
145 // } else if(eventSource == checkPartial){
146 // ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
147 // } else if(eventSource == checkProParte){
148 // ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
153 protected void handleToggleableCacheField() {
154 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
155 updateCacheRelevance();
156 updateToggleableCacheField();
160 public void refresh() {