ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / association / DerivedUnitTypeDesignationElement.java
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.occurrence.association;
11
12 import java.util.List;
13 import java.util.Set;
14
15 import org.eclipse.swt.events.SelectionListener;
16
17 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18 import eu.etaxonomy.cdm.model.common.TermType;
19 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
20 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
23 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
24 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26 import eu.etaxonomy.taxeditor.ui.section.name.AbstractTypeDesignationElement;
27 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28
29 /**
30 * @author n.hoffmann
31 * @created May 17, 2010
32 * @version 1.0
33 */
34 public class DerivedUnitTypeDesignationElement extends AbstractTypeDesignationElement<SpecimenTypeDesignation> {
35
36 private TermComboElement<SpecimenTypeDesignationStatus> combo_typeStatus;
37
38 private List<EntitySelectionElement<TaxonNameBase>> selectionTaxonNames;
39 private ICdmFormElement parentFormElement;
40 private int style;
41
42 private EntitySelectionElement<TaxonNameBase> selectionTaxonName;
43
44 public DerivedUnitTypeDesignationElement(CdmFormFactory formFactory,
45 AbstractFormSection section, SpecimenTypeDesignation entity,
46 SelectionListener removeListener, int style) {
47 super(formFactory, section, entity, removeListener, style);
48 }
49
50 @Override
51 public void setEntity(SpecimenTypeDesignation entity) {
52 super.setEntity(entity);
53 Set<TaxonNameBase> typifiedNames = entity.getTypifiedNames();
54 if(typifiedNames.size()==1){
55 selectionTaxonName.setEntity(typifiedNames.iterator().next());
56 }
57 else if(typifiedNames.size()>1){
58 formFactory.createLabel(getLayoutComposite(), "!!!!!!!!");
59 }
60
61 SpecimenTypeDesignationStatus typeStatus = (SpecimenTypeDesignationStatus) HibernateProxyHelper
62 .deproxy(entity.getTypeStatus());
63 combo_typeStatus.setSelection(typeStatus);
64 checkbox_notDesignated.setSelection(entity.isNotDesignated());
65
66 // for (TaxonNameBase taxonNameBase : typifiedNames) {
67 // EntitySelectionElement<TaxonNameBase> selectionElement = formFactory.createSelectionElement(
68 // TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
69 // EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
70 // selectionElement.setEntity(taxonNameBase);
71 // }
72
73
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 public void createControls(ICdmFormElement element, int style) {
79 this.parentFormElement = element;
80 this.style = style;
81
82 selectionTaxonName = formFactory.createSelectionElement(
83 TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
84 EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
85
86 combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
87 parentFormElement, "Designation Status", null, style);
88
89 super.createControls(element, style);
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public void handleEvent(Object eventSource) {
95 if (eventSource == selectionTaxonName) {
96 selectionTaxonName.getSelection().addTypeDesignation(getEntity(), false);
97 } else if (eventSource == combo_typeStatus) {
98 getEntity().setTypeStatus(combo_typeStatus.getSelection());
99 } else if (eventSource == checkbox_notDesignated) {
100 getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
101 } else if (eventSource == selection_reference) {
102 getEntity().setCitation(selection_reference.getSelection());
103 } else if (eventSource == text_referenceDetail) {
104 getEntity().setCitationMicroReference(
105 text_referenceDetail.getText());
106 }
107 }
108
109 }