Project

General

Profile

Download (7.58 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
            //TODO RL
62
            if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
63
                toggleable_cache.setVisible(false);
64
                combo_nomenclaturalCode.setVisible(false);
65
            }
66
        }else{
67
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE)){
68
        		toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
69
                if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
70
                    toggleable_cache.setVisible(false);
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
        		 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
77
        			  combo_nomenclaturalCode.setVisible(false);
78
                 }
79
        	}
80
        	if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
81
        		textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
82

    
83
        	}
84

    
85

    
86
        }
87

    
88

    
89
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
90
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
91
	    addControl(section_name);
92
	    addElement(section_name);
93
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
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 (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
101
    	    if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
102
    	        section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
103
    	        section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
104
    	        addControl(section_hybrid);
105
    	        addElement(section_hybrid);
106
    	    }
107
    	 }
108

    
109

    
110
    }
111

    
112
	/** {@inheritDoc} */
113
	@Override
114
	protected void updateContent() {
115
		super.updateContent();
116

    
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
		    setIrrelevant(toggleable_cache.getState(),
125
		            Arrays.asList(new Object[] { toggleable_cache }));
126
		}
127
	}
128

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

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

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

    
193
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
194
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
195
        updateToggleableCacheField();
196
    }
197

    
198

    
199

    
200

    
201
//    @Override
202
//    public void toggleAdvancedMediaView(){
203
//        mediaDetailElement.toggleAdvancedMediaView();
204
//    }
205
}
(15-15/21)