2 * Copyright (C) 2013 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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.dna
;
11 import org
.apache
.logging
.log4j
.LogManager
;
12 import org
.apache
.logging
.log4j
.Logger
;
14 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
15 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacade
;
16 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
18 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
19 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
20 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
21 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
22 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
23 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
24 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
25 import eu
.etaxonomy
.cdm
.model
.term
.VocabularyEnum
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
40 public class TissueSampleGeneralDetailElement
extends AbstractCdmDetailElement
<DerivedUnitFacade
> {
42 @SuppressWarnings("unused")
43 static private final Logger logger
= LogManager
.getLogger(TissueSampleGeneralDetailElement
.class);
45 private final TermVocabulary
<?
> plantKindOfUnitVocabulary
= CdmStore
.getService(IVocabularyService
.class).find(VocabularyEnum
.PlantKindOfUnit
.getUuid());
47 private TermComboElement
<DefinedTerm
> comboKindOfTissue
;
48 private EntitySelectionElement
<Institution
> selectionInstitution
;
49 private EntitySelectionElement
<AgentBase
> selectionStaff
;
50 private TimePeriodElement datePreparation
;
51 private TermComboElement
<DefinedTerm
> comboPreservationMedium
;
52 private EntitySelectionElement
<Collection
> selectionCollection
;
53 private TextWithLabelElement textAccessionNumber
;
54 private TextWithLabelElement textBarcode
;
55 private CheckboxElement checkIsPublish
;
57 public TissueSampleGeneralDetailElement(CdmFormFactory formFactory
, ICdmFormElement formElement
) {
58 super(formFactory
, formElement
);
62 protected void createControls(ICdmFormElement formElement
, DerivedUnitFacade facade
, int style
) {
63 DerivedUnit entity
= getEntity().innerDerivedUnit();
65 comboKindOfTissue
= formFactory
.createDefinedTermComboElement(plantKindOfUnitVocabulary
, formElement
, "Kind Of Tissue", entity
.getKindOfUnit(), style
);
66 TimePeriod preparationDate
= null;
67 DefinedTerm preservationMedium
= null;
68 AgentBase
<?
> staff
= null;
69 Institution institution
= null;
70 if(entity
.getDerivedFrom()!=null){
71 staff
= entity
.getDerivedFrom().getActor();
72 preparationDate
= entity
.getDerivedFrom().getTimeperiod();
73 institution
= entity
.getDerivedFrom().getInstitution();
75 if(entity
.getPreservation()!=null){
76 preservationMedium
= entity
.getPreservation().getMedium();
78 selectionInstitution
= formFactory
.createSelectionElement(Institution
.class,
79 formElement
, "Institution", institution
, EntitySelectionElement
.ALL
, style
);
80 selectionStaff
= formFactory
.createSelectionElement(AgentBase
.class,
81 formElement
, "Staff", staff
, EntitySelectionElement
.ALL
,style
);
82 datePreparation
= formFactory
.createTimePeriodElement(formElement
, "Preparation date", preparationDate
, style
);
83 comboPreservationMedium
= formFactory
.createDefinedTermComboElement(TermType
.MaterialOrMethod
, formElement
, "Preservation medium", preservationMedium
, style
);
84 selectionCollection
= formFactory
.createSelectionElement(Collection
.class,
85 formElement
, "Collection", entity
.getCollection(), EntitySelectionElement
.ALL
, style
);
86 textAccessionNumber
= formFactory
.createTextWithLabelElement(formElement
, "Accession Number", entity
.getAccessionNumber(), style
);
87 textBarcode
= formFactory
.createTextWithLabelElement(formElement
, "Barcode", entity
.getBarcode(), style
);
88 checkIsPublish
= formFactory
.createCheckbox(formElement
, "Publish", entity
.isPublish(), style
);
92 public void handleEvent(Object eventSource
) {
93 DerivedUnit entity
= getEntity().innerDerivedUnit();
94 if(eventSource
==comboKindOfTissue
) {
95 entity
.setKindOfUnit(comboKindOfTissue
.getSelection());
97 else if(eventSource
==comboPreservationMedium
) {
98 addPreservationMethod().setMedium(comboPreservationMedium
.getSelection());
100 else if(eventSource
==selectionCollection
){
101 getEntity().setCollection(selectionCollection
.getSelection());
103 else if(eventSource
==textAccessionNumber
){
104 getEntity().setAccessionNumber(textAccessionNumber
.getText());
106 else if(eventSource
==textBarcode
){
107 getEntity().setBarcode(textBarcode
.getText());
109 else if(eventSource
==datePreparation
){
110 if(entity
.getDerivedFrom()!=null){
111 entity
.getDerivedFrom().setTimeperiod(datePreparation
.getTimePeriod());
114 else if(eventSource
==selectionInstitution
){
115 if(entity
.getDerivedFrom()!=null){
116 entity
.getDerivedFrom().setInstitution(selectionInstitution
.getSelection());
119 else if(eventSource
==selectionStaff
){
120 if(entity
.getDerivedFrom()!=null){
121 entity
.getDerivedFrom().setActor(selectionStaff
.getSelection());
124 else if(eventSource
==checkIsPublish
){
125 entity
.setPublish(checkIsPublish
.getSelection());
129 private PreservationMethod
addPreservationMethod(){
130 DerivedUnit entity
= getEntity().innerDerivedUnit();
131 PreservationMethod preservationMethod
= null;
132 preservationMethod
= entity
.getPreservation();
133 if(entity
.getPreservation()==null){
134 preservationMethod
= PreservationMethod
.NewInstance();
135 entity
.setPreservation(preservationMethod
);
137 return preservationMethod
;
141 public void fillFields() {
144 // comboKindOfTissue;
145 // selectionInstitution;
148 // comboPreservationMedium;
149 // selectionCollection;
150 // textAccessionNumber;