0b6e10994d7067703c0577ffe08a6a1d32b54553
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / dna / SequenceReferenceCollectionDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 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.swt.SWT;
13 import org.eclipse.swt.events.SelectionListener;
14
15 import eu.etaxonomy.cdm.model.molecular.Sequence;
16 import eu.etaxonomy.cdm.model.reference.Reference;
17 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
18 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
21 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
22 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
23
24 /**
25 * @author pplitzner
26 * @date 07.01.2014
27 *
28 */
29 public class SequenceReferenceCollectionDetailElement extends AbstractEntityCollectionElement<Reference<?>>{
30
31 protected EntitySelectionElement<Reference> selection_reference;
32 protected TextWithLabelElement text_referenceDetail;
33
34 public SequenceReferenceCollectionDetailElement(CdmFormFactory formFactory,
35 AbstractFormSection<?> section, Reference<?> entity,
36 SelectionListener removeListener, int style) {
37 super(formFactory, section, entity, removeListener, null, style);
38 }
39
40 /** {@inheritDoc} */
41 @Override
42 public void createControls(ICdmFormElement formElement, int style) {
43 selection_reference = formFactory
44 .createSelectionElement(Reference.class,
45 getConversationHolder(), formElement, "Reference",
46 null, EntitySelectionElement.SELECTABLE|EntitySelectionElement.EDITABLE, style);
47 text_referenceDetail = formFactory.createTextWithLabelElement(
48 formElement, "Reference Detail", null, SWT.NULL);
49 }
50
51 @Override
52 public void setEntity(Reference<?> entity) {
53 this.entity = entity;
54 selection_reference.setEntity(entity);
55 text_referenceDetail.setText(entity.getReferenceAbstract());
56 }
57
58 @Override
59 public void handleEvent(Object eventSource) {
60 if(eventSource==selection_reference){
61 if(getParentElement() instanceof SequenceReferenceCollectionDetailSection){
62 Sequence sequence = ((SequenceReferenceCollectionDetailSection) getParentElement()).getEntity();
63 sequence.removeCitation(entity);
64 Reference<?> newCitation = selection_reference.getSelection();
65 sequence.addCitation(newCitation);
66 entity = newCitation;
67
68 text_referenceDetail.setEnabled(true);
69 }
70 } else if(eventSource==text_referenceDetail){
71 entity.setReferenceAbstract(text_referenceDetail.getText());
72 }
73 }
74
75 }