Project

General

Profile

Download (7.59 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

    
11
package eu.etaxonomy.taxeditor.ui.section.name;
12

    
13
import java.util.Arrays;
14

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

    
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.name.NonViralName;
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
 * @version 1.0
33
 */
34
public class NonViralNameDetailElement extends
35
	AbstractIdentifiableEntityDetailElement<NonViralName>  {
36

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

    
43

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

    
49
	}
50

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

    
55

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

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

    
84
        	}
85

    
86

    
87
        }
88

    
89

    
90
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
91
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
92
	    addControl(section_name);
93
	    addElement(section_name);
94
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
95
    	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
96
    	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
97
    	    addControl(section_author);
98
    	    addElement(section_author);
99
	    }
100
	    //TODO RL
101
	    if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
102
    	    if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
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

    
118
		// disable nomenclatural code, because changing of nom.code is not
119
		// implemented on library side
120
		if(combo_nomenclaturalCode!=null){
121
		    combo_nomenclaturalCode.setEnabled(false);
122
		}
123

    
124
		if(toggleable_cache!=null){
125
		    setIrrelevant(toggleable_cache.getState(),
126
		            Arrays.asList(new Object[] { toggleable_cache }));
127
		}
128
	}
129

    
130
	/** {@inheritDoc} */
131
	@Override
132
	public void setEntity(NonViralName 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
		}
182
		if (eventSource == section_name) {
183
			section_name.setEntity(getEntity());
184
			getLayoutComposite().layout();
185
		}
186
		else if(eventSource==textLsid){
187
		    getEntity().setLsid(textLsid.parseText());
188
		}
189
	}
190
	@Override
191
	protected void handleToggleableCacheField() {
192
        boolean pushedState = toggleable_cache.getState();
193

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

    
199

    
200

    
201

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