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
.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
.taxon
.Taxon
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
20 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
;
21 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
.SelectionType
;
22 import eu
.etaxonomy
.taxeditor
.forms
.CheckboxElement
;
23 import eu
.etaxonomy
.taxeditor
.forms
.ICdmFormElement
;
24 import eu
.etaxonomy
.taxeditor
.forms
.TextWithLabelElement
;
25 import eu
.etaxonomy
.taxeditor
.forms
.ToggleableTextElement
;
26 import eu
.etaxonomy
.taxeditor
.forms
.selection
.ReferenceSelectionElement
;
27 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailElement
;
28 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailSection
;
29 import eu
.etaxonomy
.taxeditor
.section
.name
.NonViralNameDetailElement
;
33 * @created Feb 26, 2010
36 public class TaxonBaseDetailElement
extends AbstractCdmDetailElement
<TaxonBase
>{
38 private CheckboxElement checkbox_doubtful
;
40 private CheckboxElement checkbox_useNameCache
;
42 private ReferenceSelectionElement selection_secundum
;
44 private TextWithLabelElement text_appendedPhrase
;
46 private ToggleableTextElement toggleable_cache
;
48 private CheckboxElement checkbox_excluded
;
50 private CheckboxElement checkbox_unplaced
;
52 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory
,
53 ICdmFormElement formElement
, int style
) {
54 super(cdmFormFactory
, formElement
);
58 protected void createControls(ICdmFormElement formElement
, TaxonBase entity
, int style
){
59 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Title Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache(), style
);
61 checkbox_doubtful
= formFactory
.createCheckbox(formElement
, "Is doubtful", entity
.isDoubtful(), style
);
62 checkbox_useNameCache
= formFactory
.createCheckbox(formElement
, "Exclude Authorship", entity
.isUseNameCache(), style
);
63 selection_secundum
= (ReferenceSelectionElement
) formFactory
.createSelectionElement(SelectionType
.REFERENCE
, getConversationHolder(), formElement
, "Secundum", entity
.getSec(), style
);
64 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", entity
.getAppendedPhrase(), SWT
.NULL
);
66 if(entity
instanceof Taxon
){
67 checkbox_excluded
= formFactory
.createCheckbox(formElement
, "Is excluded", ((Taxon
) entity
).isExcluded(), style
);
68 checkbox_unplaced
= formFactory
.createCheckbox(formElement
, "Is unplaced", ((Taxon
) entity
).isUnplaced(), style
);
73 protected void updateContent() {
74 super.updateContent();
75 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
76 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
80 public void propertyChange(PropertyChangeEvent event
) {
81 Object eventSource
= event
.getSource();
82 if(eventSource
instanceof ICdmFormElement
){
83 ICdmFormElement element
= (ICdmFormElement
) eventSource
;
84 ICdmFormElement parentElement
= element
.getParentElement();
85 if(parentElement
instanceof NonViralNameDetailElement
){
86 String title
= getEntity().generateTitle();
87 getEntity().setTitleCache(title
);
88 toggleable_cache
.setText(title
);
89 if(getParentElement() instanceof AbstractCdmDetailSection
)
90 ((AbstractCdmDetailSection
)getParentElement()).updateTitle();
94 super.propertyChange(event
);
98 public void handleEvent(Object eventSource
) {
99 if(eventSource
.equals(toggleable_cache
)){
100 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
101 // setEnabled(! toggleable_titleCache.getState(), Arrays.asList(new Object[]{toggleable_titleCache}));
102 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
104 else if(eventSource
.equals(checkbox_doubtful
)){
105 getEntity().setDoubtful(checkbox_doubtful
.getSelection());
107 else if(eventSource
.equals(checkbox_useNameCache
)){
108 getEntity().setUseNameCache(checkbox_useNameCache
.getSelection());
110 else if(eventSource
.equals(selection_secundum
)){
111 getEntity().setSec(selection_secundum
.getSelection());
113 else if(eventSource
.equals(text_appendedPhrase
)){
114 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
116 else if(eventSource
== checkbox_excluded
){
117 ((Taxon
) getEntity()).setExcluded(checkbox_excluded
.getSelection());
119 else if(eventSource
== checkbox_unplaced
){
120 ((Taxon
) getEntity()).setUnplaced(checkbox_unplaced
.getSelection());
123 if(eventSource
!= toggleable_cache
){
124 toggleable_cache
.setText(getEntity().getTitleCache());