Project

General

Profile

Download (7.92 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
	    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){
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
    	 }else{
108
    		 if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
109
    			 if (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

    
121
	/** {@inheritDoc} */
122
	@Override
123
	protected void updateContent() {
124
		super.updateContent();
125

    
126
		// disable nomenclatural code, because changing of nom.code is not
127
		// implemented on library side
128
		if(combo_nomenclaturalCode!=null){
129
		    combo_nomenclaturalCode.setEnabled(false);
130
		}
131

    
132
		if(toggleable_cache!=null){
133
		    setIrrelevant(toggleable_cache.getState(),
134
		            Arrays.asList(new Object[] { toggleable_cache }));
135
		}
136
	}
137

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

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

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

    
202
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
203
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
204
        updateToggleableCacheField();
205
    }
206

    
207

    
208

    
209

    
210
//    @Override
211
//    public void toggleAdvancedMediaView(){
212
//        mediaDetailElement.toggleAdvancedMediaView();
213
//    }
214
}
(15-15/25)