Project

General

Profile

Download (7.22 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.INonViralName;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.name.TaxonName;
19
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
25
import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
26
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
28

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

    
36
	private NameDetailSection section_name;
37
	private AuthorshipDetailSection section_author;
38
	private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
39
	private HybridDetailSection section_hybrid;
40
	private LsidWithExceptionLabelElement textLsid;
41

    
42

    
43
	public NonViralNameDetailElement(CdmFormFactory formFactory,
44
			ICdmFormElement formElement) {
45
		super(formFactory, formElement);
46
		initIsAdvancedDetailsView();
47

    
48
	}
49

    
50
	/** {@inheritDoc} */
51
	@Override
52
    protected void createControls(ICdmFormElement formElement, final TaxonName entity, int style) {
53

    
54

    
55
        if (isAdvancedView){
56
            toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
57

    
58
            combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
59
            combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
60
            textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
61

    
62
        }else{
63
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE)){
64
        		toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
65

    
66
          	}
67
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE)){
68
        		combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
69
        		combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
70
        	}
71
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
72
        		textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
73

    
74
        	}
75

    
76

    
77
        }
78

    
79

    
80
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
81
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
82
	    addControl(section_name);
83
	    addElement(section_name);
84
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
85
    	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
86
    	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
87
    	    addControl(section_author);
88
    	    addElement(section_author);
89
	    }
90
	    //TODO RL
91
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
92
    	   section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
93
    	   section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
94
    	   addControl(section_hybrid);
95
    	   addElement(section_hybrid);
96

    
97
    	 }
98

    
99

    
100
    }
101

    
102
	/** {@inheritDoc} */
103
	@Override
104
	protected void updateContent() {
105
		super.updateContent();
106
		// disable nomenclatural code, because changing of nom.code is not
107
		// implemented on library side
108
//		if(combo_nomenclaturalCode!=null){
109
//		    combo_nomenclaturalCode.setEnabled(false);
110
//		}
111

    
112
		if(toggleable_cache!=null){
113
		    toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
114
		    setIrrelevant(toggleable_cache.getState(),
115
		            Arrays.asList(new Object[] { toggleable_cache, textLsid }));
116
		}
117
	}
118

    
119
	/** {@inheritDoc} */
120
	@Override
121
	public void setEntity(TaxonName entity) {
122
		super.setEntity(entity);
123
		if (section_name!=null) {
124
            section_name.setEntity(entity);
125
        }
126
		if (section_author!=null) {
127
            section_author.setEntity(entity);
128
        }
129
		if (section_hybrid!=null) {
130
            section_hybrid.setEntity(entity);
131
        }
132
	}
133

    
134
	/** {@inheritDoc} */
135
	@Override
136
	public void removeElements() {
137
		super.removeElements();
138
		if (section_name != null) {
139
			section_name.removeElements();
140
			removeControl(section_name);
141
			section_name.dispose();
142
			section_name = null;
143
		}
144
		if (section_author != null) {
145
			section_author.removeElements();
146
			removeControl(section_author);
147
			section_author.dispose();
148
			section_author = null;
149
		}
150
	}
151

    
152
	/** {@inheritDoc} */
153
	@Override
154
	public void handleEvent(Object eventSource) {
155
		if (eventSource == toggleable_cache) {
156
			handleToggleableCacheField();
157
			// we never want the fullTitleCache to be protected since we only
158
			// use it for
159
			// initiating the free text name editor
160
			getEntity().setProtectedFullTitleCache(false);
161
		} else if (eventSource == section_name || eventSource == section_author) {
162
			if (getParentElement() instanceof AbstractCdmDetailSection) {
163
                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
164
            }
165
			if (toggleable_cache != null){
166
    			if (!toggleable_cache.getState()) {
167
    				toggleable_cache.setText(getEntity().getTitleCache());
168
    			}
169
			}
170
		}
171
		if (eventSource == section_name) {
172
			section_name.setEntity(getEntity());
173
			getLayoutComposite().layout();
174
		}
175
		else if(eventSource==textLsid){
176
		    getEntity().setLsid(textLsid.parseText());
177
		}
178
		
179
		if (eventSource == combo_nomenclaturalCode){
180
			getEntity().setNameType(combo_nomenclaturalCode.getSelection());
181
			section_name.updateContent();
182
		}
183
	}
184
	@Override
185
	protected void handleToggleableCacheField() {
186
        boolean pushedState = toggleable_cache.getState();
187

    
188
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
189
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
190
        updateToggleableCacheField();
191
    }
192

    
193

    
194

    
195

    
196
//    @Override
197
//    public void toggleAdvancedMediaView(){
198
//        mediaDetailElement.toggleAdvancedMediaView();
199
//    }
200
}
(15-15/21)