Project

General

Profile

Download (10.6 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 eu.etaxonomy.cdm.model.name.IBacterialName;
15
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
16
import eu.etaxonomy.cdm.model.name.TaxonName;
17
import eu.etaxonomy.taxeditor.l10n.Messages;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.store.StoreUtil;
22
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26
import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
27
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
29
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
30

    
31
/**
32
 * @author n.hoffmann
33
 * @created May 20, 2010
34
 */
35
public class NonViralNameDetailElement
36
		extends AbstractIdentifiableEntityDetailElement<TaxonName>  {
37

    
38
	private NameDetailSection section_name;
39
	private AuthorshipDetailSection section_author;
40
	private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
41
	private HybridDetailSection section_hybrid;
42
	private LsidWithExceptionLabelElement textLsid;
43
	private TextWithLabelElement text_nameApprobation;
44
	//protected boolean isAdvancedView ;
45

    
46
	public NonViralNameDetailElement(CdmFormFactory formFactory,
47
			ICdmFormElement formElement) {
48
		super(formFactory, formElement);
49

    
50
	}
51

    
52
	/** {@inheritDoc} */
53
	@Override
54
    protected void createControls(ICdmFormElement formElement, final TaxonName entity, int style) {
55
	    NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
56

    
57
        if (!config.isSimpleDetailsViewActivated() ){
58
            toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
59

    
60
            combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
61
            combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
62
            if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
63
            	text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
64
            }
65
            textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
66

    
67

    
68
        }else{
69
        	if (config.isNameCacheActivated()){
70
        		toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
71

    
72
          	}
73
        	if (config.isNomenclaturalCodeActived()){
74
        		combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
75
        		combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
76
        	}
77
        	if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
78
        		if (config.isNameApprobiationActivated()){
79
    			 text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
80
        		}
81
        	}
82

    
83
        	if (config.isLSIDActivated()){
84
        		textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
85

    
86
        	}
87

    
88

    
89
        }
90

    
91

    
92
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(NameDetailSection.class, entity.getClass().getCanonicalName(), true));
93
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
94
	    addControl(section_name);
95
	    addElement(section_name);
96
//	    if (isAdvancedView || PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
97
    	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(AuthorshipDetailSection.class, entity.getClass().getCanonicalName(), true));
98
    	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
99
    	    addControl(section_author);
100
    	    addElement(section_author);
101
//	    }
102
	    //TODO RL
103
	    if (config.isHybridActivated()){
104
    	   section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(HybridDetailSection.class, entity.getClass().getCanonicalName()));
105
    	   section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
106
    	   addControl(section_hybrid);
107
    	   addElement(section_hybrid);
108

    
109
    	 }
110

    
111

    
112
    }
113

    
114
	/** {@inheritDoc} */
115
	@Override
116
	protected void updateContent() {
117
		super.updateContent();
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
		    toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
126
		    setIrrelevant(toggleable_cache.getState(),
127
		            Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
128
		}
129
	}
130

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

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

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

    
192
				this.updateContent();
193
	            //this is needed for the "new" wizards in order to redraw correctly
194
	            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
195
				section_hybrid.setEntity(getEntity());
196
				section_author.setEntity(getEntity());
197
				section_name.setEntity(getEntity());
198
			}else{
199
				combo_nomenclaturalCode.setSelection(getEntity().getNameType());
200
			}
201
		} else if(eventSource == this.text_nameApprobation){
202
            ((IBacterialName)getEntity()).setNameApprobation(text_nameApprobation.getText());
203
        }
204
	}
205
	private boolean checkForDeletableParts(NomenclaturalCode selection) {
206
		NomenclaturalCode actualCode =  getEntity().getNameType();
207
		if (selection.equals(actualCode)){
208
			return true;
209
		}
210
		if (actualCode.equals(NomenclaturalCode.ICZN) ){
211
			if(getEntity().getOriginalPublicationYear() != null || getEntity().getPublicationYear() != null || getEntity().getBreed() != null){
212
				if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfZoologicalNameParts, Messages.NonViralNameDetails_descriptionDeleteZoologicalNameParts)){
213
					getEntity().setOriginalPublicationYear(null);
214
					getEntity().setPublicationYear(null);
215
					getEntity().setBreed(null);
216
					return true;
217
				}
218
			}else {
219
				return true;
220
			}
221

    
222
		}
223
		if (actualCode.equals(NomenclaturalCode.ICNB)){
224
			if (getEntity().getNameApprobation() != null || getEntity().getSubGenusAuthorship() != null){
225
				if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfBacterialNameParts, Messages.NonViralNameDetails_desciptionDeleteOfBacterialNameParts)){
226
					getEntity().setNameApprobation(null);
227
					getEntity().setSubGenusAuthorship(null);
228
					return true;
229
				}
230
			}else{
231
				return true;
232
			}
233

    
234
		}
235
		if (actualCode.equals(NomenclaturalCode.NonViral)){
236
		    return true;
237
        }
238
		if (actualCode.equals(NomenclaturalCode.Fungi)){
239
			if (getEntity().isAnamorphic() ){
240
				if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfFungiNameParts, Messages.NonViralNameDetails_descriptionDeleteOfFungiNameParts)){
241
					getEntity().setAnamorphic(false);
242
					return true;
243
				}
244
			}else{
245
				return true;
246
			}
247
		}
248
		if (actualCode.equals(NomenclaturalCode.ICNCP)){
249
			if (getEntity().getCultivarName() != null){
250
				if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfCultivarNameParts, Messages.NonViralNameDetails_descriptionDeleteOfCultivarNameParts)){
251
					getEntity().setCultivarName(null);
252
					return true;
253
				}
254
			}else{
255
				return true;
256
			}
257

    
258
		}
259
		if (actualCode.equals(NomenclaturalCode.ICNAFP)){
260
			return true;
261
		}
262
		return false;
263
	}
264

    
265
	@Override
266
	protected void handleToggleableCacheField() {
267
        boolean pushedState = toggleable_cache.getState();
268

    
269
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
270
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
271
        updateToggleableCacheField();
272
    }
273

    
274

    
275

    
276

    
277
//    @Override
278
//    public void toggleAdvancedMediaView(){
279
//        mediaDetailElement.toggleAdvancedMediaView();
280
//    }
281
}
(15-15/22)