Project

General

Profile

Download (5.14 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.LsidWithExceptionLabelElement;
22
import eu.etaxonomy.taxeditor.ui.element.OrcidWithLabelElement;
23
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
24
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
25
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
26

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

    
37
	private TextWithLabelElement text_nomenclaturalTitle;
38
	private TextWithLabelElement text_firstname;
39
	private TextWithLabelElement text_lastname;
40
	private TextWithLabelElement text_prefix;
41
	private TextWithLabelElement text_suffix;
42
	private TextWithLabelElement text_initials;
43
	private TimePeriodElement time_lifespan;
44
	private OrcidWithLabelElement text_orcid;
45
    private LsidWithExceptionLabelElement text_lsid;
46
	private Collection<Object> excludeFromIrrelevantToggleableObjects;
47

    
48
	public PersonDetailElement(CdmFormFactory cdmFormFactory,
49
			ICdmFormElement formElement, int style) {
50
		super(cdmFormFactory, formElement);
51
	}
52

    
53
	@Override
54
	protected void createControls(ICdmFormElement formElement, Person entity,
55
			int style) {
56
		setWarnForReferencingObjects(formElement);
57
		toggleable_cache = formFactory.createToggleableTextField(formElement,
58
				"Title Cache", entity.getTitleCache(),
59
				entity.isProtectedTitleCache(), SWT.NULL);
60

    
61
		text_nomenclaturalTitle = formFactory.createTextWithLabelElement(
62
				formElement, "Abbrev. Title", entity.getNomenclaturalTitle(),
63
				SWT.NULL);
64
		text_lastname = formFactory.createTextWithLabelElement(formElement,
65
                "Familiy Name", entity.getFamilyName(), SWT.NULL);
66
		text_firstname = formFactory.createTextWithLabelElement(formElement,
67
				"Other/ Given Names", entity.getGivenName(), SWT.NULL);
68
		text_initials = formFactory.createTextWithLabelElement(formElement,
69
				"Initials", entity.getInitials(), SWT.NULL);
70
		text_prefix = formFactory.createTextWithLabelElement(formElement,
71
				"Prefix", entity.getPrefix(), SWT.NULL);
72
		time_lifespan = formFactory.createTimePeriodElement(formElement, "Lifespan", entity.getLifespan(), SWT.NULL);
73
		text_orcid = formFactory.createOrcidWithLabelElement(formElement, "ORCID", entity.getOrcid(), SWT.NULL);
74
		text_lsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), SWT.NULL);
75
		getLayoutComposite().layout();
76

    
77
	}
78

    
79
	@Override
80
	protected void updateContent() {
81
		super.updateContent();
82

    
83
		excludeFromIrrelevantToggleableObjects = Arrays.asList(new Object[] {
84
				toggleable_cache, text_nomenclaturalTitle });
85

    
86
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
87
		setIrrelevant(toggleable_cache.getState(),
88
				excludeFromIrrelevantToggleableObjects);
89
	}
90

    
91
	@Override
92
	public void handleEvent(Object eventSource) {
93
		if (eventSource == toggleable_cache) {
94
			handleToggleableCacheField();
95

    
96
		} else if (eventSource == text_nomenclaturalTitle) {
97
			getEntity()
98
					.setNomenclaturalTitle(text_nomenclaturalTitle.getText());
99
		} else if (eventSource == text_firstname) {
100
			getEntity().setGivenName(text_firstname.getText());
101
		}else if (eventSource == text_initials) {
102
			getEntity().setInitials(text_initials.getText());
103
		}else if (eventSource == text_lastname) {
104
			getEntity().setFamilyName(text_lastname.getText());
105
		} else if (eventSource == text_prefix) {
106
			getEntity().setPrefix(text_prefix.getText());
107
		} else if (eventSource == text_suffix) {
108
			getEntity().setSuffix(text_suffix.getText());
109
		}else if (eventSource == text_orcid) {
110
            getEntity().setOrcid(text_orcid.parseText());
111
        }else if (eventSource == text_lsid) {
112
            getEntity().setLsid(text_lsid.parseText());
113
        }else if (eventSource == time_lifespan) {
114
            getEntity().setLifespan(time_lifespan.getTimePeriod());
115
        }
116

    
117
		//if (eventSource != toggleable_cache) {
118
		if (!getEntity().isProtectedTitleCache()){
119
			toggleable_cache.setText(getEntity().generateTitle());
120
		}
121

    
122
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
123
	}
124

    
125
	@Override
126
	protected void handleToggleableCacheField() {
127
        boolean pushedState = toggleable_cache.getState();
128
        getEntity().setProtectedTitleCache(pushedState);
129
        getEntity().getTitleCache();
130
        if (pushedState){
131
            getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
132
        }
133
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_nomenclaturalTitle }));
134
        updateToggleableCacheField();
135

    
136
    }
137
}
(4-4/12)