Project

General

Profile

Download (5.02 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 org.eclipse.swt.events.SelectionListener;
13

    
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
16
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
17
import eu.etaxonomy.cdm.model.name.TaxonName;
18
import eu.etaxonomy.cdm.model.reference.NamedSource;
19
import eu.etaxonomy.cdm.model.term.TermType;
20
import eu.etaxonomy.taxeditor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
26
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28

    
29
/**
30
 *
31
 * @author n.hoffmann
32
 * @created May 17, 2010
33
 * @version 1.0
34
 */
35
public class NameTypeDesignationElement extends
36
		AbstractTypeDesignationElement<NameTypeDesignation> {
37

    
38
	private CheckboxElement checkbox_rejectedType;
39
	private CheckboxElement checkbox_conservedType;
40
	private EntitySelectionElement<TaxonName> selection_typeName;
41
	private TermComboElement<NameTypeDesignationStatus> combo_typeStatus;
42

    
43
	public NameTypeDesignationElement(CdmFormFactory formFactory,
44
			AbstractFormSection section, NameTypeDesignation entity,
45
			SelectionListener removeListener, int style) {
46
		super(formFactory, section, entity, removeListener, style);
47
	}
48

    
49
	/** {@inheritDoc} */
50
	@Override
51
	public void createControls(ICdmFormElement formElement, int style) {
52

    
53
		checkbox_rejectedType = formFactory.createCheckbox(formElement,
54
				"Rejected Type", false, style); //$NON-NLS-1$
55
		checkbox_conservedType = formFactory.createCheckbox(formElement,
56
				"Conserved Type", false, style); //$NON-NLS-1$
57
		selection_typeName = formFactory
58
				.createSelectionElement(TaxonName.class,//getConversationHolder(),
59
				        formElement, "Name", null, //$NON-NLS-1$
60
						EntitySelectionElement.ALL, style);
61
		combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.NameTypeDesignationStatus, formElement,
62
						"Designation Status", null, style); //$NON-NLS-1$
63

    
64
		super.createControls(formElement, style);
65
		if (entity != null){
66
			setEntity(entity);
67
		}
68
	}
69

    
70
	/** {@inheritDoc} */
71
	@Override
72
	public void setEntity(NameTypeDesignation entity) {
73
		super.setEntity(entity);
74
		if (checkbox_conservedType != null){
75
			checkbox_conservedType.setSelection(entity.isConservedType());
76
			checkbox_rejectedType.setSelection(entity.isRejectedType());
77
			selection_typeName.setEntity(HibernateProxyHelper.deproxy(entity.getTypeName()));
78
			combo_typeStatus.setSelection(HibernateProxyHelper.deproxy(entity.getTypeStatus(), NameTypeDesignationStatus.class));
79
			checkbox_notDesignated.setSelection(entity.isNotDesignated());
80
		}
81

    
82
	}
83

    
84
	@Override
85
	public void handleEvent(Object eventSource) {
86
		if (eventSource == checkbox_conservedType) {
87
			getEntity().setConservedType(checkbox_conservedType.getSelection());
88
		} else if (eventSource == checkbox_rejectedType) {
89
			getEntity().setRejectedType(checkbox_rejectedType.getSelection());
90
		} else if (eventSource == selection_typeName) {
91
			getEntity().setTypeName(selection_typeName.getEntity());
92
		} else if (eventSource == combo_typeStatus) {
93
		    if ((combo_typeStatus.getSelection() == null && entity.getCitation() != null)){
94
		        boolean ok = MessagingUtils.confirmDialog(Messages.NameTypeDesignationElement_4, Messages.NameTypeDesignationElement_5);
95
                if (!ok){
96
                    combo_typeStatus.setSelection(entity.getTypeStatus());
97
                    return;
98
                }
99
		    }else if ( entity.getTypeStatus() != null && getEntity().getTypeStatus().hasDesignationSource() && !combo_typeStatus.getSelection().hasDesignationSource() && entity.getCitation() != null){
100
		        boolean ok = MessagingUtils.confirmDialog(Messages.NameTypeDesignationElement_4, Messages.NameTypeDesignationElement_5);
101
                if (!ok){
102
                    combo_typeStatus.setSelection(entity.getTypeStatus());
103
                    return;
104
                }
105
            }
106
			getEntity().setTypeStatus(combo_typeStatus.getSelection());
107
			if (getEntity().hasDesignationSource()){
108
			    NamedSource source = NamedSource.NewPrimarySourceInstance(null, null);
109
                entity.setDesignationSource(source);
110
			}
111

    
112
			setEntity(entity);
113
		} else if (eventSource == checkbox_notDesignated) {
114
			getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
115
		}
116
//		else if (eventSource == selection_reference) {
117
//			getEntity().setCitation(selection_reference.getSelection());
118
//		} else if (eventSource == text_referenceDetail) {
119
//			getEntity().setCitationMicroReference(
120
//					text_referenceDetail.getText());
121
//		}
122
	}
123
}
(12-12/21)