- moved ICdmFormElement to ui.element
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / dna / SequenceGeneralDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
11
12 import org.eclipse.ui.forms.widgets.ExpandableComposite;
13
14 import eu.etaxonomy.cdm.model.common.DefinedTerm;
15 import eu.etaxonomy.cdm.model.molecular.Sequence;
16 import eu.etaxonomy.cdm.model.molecular.SequenceString;
17 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
18 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
21 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
22 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
23 import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
25
26 /**
27 * @author pplitzner
28 * @date 19.12.2013
29 *
30 */
31 public class SequenceGeneralDetailElement extends AbstractCdmDetailElement<Sequence> {
32
33 private TermComboElement<DefinedTerm> comboMarker;
34 private TextWithLabelElement textContigFile;
35 private TextWithLabelElement textConsensusSequence;
36 private NumberWithLabelElement textConsensusSequenceLength;
37 private TextWithLabelElement textBarcodeSequence;
38 private TextWithLabelElement textGeneticAccessNo;
39 private TextWithLabelElement textBoldProcessID;
40 private UriWithLabelElement textBoldUri;
41
42 private SequenceReferenceCollectionDetailSection sectionReferenceCollection;
43
44 /**
45 * @param formFactory
46 * @param formElement
47 */
48 public SequenceGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
49 super(formFactory, formElement);
50 }
51
52 /*
53 * (non-Javadoc)
54 *
55 * @see
56 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
57 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
58 */
59 @Override
60 protected void createControls(ICdmFormElement formElement, Sequence entity, int style) {
61 comboMarker = formFactory.createTermComboElement(DefinedTerm.class, formElement, "DNA Marker",
62 entity.getDnaMarker(),
63 style);
64 textContigFile = formFactory.createTextWithLabelElement(formElement, "Contig File", "XXX", style);
65 textConsensusSequence = formFactory.createTextWithLabelElement(formElement, "Consensus Sequence 5'->3'", entity.getConsensusSequence().getString(), style);
66 textConsensusSequenceLength = formFactory.createNumberTextWithLabelElement(formElement, "Consensus Seq. Length", entity.getConsensusSequence().getLength(), style);
67 textBarcodeSequence = formFactory.createTextWithLabelElement(formElement, "Barcode Sequence 5'->3'", entity.getBarcodeSequencePart()==null?"":entity.getBarcodeSequencePart().getString(), style);
68
69 textGeneticAccessNo = formFactory.createTextWithLabelElement(formElement, "Genetic Acc. No.", entity.getGeneticAccessionNumber(), style);
70 textBoldProcessID = formFactory.createTextWithLabelElement(formElement, "BOLD Process ID", entity.getBoldProcessId(), style);
71 textBoldUri = formFactory.createUriWithLabelElement(formElement, "BOLD URI", entity.getBoldUri(), style);
72 textBoldUri.setEnabled(false);
73
74 sectionReferenceCollection = formFactory.createSequenceReferenceCollectionDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
75 sectionReferenceCollection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
76 sectionReferenceCollection.setEntity(entity);
77 }
78
79 /*
80 * (non-Javadoc)
81 *
82 * @see
83 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
84 * .lang.Object)
85 */
86 @Override
87 public void handleEvent(Object eventSource) {
88 if(eventSource==comboMarker){
89 getEntity().setDnaMarker(comboMarker.getSelection());
90 }
91 else if(eventSource==textContigFile){
92
93 }
94 else if(eventSource==textConsensusSequence){
95 SequenceString consensusSequence = getEntity().getConsensusSequence();
96 if(consensusSequence==null){
97 consensusSequence = SequenceString.NewInstance();
98 }
99 consensusSequence.setString(textConsensusSequence.getText());
100 getEntity().setConsensusSequence(consensusSequence);
101 }
102 else if(eventSource==textConsensusSequenceLength){
103 SequenceString consensusSequence = getEntity().getConsensusSequence();
104 if(consensusSequence==null){
105 consensusSequence = SequenceString.NewInstance();
106 }
107 consensusSequence.setLength(textConsensusSequenceLength.getInteger());
108 getEntity().setConsensusSequence(consensusSequence);
109 }
110 else if(eventSource==textBarcodeSequence){
111 SequenceString barcodeSequencePart = getEntity().getBarcodeSequencePart();
112 if(barcodeSequencePart==null){
113 barcodeSequencePart = SequenceString.NewInstance();
114 }
115 barcodeSequencePart.setString(textBarcodeSequence.getText());
116 getEntity().setBarcodeSequencePart(barcodeSequencePart);
117 }
118 else if(eventSource==textGeneticAccessNo){
119 getEntity().setGeneticAccessionNumber(textGeneticAccessNo.getText());
120 }
121 else if(eventSource==textBoldProcessID){
122 getEntity().setBoldProcessId(textBoldProcessID.getText());
123 if(textBoldProcessID.getText()!=null && !textBoldProcessID.getText().isEmpty()){
124 textBoldUri.setUri(getEntity().getBoldUri());
125 }
126 else{
127 textBoldUri.setText("");
128 }
129 }
130 else if(eventSource==textBoldUri){
131 //cannot be set because it is generated from the genetic access number and a base URI
132 }
133 }
134
135 }