3a56e5c1f9e58750b6352a0052fd3c66aa10d185
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / detail / TaxonInteractionDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.ui.section.description.detail;
12
13 import org.eclipse.swt.SWT;
14
15 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
16 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
17 import eu.etaxonomy.cdm.model.taxon.Taxon;
18 import eu.etaxonomy.taxeditor.store.CdmStore;
19 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
22 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
23
24 /**
25 * <p>
26 * TaxonInteractionDetailElement class.
27 * </p>
28 *
29 * @author n.hoffmann
30 * @created Jun 10, 2010
31 * @version 1.0
32 */
33 public class TaxonInteractionDetailElement extends
34 AbstractDetailedDescriptionDetailElement<TaxonInteraction> {
35
36 private EntitySelectionElement<Taxon> taxonSelection;
37 private TextWithLabelElement interactionDescription;
38
39 /**
40 * <p>
41 * Constructor for TaxonInteractionDetailElement.
42 * </p>
43 *
44 * @param formFactory
45 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
46 * object.
47 * @param formElement
48 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
49 * object.
50 * @param entity
51 * a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction}
52 * object.
53 * @param style
54 * a int.
55 */
56 public TaxonInteractionDetailElement(CdmFormFactory formFactory,
57 ICdmFormElement formElement, TaxonInteraction entity, int style) {
58 super(formFactory, formElement, entity, style);
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 protected void createControls(ICdmFormElement formElement,
64 TaxonInteraction entity, int style) {
65 taxonSelection = formFactory
66 .createSelectionElement(Taxon.class,
67 getConversationHolder(), this, "Taxon",
68 entity.getTaxon2(), EntitySelectionElement.NOTHING,
69 SWT.WRAP);
70
71 interactionDescription = formFactory.createMultiLineTextWithLabel(this,
72 "Relationship to the taxon:", 200, SWT.WRAP);
73 entity = HibernateProxyHelper.deproxy(entity, TaxonInteraction.class);
74 interactionDescription.setText(entity.getDescription(CdmStore
75 .getDefaultLanguage()));
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 public void handleEvent(Object eventSource) {
81 if (eventSource == taxonSelection) {
82 getEntity().setTaxon2(taxonSelection.getEntity());
83 } else if (eventSource == interactionDescription) {
84 getEntity().putDescription(CdmStore.getDefaultLanguage(), interactionDescription.getText());
85 }
86 }
87 }