2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Comparator
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
18 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
19 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
20 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
21 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEntityElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.LabelElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
30 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.AbstractSourcedEntityElement
;
34 * @created Nov 5, 2009
36 public class NomenclaturalStatusElement
extends AbstractSourcedEntityElement
<NomenclaturalStatus
> implements IEntityElement
<NomenclaturalStatus
>, ISelectableElement
{
38 private TermComboElement
<NomenclaturalStatusType
> nomenclaturalStatusTypeCombo
;
40 private RuleConsideredElement ruleConsidered
;
44 private final SelectionArbitrator selectionArbitrator
;
46 public NomenclaturalStatusElement(CdmFormFactory cdmFormFactory
, AbstractFormSection formElement
,
47 NomenclaturalStatus element
, SelectionListener removeListener
, int style
) {
48 super(cdmFormFactory
, formElement
, element
, removeListener
, "Source", style
);
49 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
54 public void createControls(ICdmFormElement element
, int style
) {
55 //TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
56 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
57 Comparator
<NomenclaturalStatusType
> termComparator
= new Comparator
<NomenclaturalStatusType
>() {
60 public int compare(NomenclaturalStatusType t1
, NomenclaturalStatusType t2
) {
70 if (t1
.getIdInVocabulary() == t2
.getIdInVocabulary()){
73 if (t1
.getIdInVocabulary() == null ){
74 return t1
.getLabel().compareTo(t2
.getIdInVocabulary());
76 if (t2
.getIdInVocabulary() == null){
77 return t1
.getIdInVocabulary().compareTo(t2
.getLabel());
79 return t1
.getIdInVocabulary().compareTo(t2
.getIdInVocabulary());
84 nomenclaturalStatusTypeCombo
= formFactory
.createDefinedTermComboElement(TermType
.NomenclaturalStatusType
, this, "Status", null,true, style
, true);
85 nomenclaturalStatusTypeCombo
.setTermComparator(termComparator
);
86 if (config
== null || config
.isNomenclaturalStatusRuleConsideredActivated()){
87 ruleConsidered
= formFactory
.createRuleConsideredElement(this, "Rule Considered", config
== null || config
.isNomenclaturalStatusRuleConsideredCodeEditionActivated(), style
);
89 setSourceLabel("Source");
90 LabelElement spacer
= formFactory
.createLabel(this, null);
91 spacer
.getLayoutComposite().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
93 super.createControls(element
, style
);
100 public void setEntity(NomenclaturalStatus entity
) {
101 super.setEntity(entity
);
102 if (entity
.getType() != null){
103 nomenclaturalStatusTypeCombo
.setSelection(entity
.getType());
104 nomenclaturalStatusTypeCombo
.removeEmptyElement();
106 if (ruleConsidered
!= null){
107 ruleConsidered
.setElement(entity
);
112 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
114 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
117 public SelectionArbitrator
getSelectionArbitrator() {
118 return selectionArbitrator
;
123 public void handleEvent(Object eventSource
) {
124 if(eventSource
== nomenclaturalStatusTypeCombo
){
125 getEntity().setType(nomenclaturalStatusTypeCombo
.getSelection());
128 // else if(eventSource == selection_reference){
129 // getEntity().setCitation(selection_reference.getSelection());
131 // else if(eventSource == text_referenceDetail){
132 // getEntity().setCitationMicroReference(text_referenceDetail.getText());