bf0a493884ca5196da640180ee0fdb5b5c5456dd
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / agent / PersonDetailElement.java
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.agent;
12
13 import java.util.Arrays;
14 import java.util.Collection;
15
16 import org.eclipse.swt.SWT;
17
18 import eu.etaxonomy.cdm.model.agent.Person;
19 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
20 import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
21 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
23 import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
25
26 /**
27 * <p>
28 * PersonDetailElement class.
29 * </p>
30 *
31 * @author n.hoffmann
32 * @created Mar 8, 2010
33 * @version 1.0
34 */
35 public class PersonDetailElement extends AbstractCdmDetailElement<Person> {
36
37 private ToggleableTextElement toggleable_cache;
38 private TextWithLabelElement text_nomenclaturalTitle;
39 private TextWithLabelElement text_firstname;
40 private TextWithLabelElement text_lastname;
41 private TextWithLabelElement text_prefix;
42 private TextWithLabelElement text_suffix;
43
44 private Collection<Object> excludeFromIrrelevantToggleableObjects;
45
46 /**
47 * <p>
48 * Constructor for PersonDetailElement.
49 * </p>
50 *
51 * @param cdmFormFactory
52 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
53 * object.
54 * @param formElement
55 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
56 * object.
57 * @param style
58 * a int.
59 */
60 public PersonDetailElement(CdmFormFactory cdmFormFactory,
61 ICdmFormElement formElement, int style) {
62 super(cdmFormFactory, formElement);
63 }
64
65 /** {@inheritDoc} */
66 @Override
67 protected void createControls(ICdmFormElement formElement, Person entity,
68 int style) {
69 toggleable_cache = formFactory.createToggleableTextField(formElement,
70 "Title Cache", entity.getTitleCache(),
71 entity.isProtectedTitleCache(), SWT.NULL);
72
73 text_nomenclaturalTitle = formFactory.createTextWithLabelElement(
74 formElement, "Nom. Title", entity.getNomenclaturalTitle(),
75 SWT.NULL);
76
77 text_firstname = formFactory.createTextWithLabelElement(formElement,
78 "Firstname", entity.getFirstname(), SWT.NULL);
79 text_lastname = formFactory.createTextWithLabelElement(formElement,
80 "Lastname", entity.getLastname(), SWT.NULL);
81
82 text_prefix = formFactory.createTextWithLabelElement(formElement,
83 "Prefix", entity.getPrefix(), SWT.NULL);
84 text_suffix = formFactory.createTextWithLabelElement(formElement,
85 "Suffix", entity.getSuffix(), SWT.NULL);
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 protected void updateContent() {
91 super.updateContent();
92
93 excludeFromIrrelevantToggleableObjects = Arrays.asList(new Object[] {
94 toggleable_cache, text_nomenclaturalTitle });
95
96 toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
97 setIrrelevant(toggleable_cache.getState(),
98 excludeFromIrrelevantToggleableObjects);
99 }
100
101 /** {@inheritDoc} */
102 @Override
103 public void handleEvent(Object eventSource) {
104 if (eventSource == toggleable_cache) {
105 getEntity().setTitleCache(toggleable_cache.getText(),
106 toggleable_cache.getState());
107 setIrrelevant(toggleable_cache.getState(),
108 excludeFromIrrelevantToggleableObjects);
109 } else if (eventSource == text_nomenclaturalTitle) {
110 getEntity()
111 .setNomenclaturalTitle(text_nomenclaturalTitle.getText());
112 } else if (eventSource == text_firstname) {
113 getEntity().setFirstname(text_firstname.getText());
114 } else if (eventSource == text_lastname) {
115 getEntity().setLastname(text_lastname.getText());
116 } else if (eventSource == text_prefix) {
117 getEntity().setPrefix(text_prefix.getText());
118 } else if (eventSource == text_suffix) {
119 getEntity().setSuffix(text_suffix.getText());
120 }
121
122 if (eventSource != toggleable_cache) {
123 toggleable_cache.setText(getEntity().getTitleCache());
124 }
125
126 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
127 }
128 }