Project

General

Profile

Download (6.26 KB) Statistics
| Branch: | Tag: | Revision:
1 729887cf n.hoffmann
// $Id$
2
/**
3 86d58314 n.hoffmann
 * Copyright (C) 2007 EDIT
4 139902da Patric Plitzner
 * European Distributed Institute of Taxonomy
5 86d58314 n.hoffmann
 * http://www.e-taxonomy.eu
6 139902da Patric Plitzner
 *
7 86d58314 n.hoffmann
 * 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 729887cf n.hoffmann
11 f211dd28 n.hoffmann
package eu.etaxonomy.taxeditor.ui.section.name;
12 729887cf n.hoffmann
13
import java.util.Arrays;
14
15 139902da Patric Plitzner
import org.eclipse.ui.forms.widgets.ExpandableComposite;
16 729887cf n.hoffmann
17 b9a0d300 l.morris
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.name.NonViralName;
19 4db49a38 Alexander Oppermann
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21 b9a0d300 l.morris
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
22 78222507 n.hoffmann
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 dacb59c9 Patric Plitzner
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 23783f7a n.hoffmann
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
25 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
26 89f83939 n.hoffmann
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
27 729887cf n.hoffmann
28
/**
29 86d58314 n.hoffmann
 * <p>
30
 * NonViralNameDetailElement class.
31
 * </p>
32 139902da Patric Plitzner
 *
33 729887cf n.hoffmann
 * @author n.hoffmann
34
 * @created May 20, 2010
35
 * @version 1.0
36
 */
37 86d58314 n.hoffmann
public class NonViralNameDetailElement extends
38 89f83939 n.hoffmann
	AbstractIdentifiableEntityDetailElement<NonViralName> {
39 729887cf n.hoffmann
40
	private NameDetailSection section_name;
41
	private AuthorshipDetailSection section_author;
42 b9a0d300 l.morris
	private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
43 c744ab59 n.hoffmann
	private HybridDetailSection section_hybrid;
44 729887cf n.hoffmann
45 3be6ef3e n.hoffmann
	/**
46 86d58314 n.hoffmann
	 * <p>
47
	 * Constructor for NonViralNameDetailElement.
48
	 * </p>
49 139902da Patric Plitzner
	 *
50 86d58314 n.hoffmann
	 * @param formFactory
51 78222507 n.hoffmann
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
52 86d58314 n.hoffmann
	 *            object.
53
	 * @param formElement
54 78222507 n.hoffmann
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55 86d58314 n.hoffmann
	 *            object.
56 3be6ef3e n.hoffmann
	 */
57 729887cf n.hoffmann
	public NonViralNameDetailElement(CdmFormFactory formFactory,
58
			ICdmFormElement formElement) {
59
		super(formFactory, formElement);
60
	}
61 86d58314 n.hoffmann
62
	/*
63
	 * (non-Javadoc)
64 139902da Patric Plitzner
	 *
65 86d58314 n.hoffmann
	 * @see
66
	 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
67
	 * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
68
	 * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
69 729887cf n.hoffmann
	 */
70 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
71 729887cf n.hoffmann
	@Override
72 139902da Patric Plitzner
    protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
73 2a7820b7 Patric Plitzner
	    //name can be null in rare cases. Temporary solution for #4221. May be obsolete when
74
	    //#4393 (Make changing name of a taxon possible in details view) is implemented.
75
	    if(entity==null){
76
	        formFactory.createEmptyElement(formElement, "No name associated with this taxon.");
77
	    }
78
	    else {
79
	        toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
80
81
	        combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
82
	        combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
83
84
	        //TODO RL
85
	        if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
86
	            toggleable_cache.setVisible(false);
87
	            combo_nomenclaturalCode.setVisible(false);
88
	        }
89
90
	        section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
91
	        section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
92
	        addControl(section_name);
93
	        addElement(section_name);
94
	        section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
95
	        section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
96
	        addControl(section_author);
97
	        addElement(section_author);
98
99
	        //TODO RL
100
	        if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
101
	            section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
102
	            section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
103
	            addControl(section_hybrid);
104
	            addElement(section_hybrid);
105
	        }
106
	    }
107 139902da Patric Plitzner
    }
108 729887cf n.hoffmann
109 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
110 729887cf n.hoffmann
	@Override
111
	protected void updateContent() {
112
		super.updateContent();
113 86d58314 n.hoffmann
114
		// disable nomenclatural code, because changing of nom.code is not
115
		// implemented on library side
116 2a7820b7 Patric Plitzner
		if(combo_nomenclaturalCode!=null){
117
		    combo_nomenclaturalCode.setEnabled(false);
118
		}
119 86d58314 n.hoffmann
120 2a7820b7 Patric Plitzner
		if(toggleable_cache!=null){
121
		    setIrrelevant(toggleable_cache.getState(),
122
		            Arrays.asList(new Object[] { toggleable_cache }));
123
		}
124 729887cf n.hoffmann
	}
125 86d58314 n.hoffmann
126 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
127 729887cf n.hoffmann
	@Override
128
	public void setEntity(NonViralName entity) {
129
		super.setEntity(entity);
130 2a7820b7 Patric Plitzner
		if (section_name!=null) {
131
            section_name.setEntity(entity);
132
        }
133
		if (section_author!=null) {
134
            section_author.setEntity(entity);
135
        }
136
		if (section_hybrid!=null) {
137
            section_hybrid.setEntity(entity);
138
        }
139 729887cf n.hoffmann
	}
140 86d58314 n.hoffmann
141 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
142 729887cf n.hoffmann
	@Override
143
	public void removeElements() {
144
		super.removeElements();
145 86d58314 n.hoffmann
		if (section_name != null) {
146 3fb05254 n.hoffmann
			section_name.removeElements();
147 729887cf n.hoffmann
			removeControl(section_name);
148
			section_name.dispose();
149
			section_name = null;
150
		}
151 86d58314 n.hoffmann
		if (section_author != null) {
152 3fb05254 n.hoffmann
			section_author.removeElements();
153 729887cf n.hoffmann
			removeControl(section_author);
154
			section_author.dispose();
155
			section_author = null;
156
		}
157
	}
158 86d58314 n.hoffmann
159
	/*
160
	 * (non-Javadoc)
161 139902da Patric Plitzner
	 *
162 86d58314 n.hoffmann
	 * @see
163
	 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
164
	 * .lang.Object)
165 729887cf n.hoffmann
	 */
166 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
167 729887cf n.hoffmann
	@Override
168
	public void handleEvent(Object eventSource) {
169 86d58314 n.hoffmann
		if (eventSource == toggleable_cache) {
170 e0b35bf1 n.hoffmann
			handleToggleableCacheField();
171 86d58314 n.hoffmann
			// we never want the fullTitleCache to be protected since we only
172
			// use it for
173 3fb05254 n.hoffmann
			// initiating the free text name editor
174
			getEntity().setProtectedFullTitleCache(false);
175 86d58314 n.hoffmann
		} else if (eventSource == section_name || eventSource == section_author) {
176 139902da Patric Plitzner
			if (getParentElement() instanceof AbstractCdmDetailSection) {
177
                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
178
            }
179 86d58314 n.hoffmann
			if (!toggleable_cache.getState()) {
180 729887cf n.hoffmann
				toggleable_cache.setText(getEntity().getTitleCache());
181
			}
182
		}
183 86d58314 n.hoffmann
		if (eventSource == section_name) {
184 6a6ea365 n.hoffmann
			section_name.setEntity(getEntity());
185
			getLayoutComposite().layout();
186
		}
187 729887cf n.hoffmann
	}
188
}