Project

General

Profile

Download (4.98 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
package eu.etaxonomy.taxeditor.ui.section.agent;
10

    
11
import org.eclipse.swt.SWT;
12

    
13
import eu.etaxonomy.cdm.model.agent.Person;
14
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
15
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
16
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
17
import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
18
import eu.etaxonomy.taxeditor.ui.element.OrcidWithLabelElement;
19
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
20
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
22

    
23
/**
24
 * PersonDetailElement class.
25
 *
26
 * @author n.hoffmann
27
 * @created Mar 8, 2010
28
 */
29
public class PersonDetailElement extends AbstractIdentifiableEntityDetailElement<Person> {
30

    
31
	private TextWithLabelElement text_nomenclaturalTitle;
32
	private TextWithLabelElement text_firstname;
33
	private TextWithLabelElement text_lastname;
34
	private TextWithLabelElement text_prefix;
35
	private TextWithLabelElement text_suffix;
36
	private TextWithLabelElement text_initials;
37
	private TimePeriodElement time_lifespan;
38
	private OrcidWithLabelElement text_orcid;
39
    private LsidWithExceptionLabelElement text_lsid;
40

    
41
	public PersonDetailElement(CdmFormFactory cdmFormFactory,
42
			ICdmFormElement formElement, int style) {
43
		super(cdmFormFactory, formElement);
44
	}
45

    
46
	@Override
47
	protected void createControls(ICdmFormElement formElement, Person entity,
48
			int style) {
49
		setWarnForReferencingObjects(formElement);
50
		toggleable_cache = formFactory.createToggleableTextField(formElement,
51
				"Title Cache", entity.getTitleCache(),
52
				entity.isProtectedTitleCache(), SWT.NULL);
53

    
54
		text_nomenclaturalTitle = formFactory.createTextWithLabelElement(
55
				formElement, "Abbrev. Title", entity.getNomenclaturalTitle(),
56
				SWT.NULL);
57
		text_lastname = formFactory.createTextWithLabelElement(formElement,
58
                "Familiy Name", entity.getFamilyName(), SWT.NULL);
59
		text_firstname = formFactory.createTextWithLabelElement(formElement,
60
				"Other/Given Names", entity.getGivenName(), SWT.NULL);
61
		text_initials = formFactory.createTextWithLabelElement(formElement,
62
				"Initials", entity.getInitials(), SWT.NULL);
63
		text_prefix = formFactory.createTextWithLabelElement(formElement,
64
				"Prefix", entity.getPrefix(), SWT.NULL);
65
		time_lifespan = formFactory.createTimePeriodElement(formElement, "Lifespan", entity.getLifespan(), SWT.NULL);
66
		text_orcid = formFactory.createOrcidWithLabelElement(formElement, "ORCID", entity.getOrcid(), SWT.NULL);
67
		text_lsid = formFactory.createLsidWithExceptionLabelElement(formElement, "LSID", entity.getLsid(), SWT.NULL);
68
		getLayoutComposite().layout();
69

    
70
	    //cache relevance
71
        registerCacheRelevance(text_firstname);
72
        registerCacheRelevance(text_lastname);
73
        registerCacheRelevance(text_prefix);
74
        registerCacheRelevance(text_suffix);
75
        registerCacheRelevance(text_initials);
76
	}
77

    
78
	@Override
79
	protected void updateContent() {
80
		super.updateContent();
81
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
82
		updateCacheRelevance();
83
	}
84

    
85
	@Override
86
	public void handleEvent(Object eventSource) {
87
		if (eventSource == toggleable_cache) {
88
			handleToggleableCacheField();
89
		} else if (eventSource == text_nomenclaturalTitle) {
90
			getEntity().setNomenclaturalTitle(text_nomenclaturalTitle.getText());
91
		} else if (eventSource == text_firstname) {
92
			getEntity().setGivenName(text_firstname.getText());
93
		}else if (eventSource == text_initials) {
94
			getEntity().setInitials(text_initials.getText());
95
		}else if (eventSource == text_lastname) {
96
			getEntity().setFamilyName(text_lastname.getText());
97
		} else if (eventSource == text_prefix) {
98
			getEntity().setPrefix(text_prefix.getText());
99
		} else if (eventSource == text_suffix) {
100
			getEntity().setSuffix(text_suffix.getText());
101
		}else if (eventSource == text_orcid) {
102
            getEntity().setOrcid(text_orcid.parseText());
103
        }else if (eventSource == text_lsid) {
104
            getEntity().setLsid(text_lsid.parseText());
105
        }else if (eventSource == time_lifespan) {
106
            getEntity().setLifespan(time_lifespan.getTimePeriod());
107
        }
108

    
109
		//if (eventSource != toggleable_cache) {
110
		if (!getEntity().isProtectedTitleCache()){
111
			toggleable_cache.setText(getEntity().generateTitle());
112
		}
113

    
114
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
115
	}
116

    
117
	@Override
118
	protected void handleToggleableCacheField() {
119
        boolean pushedState = toggleable_cache.getState();
120
        getEntity().setProtectedTitleCache(pushedState);
121
        getEntity().getTitleCache();
122
        if (pushedState){
123
            getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
124
        }
125
        updateCacheRelevance();
126
        updateToggleableCacheField();
127
    }
128
}
(4-4/12)