Project

General

Profile

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

    
28
/**
29
 * @author n.hoffmann
30
 * @created May 20, 2010
31
 * @version 1.0
32
 */
33
public class NonViralNameDetailElement extends
34
	AbstractIdentifiableEntityDetailElement<NonViralName>  {
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 NonViralName 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
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
112
		if(toggleable_cache!=null){
113
		    setIrrelevant(toggleable_cache.getState(),
114
		            Arrays.asList(new Object[] { toggleable_cache, textLsid }));
115
		}
116
	}
117

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

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

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

    
182
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
183
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
184
        updateToggleableCacheField();
185
    }
186

    
187

    
188

    
189

    
190
//    @Override
191
//    public void toggleAdvancedMediaView(){
192
//        mediaDetailElement.toggleAdvancedMediaView();
193
//    }
194
}
(15-15/21)