Project

General

Profile

Download (8.16 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.name;
11

    
12
import java.util.Arrays;
13

    
14
import org.eclipse.ui.forms.widgets.ExpandableComposite;
15

    
16
import eu.etaxonomy.cdm.model.name.IBacterialName;
17
import eu.etaxonomy.cdm.model.name.INonViralName;
18
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
21
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26
import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
27
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
29
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
30

    
31
/**
32
 * @author n.hoffmann
33
 * @created May 20, 2010
34
 */
35
public class NonViralNameDetailElement 
36
		extends AbstractIdentifiableEntityDetailElement<TaxonName>  {
37

    
38
	private NameDetailSection section_name;
39
	private AuthorshipDetailSection section_author;
40
	private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
41
	private HybridDetailSection section_hybrid;
42
	private LsidWithExceptionLabelElement textLsid;
43
	private TextWithLabelElement text_nameApprobation;
44

    
45

    
46
	public NonViralNameDetailElement(CdmFormFactory formFactory,
47
			ICdmFormElement formElement) {
48
		super(formFactory, formElement);
49
		initIsAdvancedDetailsView();
50

    
51
	}
52

    
53
	/** {@inheritDoc} */
54
	@Override
55
    protected void createControls(ICdmFormElement formElement, final TaxonName entity, int style) {
56

    
57

    
58
        if (isAdvancedView){
59
            toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
60

    
61
            combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
62
            combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
63
            textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
64
            if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
65
            	text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
66
            }
67

    
68
        }else{
69
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE)){
70
        		toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
71

    
72
          	}
73
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE)){
74
        		combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
75
        		combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
76
        	}
77
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
78
        		textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
79

    
80
        	}
81
        	
82
        	if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
83
        		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION)){
84
    			 text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
85
        		}
86
        	}
87

    
88
        }
89

    
90

    
91
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
92
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
93
	    addControl(section_name);
94
	    addElement(section_name);
95
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
96
    	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
97
    	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
98
    	    addControl(section_author);
99
    	    addElement(section_author);
100
	    }
101
	    //TODO RL
102
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
103
    	   section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
104
    	   section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
105
    	   addControl(section_hybrid);
106
    	   addElement(section_hybrid);
107

    
108
    	 }
109

    
110

    
111
    }
112

    
113
	/** {@inheritDoc} */
114
	@Override
115
	protected void updateContent() {
116
		super.updateContent();
117
		// disable nomenclatural code, because changing of nom.code is not
118
		// implemented on library side
119
//		if(combo_nomenclaturalCode!=null){
120
//		    combo_nomenclaturalCode.setEnabled(false);
121
//		}
122

    
123
		if(toggleable_cache!=null){
124
		    toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
125
		    setIrrelevant(toggleable_cache.getState(),
126
		            Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
127
		}
128
	}
129

    
130
	/** {@inheritDoc} */
131
	@Override
132
	public void setEntity(TaxonName entity) {
133
		super.setEntity(entity);
134
		if (section_name!=null) {
135
            section_name.setEntity(entity);
136
        }
137
		if (section_author!=null) {
138
            section_author.setEntity(entity);
139
        }
140
		if (section_hybrid!=null) {
141
            section_hybrid.setEntity(entity);
142
        }
143
	}
144

    
145
	/** {@inheritDoc} */
146
	@Override
147
	public void removeElements() {
148
		super.removeElements();
149
		if (section_name != null) {
150
			section_name.removeElements();
151
			removeControl(section_name);
152
			section_name.dispose();
153
			section_name = null;
154
		}
155
		if (section_author != null) {
156
			section_author.removeElements();
157
			removeControl(section_author);
158
			section_author.dispose();
159
			section_author = null;
160
		}
161
	}
162

    
163
	/** {@inheritDoc} */
164
	@Override
165
	public void handleEvent(Object eventSource) {
166
		if (eventSource == toggleable_cache) {
167
			handleToggleableCacheField();
168
			// we never want the fullTitleCache to be protected since we only
169
			// use it for
170
			// initiating the free text name editor
171
			getEntity().setProtectedFullTitleCache(false);
172
		} else if (eventSource == section_name || eventSource == section_author) {
173
			if (getParentElement() instanceof AbstractCdmDetailSection) {
174
                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
175
            }
176
			if (toggleable_cache != null){
177
    			if (!toggleable_cache.getState()) {
178
    				toggleable_cache.setText(getEntity().getTitleCache());
179
    			}
180
			}
181
		} else if (eventSource == section_name) {
182
			section_name.setEntity(getEntity());
183
			getLayoutComposite().layout();
184
		} else if(eventSource==textLsid){
185
		    getEntity().setLsid(textLsid.parseText());
186
		} else if (eventSource == combo_nomenclaturalCode){
187
			getEntity().setNameType(combo_nomenclaturalCode.getSelection());
188
			section_name.updateContent();
189
		} else if(eventSource == this.text_nameApprobation){
190
            ((IBacterialName)getEntity()).setNameApprobation(text_nameApprobation.getText());
191
        }
192
	}
193
	@Override
194
	protected void handleToggleableCacheField() {
195
        boolean pushedState = toggleable_cache.getState();
196

    
197
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
198
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
199
        updateToggleableCacheField();
200
    }
201

    
202

    
203

    
204

    
205
//    @Override
206
//    public void toggleAdvancedMediaView(){
207
//        mediaDetailElement.toggleAdvancedMediaView();
208
//    }
209
}
(15-15/21)