Project

General

Profile

Download (5.24 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 org.eclipse.ui.forms.widgets.ExpandableComposite;
16

    
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.name.NonViralName;
19
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
20
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
23
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
24
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
25

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

    
38
	private NameDetailSection section_name;
39
	private AuthorshipDetailSection section_author;
40
	private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
41
	private HybridDetailSection section_hybrid;
42

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

    
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see
64
	 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
65
	 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
66
	 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
67
	 */
68
	/** {@inheritDoc} */
69
	@Override
70
    protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
71

    
72
        toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
73

    
74
        combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
75
        combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
76

    
77
        section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
78
        section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
79
        addControl(section_name);
80
        addElement(section_name);
81
        section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
82
        section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
83
        addControl(section_author);
84
        addElement(section_author);
85

    
86
        section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
87
        section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
88
        addControl(section_hybrid);
89
        addElement(section_hybrid);
90
    }
91

    
92
	/** {@inheritDoc} */
93
	@Override
94
	protected void updateContent() {
95
		super.updateContent();
96

    
97
		// disable nomenclatural code, because changing of nom.code is not
98
		// implemented on library side
99
		combo_nomenclaturalCode.setEnabled(false);
100

    
101
		setIrrelevant(toggleable_cache.getState(),
102
				Arrays.asList(new Object[] { toggleable_cache }));
103
	}
104

    
105
	/** {@inheritDoc} */
106
	@Override
107
	public void setEntity(NonViralName entity) {
108
		super.setEntity(entity);
109
		section_name.setEntity(entity);
110
		section_author.setEntity(entity);
111
		section_hybrid.setEntity(entity);
112
	}
113

    
114
	/** {@inheritDoc} */
115
	@Override
116
	public void removeElements() {
117
		super.removeElements();
118
		if (section_name != null) {
119
			section_name.removeElements();
120
			removeControl(section_name);
121
			section_name.dispose();
122
			section_name = null;
123
		}
124
		if (section_author != null) {
125
			section_author.removeElements();
126
			removeControl(section_author);
127
			section_author.dispose();
128
			section_author = null;
129
		}
130
	}
131

    
132
	/*
133
	 * (non-Javadoc)
134
	 *
135
	 * @see
136
	 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
137
	 * .lang.Object)
138
	 */
139
	/** {@inheritDoc} */
140
	@Override
141
	public void handleEvent(Object eventSource) {
142
		if (eventSource == toggleable_cache) {
143
			handleToggleableCacheField();
144
			// we never want the fullTitleCache to be protected since we only
145
			// use it for
146
			// initiating the free text name editor
147
			getEntity().setProtectedFullTitleCache(false);
148
		} else if (eventSource == section_name || eventSource == section_author) {
149
			if (getParentElement() instanceof AbstractCdmDetailSection) {
150
                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
151
            }
152
			if (!toggleable_cache.getState()) {
153
				toggleable_cache.setText(getEntity().getTitleCache());
154
			}
155
		}
156
		if (eventSource == section_name) {
157
			section_name.setEntity(getEntity());
158
			getLayoutComposite().layout();
159
		}
160
	}
161
}
(15-15/21)