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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Arrays
;
14 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
15 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
16 import eu
.etaxonomy
.cdm
.model
.name
.IZoologicalName
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
19 import eu
.etaxonomy
.taxeditor
.event
.EventUtility
;
20 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
21 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
22 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
32 * AuthorshipDetailElement class.
36 * @created Mar 4, 2010
39 public class AuthorshipDetailElement
extends
40 AbstractIdentifiableEntityDetailElement
<INonViralName
> {
42 private EntitySelectionElement
<TeamOrPersonBase
> selectionExBasionymAuthor
;
43 private EntitySelectionElement
<TeamOrPersonBase
> selectionBasionymAuthor
;
44 private EntitySelectionElement
<TeamOrPersonBase
> selectionExCombinationAuthor
;
45 private EntitySelectionElement
<TeamOrPersonBase
> selectionCombinationAuthor
;
47 private NumberWithLabelElement text_publicationYear
;
48 private NumberWithLabelElement text_originalPublicationYear
;
51 * Constructor for AuthorshipDetailElement.
54 * @param cdmFormFactory
55 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
58 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
63 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
64 ICdmFormElement formElement
, int style
) {
65 super(cdmFormFactory
, formElement
);
70 protected void createControls(ICdmFormElement formElement
,
71 INonViralName entity
, int style
) {
72 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
73 if (!config
.isSimpleDetailsViewActivated() || config
.isAuthorCacheActivated()){
74 toggleable_cache
= formFactory
.createToggleableTextField(this,
75 "Authorship Cache", entity
.getAuthorshipCache(),
76 entity
.isProtectedAuthorshipCache(), style
);
77 addElement(toggleable_cache
);
79 NomenclaturalCode code
= entity
.getNameType();
81 if (!config
.isSimpleDetailsViewActivated() || config
.isAuthorshipSectionActivated()){
82 selectionCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
83 getConversationHolder(),
84 formElement
, "Author",
85 entity
.getCombinationAuthorship(),
86 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
87 addElement(selectionCombinationAuthor
);
88 selectionExCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
89 getConversationHolder(),
90 formElement
, "Ex Author",
91 entity
.getExCombinationAuthorship(),
92 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
93 addElement(selectionExCombinationAuthor
);
95 if (code
.equals(NomenclaturalCode
.ICZN
)){
96 text_publicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Publication Year", ((IZoologicalName
)entity
).getPublicationYear(), style
);
100 selectionBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class, getConversationHolder(),
101 formElement
, "Basionym Author", entity
.getBasionymAuthorship(),
102 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
103 addElement(selectionBasionymAuthor
);
104 selectionExBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class, getConversationHolder(),
105 formElement
, "Ex Basionym Author",entity
.getExBasionymAuthorship(),
106 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
108 addElement(selectionExBasionymAuthor
);
110 if (code
.equals(NomenclaturalCode
.ICZN
)){
112 text_originalPublicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Orig. Publication Year", ((IZoologicalName
)entity
).getOriginalPublicationYear(), style
);
123 public void updateContent() {
124 if (getEntity() == null) {
125 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
128 super.updateContent();
129 if (toggleable_cache
!= null){
130 toggleable_cache
.setEnabled(getEntity().isProtectedAuthorshipCache());
133 if (this.isIrrelevant()) {
134 setIrrelevant(isIrrelevant());
136 setIrrelevant(toggleable_cache
.getState(),
137 Arrays
.asList(new Object
[] { toggleable_cache
}));
144 public void handleEvent(Object eventSource
) {
145 if (eventSource
== toggleable_cache
) {
146 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
147 toggleable_cache
.getState());
148 if (!isIrrelevant()){
149 setIrrelevant(toggleable_cache
.getState(),
150 Arrays
.asList(new Object
[] { toggleable_cache
}));
152 } else if (eventSource
== selectionCombinationAuthor
) {
153 getEntity().setCombinationAuthorship(
154 selectionCombinationAuthor
.getSelection());
155 } else if (eventSource
== selectionExCombinationAuthor
) {
156 getEntity().setExCombinationAuthorship(
157 selectionExCombinationAuthor
.getSelection());
158 } else if (eventSource
== selectionBasionymAuthor
) {
159 getEntity().setBasionymAuthorship(
160 selectionBasionymAuthor
.getSelection());
161 } else if (eventSource
== selectionExBasionymAuthor
) {
162 getEntity().setExBasionymAuthorship(
163 selectionExBasionymAuthor
.getSelection());
164 } else if (eventSource
== text_originalPublicationYear
) {
165 ((IZoologicalName
)getEntity()).setOriginalPublicationYear(text_originalPublicationYear
.getInteger());
166 } else if (eventSource
== text_publicationYear
) {
167 ((IZoologicalName
)getEntity()).setPublicationYear(text_publicationYear
.getInteger());
170 // if (eventSource != toggleable_cache) {
171 // toggleable_cache.setText(getEntity().getAuthorshipCache());
174 // we have to notify the parent if this is embedded in the nonviral name
176 // maybe we can handle this a little bit more elegant
177 // if (getParentElement() instanceof AbstractCdmDetailSection)
178 firePropertyChangeEvent(new CdmPropertyChangeEvent(
179 getParentElement(), null));
180 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
, this.getEntity());
184 public void updateToggleableCacheField() {
185 if (toggleable_cache
!= null){
186 if(! getEntity().isProtectedAuthorshipCache()){
187 toggleable_cache
.setText(getEntity().getAuthorshipCache());