Project

General

Profile

Download (6.14 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
        }
68

    
69

    
70
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
71
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
72
	    addControl(section_name);
73
	    addElement(section_name);
74
	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
75
	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
76
	    addControl(section_author);
77
	    addElement(section_author);
78

    
79
	    //TODO RL
80
	    if (isAdvancedView){
81
    	    if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
82
    	        section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
83
    	        section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
84
    	        addControl(section_hybrid);
85
    	        addElement(section_hybrid);
86
    	    }
87
	    }
88

    
89

    
90
    }
91

    
92
	/** {@inheritDoc} */
93
	@Override
94
	protected void updateContent() {
95
		super.updateContent();
96

    
97
		// disable nomenclatural code, because changing of nom.code is not
98
		// implemented on library side
99
		if(combo_nomenclaturalCode!=null){
100
		    combo_nomenclaturalCode.setEnabled(false);
101
		}
102

    
103
		if(toggleable_cache!=null){
104
		    setIrrelevant(toggleable_cache.getState(),
105
		            Arrays.asList(new Object[] { toggleable_cache }));
106
		}
107
	}
108

    
109
	/** {@inheritDoc} */
110
	@Override
111
	public void setEntity(NonViralName entity) {
112
		super.setEntity(entity);
113
		if (section_name!=null) {
114
            section_name.setEntity(entity);
115
        }
116
		if (section_author!=null) {
117
            section_author.setEntity(entity);
118
        }
119
		if (section_hybrid!=null) {
120
            section_hybrid.setEntity(entity);
121
        }
122
	}
123

    
124
	/** {@inheritDoc} */
125
	@Override
126
	public void removeElements() {
127
		super.removeElements();
128
		if (section_name != null) {
129
			section_name.removeElements();
130
			removeControl(section_name);
131
			section_name.dispose();
132
			section_name = null;
133
		}
134
		if (section_author != null) {
135
			section_author.removeElements();
136
			removeControl(section_author);
137
			section_author.dispose();
138
			section_author = null;
139
		}
140
	}
141

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

    
173
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
174
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
175
        updateToggleableCacheField();
176
    }
177

    
178

    
179

    
180

    
181
//    @Override
182
//    public void toggleAdvancedMediaView(){
183
//        mediaDetailElement.toggleAdvancedMediaView();
184
//    }
185
}
(15-15/25)