Project

General

Profile

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

    
10
package eu.etaxonomy.taxeditor.ui.section.agent;
11

    
12
import java.util.Arrays;
13
import java.util.Collection;
14

    
15
import org.eclipse.swt.SWT;
16

    
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
22
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
23

    
24
/**
25
 * <p>
26
 * PersonDetailElement class.
27
 * </p>
28
 *
29
 * @author n.hoffmann
30
 * @created Mar 8, 2010
31
 * @version 1.0
32
 */
33
public class PersonDetailElement extends AbstractIdentifiableEntityDetailElement<Person> {
34

    
35
	private TextWithLabelElement text_nomenclaturalTitle;
36
	private TextWithLabelElement text_firstname;
37
	private TextWithLabelElement text_lastname;
38
	private TextWithLabelElement text_prefix;
39
	private TextWithLabelElement text_suffix;
40
	private TextWithLabelElement text_initials;
41

    
42
	private Collection<Object> excludeFromIrrelevantToggleableObjects;
43

    
44
	/**
45
	 * <p>
46
	 * Constructor for PersonDetailElement.
47
	 * </p>
48
	 *
49
	 * @param cdmFormFactory
50
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
51
	 *            object.
52
	 * @param formElement
53
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
54
	 *            object.
55
	 * @param style
56
	 *            a int.
57
	 */
58
	public PersonDetailElement(CdmFormFactory cdmFormFactory,
59
			ICdmFormElement formElement, int style) {
60
		super(cdmFormFactory, formElement);
61
	}
62

    
63
	/** {@inheritDoc} */
64
	@Override
65
	protected void createControls(ICdmFormElement formElement, Person entity,
66
			int style) {
67
		setWarnForReferencingObjects(formElement);
68
		toggleable_cache = formFactory.createToggleableTextField(formElement,
69
				"Title Cache", entity.getTitleCache(),
70
				entity.isProtectedTitleCache(), SWT.NULL);
71

    
72
		text_nomenclaturalTitle = formFactory.createTextWithLabelElement(
73
				formElement, "Abbrev. Title", entity.getNomenclaturalTitle(),
74
				SWT.NULL);
75
		text_lastname = formFactory.createTextWithLabelElement(formElement,
76
                "Familiy Name", entity.getFamilyName(), SWT.NULL);
77
		text_firstname = formFactory.createTextWithLabelElement(formElement,
78
				"Other/ Given Names", entity.getGivenName(), SWT.NULL);
79
		text_initials = formFactory.createTextWithLabelElement(formElement,
80
				"Initials", entity.getInitials(), SWT.NULL);
81
		text_prefix = formFactory.createTextWithLabelElement(formElement,
82
				"Prefix", entity.getPrefix(), SWT.NULL);
83
		text_suffix = formFactory.createTextWithLabelElement(formElement,
84
				"Suffix", entity.getSuffix(), SWT.NULL);
85
	}
86

    
87
	/** {@inheritDoc} */
88
	@Override
89
	protected void updateContent() {
90
		super.updateContent();
91

    
92
		excludeFromIrrelevantToggleableObjects = Arrays.asList(new Object[] {
93
				toggleable_cache, text_nomenclaturalTitle });
94

    
95
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
96
		setIrrelevant(toggleable_cache.getState(),
97
				excludeFromIrrelevantToggleableObjects);
98
	}
99

    
100
	/** {@inheritDoc} */
101
	@Override
102
	public void handleEvent(Object eventSource) {
103
		if (eventSource == toggleable_cache) {
104
			handleToggleableCacheField();
105
		} else if (eventSource == text_nomenclaturalTitle) {
106
			getEntity()
107
					.setNomenclaturalTitle(text_nomenclaturalTitle.getText());
108
		} else if (eventSource == text_firstname) {
109
			getEntity().setGivenName(text_firstname.getText());
110
		}else if (eventSource == text_initials) {
111
			getEntity().setInitials(text_initials.getText());
112
		}else if (eventSource == text_lastname) {
113
			getEntity().setFamilyName(text_lastname.getText());
114
		} else if (eventSource == text_prefix) {
115
			getEntity().setPrefix(text_prefix.getText());
116
		} else if (eventSource == text_suffix) {
117
			getEntity().setSuffix(text_suffix.getText());
118
		}
119

    
120
		//if (eventSource != toggleable_cache) {
121
		if (!getEntity().isProtectedTitleCache()){
122
			toggleable_cache.setText(getEntity().generateTitle());
123
		}
124

    
125
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
126
	}
127

    
128
	@Override
129
	protected void handleToggleableCacheField() {
130
        boolean pushedState = toggleable_cache.getState();
131

    
132
        getEntity().setTitleCache(getEntity().generateTitle(), pushedState);
133
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_nomenclaturalTitle }));
134
        updateToggleableCacheField();
135
    }
136
}
(4-4/12)