smaller changes to display taxon interactions
[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 java.util.Map;
14
15 import eu.etaxonomy.cdm.model.common.CdmBase;
16 import eu.etaxonomy.cdm.model.common.Language;
17 import eu.etaxonomy.cdm.model.common.LanguageString;
18 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
19 import eu.etaxonomy.cdm.model.taxon.Taxon;
20 import eu.etaxonomy.taxeditor.store.CdmStore;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
24 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
25
26 /**
27 * <p>
28 * TaxonInteractionDetailElement class.
29 * </p>
30 *
31 * @author n.hoffmann
32 * @created Jun 10, 2010
33 * @version 1.0
34 */
35 public class TaxonInteractionDetailElement extends
36 AbstractDetailedDescriptionDetailElement<TaxonInteraction> {
37
38 private EntitySelectionElement<Taxon> taxonSelection;
39 private TextWithLabelElement interactionDescription;
40
41 /**
42 * <p>
43 * Constructor for TaxonInteractionDetailElement.
44 * </p>
45 *
46 * @param formFactory
47 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
48 * object.
49 * @param formElement
50 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
51 * object.
52 * @param entity
53 * a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction}
54 * object.
55 * @param style
56 * a int.
57 */
58 public TaxonInteractionDetailElement(CdmFormFactory formFactory,
59 ICdmFormElement formElement, TaxonInteraction entity, int style) {
60 super(formFactory, formElement, entity, style);
61 }
62
63 /** {@inheritDoc} */
64 @Override
65 protected void createControls(ICdmFormElement formElement,
66 TaxonInteraction entity, int style) {
67
68 taxonSelection = formFactory
69 .createSelectionElement(Taxon.class,
70 getConversationHolder(), formElement, "Taxon",
71 CdmBase.deproxy(entity.getTaxon2(),Taxon.class),
72 EntitySelectionElement.ALL, style);
73
74 interactionDescription = formFactory.createMultiLineTextWithLabel(
75 formElement, "Relationship to the unit:", 200, style);
76 Map<Language, LanguageString> descriptions = entity.getDescription();
77
78 if (descriptions.get(CdmStore.getDefaultLanguage()) != null) {
79 interactionDescription.setText(descriptions.get(
80 CdmStore.getDefaultLanguage()).getText());
81 }
82 }
83
84 /** {@inheritDoc} */
85 @Override
86 public void handleEvent(Object eventSource) {
87 if (eventSource == taxonSelection) {
88 getEntity().setTaxon2(taxonSelection.getEntity());
89 } else if (eventSource == interactionDescription) {
90 getEntity().putDescription(CdmStore.getDefaultLanguage(), interactionDescription.getText());
91 }
92 }
93 }