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
.name
;
13 import java
.util
.Arrays
;
15 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
17 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
18 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
19 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
27 * AuthorshipDetailElement class.
31 * @created Mar 4, 2010
34 public class AuthorshipDetailElement
extends
35 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
37 private EntitySelectionElement
<TeamOrPersonBase
> selectionExBasionymAuthor
;
38 private EntitySelectionElement
<TeamOrPersonBase
> selectionBasionymAuthor
;
39 private EntitySelectionElement
<TeamOrPersonBase
> selectionExCombinationAuthor
;
40 private EntitySelectionElement
<TeamOrPersonBase
> selectionCombinationAuthor
;
43 * Constructor for AuthorshipDetailElement.
46 * @param cdmFormFactory
47 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
50 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
56 ICdmFormElement formElement
, int style
) {
57 super(cdmFormFactory
, formElement
);
62 protected void createControls(ICdmFormElement formElement
,
63 NonViralName entity
, int style
) {
64 toggleable_cache
= formFactory
.createToggleableTextField(this,
65 "Authorship Cache", entity
.getAuthorshipCache(),
66 entity
.isProtectedAuthorshipCache(), style
);
69 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
70 toggleable_cache
.setVisible(false);
72 selectionCombinationAuthor
= formFactory
.createSelectionElement(TeamOrPersonBase
.class,
73 getConversationHolder(),
74 formElement
, "Author",
75 entity
.getCombinationAuthorship(),
76 EntitySelectionElement
.ALL
, style
);
77 addElement(selectionCombinationAuthor
);
78 selectionExCombinationAuthor
= formFactory
.createSelectionElement(TeamOrPersonBase
.class,
79 getConversationHolder(),
80 formElement
, "Ex Author",
81 entity
.getExCombinationAuthorship(),
82 EntitySelectionElement
.ALL
, style
);
83 addElement(selectionExCombinationAuthor
);
84 selectionBasionymAuthor
= formFactory
.createSelectionElement(TeamOrPersonBase
.class, getConversationHolder(),
85 formElement
, "Basionym Author", entity
.getBasionymAuthorship(),
86 EntitySelectionElement
.ALL
, style
);
87 addElement(selectionBasionymAuthor
);
88 selectionExBasionymAuthor
= formFactory
.createSelectionElement(TeamOrPersonBase
.class, getConversationHolder(),
89 formElement
, "Ex Basionym Author", entity
.getExBasionymAuthorship(),
90 EntitySelectionElement
.ALL
, style
);
92 addElement(selectionExBasionymAuthor
);
97 public void updateContent() {
98 if (getEntity() == null) {
99 setEntity(NonViralName
.NewInstance(null));
102 super.updateContent();
103 toggleable_cache
.setEnabled(getEntity().isProtectedAuthorshipCache());
105 if (this.isIrrelevant()) {
106 setIrrelevant(isIrrelevant());
108 setIrrelevant(toggleable_cache
.getState(),
109 Arrays
.asList(new Object
[] { toggleable_cache
}));
115 public void handleEvent(Object eventSource
) {
116 if (eventSource
== toggleable_cache
) {
117 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
118 toggleable_cache
.getState());
119 if (!isIrrelevant()){
120 setIrrelevant(toggleable_cache
.getState(),
121 Arrays
.asList(new Object
[] { toggleable_cache
}));
123 } else if (eventSource
== selectionCombinationAuthor
) {
124 getEntity().setCombinationAuthorship(
125 selectionCombinationAuthor
.getSelection());
126 } else if (eventSource
== selectionExCombinationAuthor
) {
127 getEntity().setExCombinationAuthorship(
128 selectionExCombinationAuthor
.getSelection());
129 } else if (eventSource
== selectionBasionymAuthor
) {
130 getEntity().setBasionymAuthorship(
131 selectionBasionymAuthor
.getSelection());
132 } else if (eventSource
== selectionExBasionymAuthor
) {
133 getEntity().setExBasionymAuthorship(
134 selectionExBasionymAuthor
.getSelection());
137 // if (eventSource != toggleable_cache) {
138 // toggleable_cache.setText(getEntity().getAuthorshipCache());
141 // we have to notify the parent if this is embedded in the nonviral name
143 // maybe we can handle this a little bit more elegant
144 // if (getParentElement() instanceof AbstractCdmDetailSection)
145 firePropertyChangeEvent(new CdmPropertyChangeEvent(
146 getParentElement(), null));
150 public void updateToggleableCacheField() {
151 if(! getEntity().isProtectedAuthorshipCache()){
152 toggleable_cache
.setText(getEntity().getAuthorshipCache());