Project

General

Profile

Download (8.54 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
            if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
64
            	text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
65
            }
66
            textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
67
            
68

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

    
73
          	}
74
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE)){
75
        		combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
76
        		combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
77
        	}
78
        	if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
79
        		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION)){
80
    			 text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
81
        		}
82
        	}
83

    
84
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
85
        		textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
86

    
87
        	}
88
        	
89
        	if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
90
        		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION)){
91
    			 text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
92
        		}
93
        	}
94

    
95
        }
96

    
97

    
98
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
99
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
100
	    addControl(section_name);
101
	    addElement(section_name);
102
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
103
    	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
104
    	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
105
    	    addControl(section_author);
106
    	    addElement(section_author);
107
	    }
108
	    //TODO RL
109
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
110
    	   section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
111
    	   section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
112
    	   addControl(section_hybrid);
113
    	   addElement(section_hybrid);
114

    
115
    	 }
116

    
117

    
118
    }
119

    
120
	/** {@inheritDoc} */
121
	@Override
122
	protected void updateContent() {
123
		super.updateContent();
124
		// disable nomenclatural code, because changing of nom.code is not
125
		// implemented on library side
126
//		if(combo_nomenclaturalCode!=null){
127
//		    combo_nomenclaturalCode.setEnabled(false);
128
//		}
129

    
130
		if(toggleable_cache!=null){
131
		    toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
132
		    setIrrelevant(toggleable_cache.getState(),
133
		            Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
134
		}
135
	}
136

    
137
	/** {@inheritDoc} */
138
	@Override
139
	public void setEntity(TaxonName entity) {
140
		super.setEntity(entity);
141
		if (section_name!=null) {
142
            section_name.setEntity(entity);
143
        }
144
		if (section_author!=null) {
145
            section_author.setEntity(entity);
146
        }
147
		if (section_hybrid!=null) {
148
            section_hybrid.setEntity(entity);
149
        }
150
	}
151

    
152
	/** {@inheritDoc} */
153
	@Override
154
	public void removeElements() {
155
		super.removeElements();
156
		if (section_name != null) {
157
			section_name.removeElements();
158
			removeControl(section_name);
159
			section_name.dispose();
160
			section_name = null;
161
		}
162
		if (section_author != null) {
163
			section_author.removeElements();
164
			removeControl(section_author);
165
			section_author.dispose();
166
			section_author = null;
167
		}
168
	}
169

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

    
205
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
206
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
207
        updateToggleableCacheField();
208
    }
209

    
210

    
211

    
212

    
213
//    @Override
214
//    public void toggleAdvancedMediaView(){
215
//        mediaDetailElement.toggleAdvancedMediaView();
216
//    }
217
}
(15-15/21)