Project

General

Profile

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

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

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

    
48
	public NonViralNameDetailElement(CdmFormFactory formFactory,
49
			ICdmFormElement formElement) {
50
		super(formFactory, formElement);
51

    
52
	}
53

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

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

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

    
69

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

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

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

    
88
        	}
89

    
90

    
91
        }
92

    
93

    
94
	    section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
95
	    section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
96
	    addControl(section_name);
97
	    addElement(section_name);
98
//	    if (isAdvancedView || PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
99

    
100
    	    section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
101
    	    section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
102
    	    addControl(section_author);
103
    	    addElement(section_author);
104
//	    }
105
	    //TODO RL
106
	    if (config.isHybridActivated()){
107
    	   section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
108
    	   section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
109
    	   addControl(section_hybrid);
110
    	   addElement(section_hybrid);
111

    
112
    	 }
113

    
114

    
115
    }
116

    
117
	/** {@inheritDoc} */
118
	@Override
119
	protected void updateContent() {
120
		super.updateContent();
121
		// disable nomenclatural code, because changing of nom.code is not
122
		// implemented on library side
123
//		if(combo_nomenclaturalCode!=null){
124
//		    combo_nomenclaturalCode.setEnabled(false);
125
//		}
126

    
127
		if(toggleable_cache!=null){
128
		    toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
129
		    setIrrelevant(toggleable_cache.getState(),
130
		            Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
131
		}
132
	}
133

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

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

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

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

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

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

    
261
		}
262
		if (actualCode.equals(NomenclaturalCode.ICNAFP)){
263
			return true;
264
		}
265
		return false;
266
	}
267

    
268
	@Override
269
	protected void handleToggleableCacheField() {
270
        boolean pushedState = toggleable_cache.getState();
271

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

    
277

    
278

    
279

    
280
//    @Override
281
//    public void toggleAdvancedMediaView(){
282
//        mediaDetailElement.toggleAdvancedMediaView();
283
//    }
284
}
(15-15/22)