Project

General

Profile

Download (5.51 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.Comparator;
13
import java.util.List;
14

    
15
import org.eclipse.swt.events.SelectionListener;
16

    
17
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
19
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
20
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.term.TermType;
22
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
26
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
27
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
29
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
30
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
31
import eu.etaxonomy.taxeditor.ui.element.LabelElement;
32
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
33
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
34
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityElement;
35

    
36
/**
37
 * @author n.hoffmann
38
 * @created Nov 5, 2009
39
 */
40
public class NomenclaturalStatusElement extends AbstractSourcedEntityElement<NomenclaturalStatus> implements IEntityElement<NomenclaturalStatus>, ISelectableElement{
41

    
42
	private TermComboElement<NomenclaturalStatusType> nomenclaturalStatusTypeCombo;
43

    
44
	private RuleConsideredElement ruleConsidered;
45

    
46

    
47

    
48
	private final SelectionArbitrator selectionArbitrator;
49

    
50
	public NomenclaturalStatusElement(CdmFormFactory cdmFormFactory, AbstractFormSection formElement,
51
			NomenclaturalStatus element, SelectionListener removeListener, int style) {
52
		super(cdmFormFactory, formElement, element, removeListener, "Source", style);
53
		selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
54
	}
55

    
56
	/** {@inheritDoc} */
57
	@Override
58
	public void createControls(ICdmFormElement element, int style) {
59
	    //TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
60
	    NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
61
	    Comparator<NomenclaturalStatusType> termComparator= new Comparator<NomenclaturalStatusType>() {
62

    
63
            @Override
64
            public int compare(NomenclaturalStatusType t1, NomenclaturalStatusType t2) {
65
                if (t1 == t2){
66
                    return 0;
67
                }
68
                if (t1 == null){
69
                    return -1;
70
                }
71
                if (t2 == null){
72
                    return 1;
73
                }
74
                if (t1.getIdInVocabulary() == t2.getIdInVocabulary()){
75
                    return 0;
76
                }
77
                if (t1.getIdInVocabulary() == null ){
78
                    return t1.getLabel().compareTo(t2.getIdInVocabulary());
79
                }
80
                if (t2.getIdInVocabulary() == null){
81
                    return t1.getIdInVocabulary().compareTo(t2.getLabel());
82
                }
83
                return t1.getIdInVocabulary().compareTo(t2.getIdInVocabulary());
84

    
85
            }
86
        };
87

    
88
        String availableStatus = PreferencesUtil.getStringValue(PreferencePredicate.AvailableNomenclaturalStatus.getKey());
89
        List<NomenclaturalStatusType> allStatus = CdmStore.getTermManager().createTermListFromString(availableStatus, TermType.NomenclaturalStatusType);
90

    
91
		nomenclaturalStatusTypeCombo = formFactory.createDefinedTermComboElement(allStatus, this, "Status", null,style, termComparator);
92

    
93
		if (config == null || config.isNomenclaturalStatusRuleConsideredActivated()){
94
		    ruleConsidered = formFactory.createRuleConsideredElement(this, "Rule Considered", config == null || config.isNomenclaturalStatusRuleConsideredCodeEditionActivated(), style);
95
		}
96
		setSourceLabel("Source");
97
		LabelElement spacer = formFactory.createLabel(this, null);
98
        spacer.getLayoutComposite().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
99
        addElement(spacer);
100
		super.createControls(element, style);
101
		if (entity != null){
102
			setEntity(entity);
103
		}
104

    
105

    
106
	}
107

    
108
	/** {@inheritDoc} */
109
	@Override
110
	public void setEntity(NomenclaturalStatus entity) {
111
		super.setEntity(entity);
112
		if (nomenclaturalStatusTypeCombo != null){
113
			if (entity.getType() != null){
114
			    nomenclaturalStatusTypeCombo.setSelection(entity.getType());
115
			    nomenclaturalStatusTypeCombo.removeEmptyElement();
116
			}
117
			if (ruleConsidered != null){
118
			    ruleConsidered.setElement(entity);
119
			}
120
		}
121
	}
122

    
123
	/**
124
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
125
	 *
126
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
127
	 */
128
	@Override
129
    public SelectionArbitrator getSelectionArbitrator() {
130
		return selectionArbitrator;
131
	}
132

    
133
	/** {@inheritDoc} */
134
	@Override
135
	public void handleEvent(Object eventSource) {
136
		if(eventSource == nomenclaturalStatusTypeCombo){
137
			getEntity().setType(nomenclaturalStatusTypeCombo.getSelection());
138
		}
139

    
140
//		else if(eventSource == selection_reference){
141
//			getEntity().setCitation(selection_reference.getSelection());
142
//		}
143
//		else if(eventSource == text_referenceDetail){
144
//			getEntity().setCitationMicroReference(text_referenceDetail.getText());
145
//		}
146
	}
147
}
(13-13/21)