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
.EnumComboElement
;
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 EnumComboElement
<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
);
88 checkbox_published
= formFactory
.createCheckbox(formElement
,
89 entity
.getClass().getSimpleName()+" is published", entity
.isPublish(), style
);
92 registerCacheRelevance(checkbox_doubtful
);
93 registerCacheRelevance(checkbox_useNameCache
);
94 registerCacheRelevance(secElement
);
95 registerCacheRelevance(text_appendedPhrase
);
96 registerCacheRelevance(combo_relationshipType
);
99 private void updateCheckboxPublish() {
100 checkbox_published
.setEnabled(
101 CdmStore
.currentAuthentiationHasOneOfRoles(Role
.ROLE_PUBLISH
, Role
.ROLE_ADMIN
)
106 protected void updateControlStates() {
107 super.updateControlStates();
108 updateCheckboxPublish();
112 protected void updateContent() {
113 super.updateContent();
114 toggleable_cache
.setCacheEnabled(getEntity().isProtectedTitleCache());
115 updateCacheRelevance();
119 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event
) {
120 String title
= getEntity().generateTitle();
121 getEntity().setTitleCache(title
);
122 super.handleTitleCacheRelevantChange(event
);
126 public void handleEvent(Object eventSource
) {
127 if (eventSource
== toggleable_cache
) {
128 handleToggleableCacheField();
129 } else if (eventSource
== checkbox_doubtful
) {
130 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
131 } else if (eventSource
== checkbox_useNameCache
) {
132 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
133 } else if (eventSource
== secElement
) {
134 getEntity().setSecSource(secElement
.getEntity());
135 } else if (eventSource
== text_appendedPhrase
) {
136 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
137 } else if (eventSource
== checkbox_published
) {
138 getEntity().setPublish(checkbox_published
.getSelection());
139 } else if(eventSource
== combo_relationshipType
){
140 ((Synonym
) getEntity()).setType(combo_relationshipType
.getSelection());
141 //#7334/5 removed pro parte and partial as they are handled as concept relationships now
142 // } else if(eventSource == checkPartial){
143 // ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
144 // } else if(eventSource == checkProParte){
145 // ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
150 protected void handleToggleableCacheField() {
151 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
152 updateCacheRelevance();
153 updateToggleableCacheField();
157 public void refresh() {
163 public void fillFields() {
165 if (!(checkbox_doubtful
.getSelection() == getEntity().isDoubtful())) {
166 checkbox_doubtful
.setSelection(getEntity().isDoubtful());
168 if (!(checkbox_useNameCache
.getSelection() == getEntity().isUseNameCache())) {
169 checkbox_useNameCache
.setSelection(getEntity().isUseNameCache());
171 if (!secElement
.getEntity().equals(getEntity().getSecSource())) {
172 secElement
.fillFields();
174 if (getEntity().getAppendedPhrase()!= null && !getEntity().getAppendedPhrase().equals(text_appendedPhrase
.getText())) {
175 text_appendedPhrase
.setText(getEntity().getAppendedPhrase());
177 if (!(checkbox_published
.getSelection() == getEntity().isPublish())) {
178 checkbox_published
.setSelection(getEntity().isPublish());
180 if (combo_relationshipType
!= null && !((Synonym
) getEntity()).getType().equals(combo_relationshipType
.getSelection())) {
181 combo_relationshipType
.setSelection(((Synonym
) getEntity()).getType());