Project

General

Profile

Download (5.61 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
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.
9
 */
10

    
11
package eu.etaxonomy.taxeditor.ui.section.name;
12

    
13
import java.util.Arrays;
14

    
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;
24

    
25
/**
26
 * <p>
27
 * AuthorshipDetailElement class.
28
 * </p>
29
 *
30
 * @author n.hoffmann
31
 * @created Mar 4, 2010
32
 * @version 1.0
33
 */
34
public class AuthorshipDetailElement extends
35
	AbstractIdentifiableEntityDetailElement<NonViralName> {
36

    
37
    private EntitySelectionElement<TeamOrPersonBase> selectionExBasionymAuthor;
38
    private EntitySelectionElement<TeamOrPersonBase> selectionBasionymAuthor;
39
    private EntitySelectionElement<TeamOrPersonBase> selectionExCombinationAuthor;
40
    private EntitySelectionElement<TeamOrPersonBase> selectionCombinationAuthor;
41
	/**
42
	 * <p>
43
	 * Constructor for AuthorshipDetailElement.
44
	 * </p>
45
	 *
46
	 * @param cdmFormFactory
47
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
48
	 *            object.
49
	 * @param formElement
50
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
51
	 *            object.
52
	 * @param style
53
	 *            a int.
54
	 */
55
	public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
56
			ICdmFormElement formElement, int style) {
57
		super(cdmFormFactory, formElement);
58
	}
59

    
60
	/** {@inheritDoc} */
61
	@Override
62
	protected void createControls(ICdmFormElement formElement,
63
			NonViralName entity, int style) {
64
	    if (isAdvancedView){
65
	        toggleable_cache = formFactory.createToggleableTextField(this,
66
				"Authorship Cache", entity.getAuthorshipCache(),
67
				entity.isProtectedAuthorshipCache(), style);
68
		    //TODO RL
69
            if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
70
                toggleable_cache.setVisible(false);
71
            }
72
	    }
73

    
74
		selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
75
				getConversationHolder(),
76
				formElement, "Author",
77
				entity.getCombinationAuthorship(),
78
				EntitySelectionElement.ALL, style);
79
		addElement(selectionCombinationAuthor);
80
		selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
81
				getConversationHolder(),
82
				formElement, "Ex Author",
83
				entity.getExCombinationAuthorship(),
84
				EntitySelectionElement.ALL, style);
85
		addElement(selectionExCombinationAuthor);
86
		selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
87
                formElement, "Basionym Author", entity.getBasionymAuthorship(),
88
                EntitySelectionElement.ALL, style);
89
		addElement(selectionBasionymAuthor);
90
		selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
91
		        formElement, "Ex Basionym Author", entity.getExBasionymAuthorship(),
92
		        EntitySelectionElement.ALL, style);
93

    
94
		addElement(selectionExBasionymAuthor);
95
	}
96

    
97
	/** {@inheritDoc} */
98
	@Override
99
	public void updateContent() {
100
		if (getEntity() == null) {
101
			setEntity(NonViralName.NewInstance(null));
102
		}
103

    
104
		super.updateContent();
105
		if (toggleable_cache != null){
106
    		toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
107

    
108

    
109
    		if (this.isIrrelevant()) {
110
    			setIrrelevant(isIrrelevant());
111
    		} else {
112
    			setIrrelevant(toggleable_cache.getState(),
113
    					Arrays.asList(new Object[] { toggleable_cache }));
114
    		}
115
		}
116
	}
117

    
118
	/** {@inheritDoc} */
119
	@Override
120
	public void handleEvent(Object eventSource) {
121
		if (eventSource == toggleable_cache) {
122
			getEntity().setAuthorshipCache(toggleable_cache.getText(),
123
					toggleable_cache.getState());
124
			if (!isIrrelevant()){
125
				setIrrelevant(toggleable_cache.getState(),
126
						Arrays.asList(new Object[] { toggleable_cache }));
127
			}
128
		} else if (eventSource == selectionCombinationAuthor) {
129
			getEntity().setCombinationAuthorship(
130
					selectionCombinationAuthor.getSelection());
131
		} else if (eventSource == selectionExCombinationAuthor) {
132
			getEntity().setExCombinationAuthorship(
133
					selectionExCombinationAuthor.getSelection());
134
		} else if (eventSource == selectionBasionymAuthor) {
135
			getEntity().setBasionymAuthorship(
136
					selectionBasionymAuthor.getSelection());
137
		} else if (eventSource == selectionExBasionymAuthor) {
138
			getEntity().setExBasionymAuthorship(
139
					selectionExBasionymAuthor.getSelection());
140
		}
141

    
142
//		if (eventSource != toggleable_cache) {
143
//			toggleable_cache.setText(getEntity().getAuthorshipCache());
144
//		}
145

    
146
//		 we have to notify the parent if this is embedded in the nonviral name
147
//		 section
148
//		 maybe we can handle this a little bit more elegant
149
//		if (getParentElement() instanceof AbstractCdmDetailSection)
150
			firePropertyChangeEvent(new CdmPropertyChangeEvent(
151
					getParentElement(), null));
152
	}
153

    
154
	@Override
155
	public void updateToggleableCacheField() {
156
	    if (toggleable_cache != null){
157
    		if(! getEntity().isProtectedAuthorshipCache()){
158
    			toggleable_cache.setText(getEntity().getAuthorshipCache());
159
    		}
160
	    }
161
	}
162
}
(2-2/25)