Merge branch 'develop' into unify_derivative_views
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / detail / IndividualsAssociationDetailElement.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.IndividualsAssociation;
19 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
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 * @author n.hoffmann
28 * @created Jun 10, 2010
29 * @version 1.0
30 */
31 public class IndividualsAssociationDetailElement extends
32 AbstractDetailedDescriptionDetailElement<IndividualsAssociation> {
33
34 private TextWithLabelElement text_description;
35 private EntitySelectionElement<SpecimenOrObservationBase> selection_derivedUnit;
36
37 public IndividualsAssociationDetailElement(CdmFormFactory formFactory,
38 ICdmFormElement formElement, IndividualsAssociation entity,
39 int style) {
40 super(formFactory, formElement, entity, style);
41 }
42
43 /** {@inheritDoc} */
44 @Override
45 protected void createControls(ICdmFormElement formElement,
46 IndividualsAssociation entity, int style) {
47 selection_derivedUnit = formFactory
48 .createSelectionElement(SpecimenOrObservationBase.class,
49 getConversationHolder(), formElement, "Occurrence/Unit",
50 CdmBase.deproxy(entity.getAssociatedSpecimenOrObservation(),SpecimenOrObservationBase.class),
51 EntitySelectionElement.ALL, style);
52
53 text_description = formFactory.createMultiLineTextWithLabel(
54 formElement, "Relationship to the unit:", 200, style);
55 Map<Language, LanguageString> descriptions = entity.getDescription();
56
57 if (descriptions.get(CdmStore.getDefaultLanguage()) != null) {
58 text_description.setText(descriptions.get(
59 CdmStore.getDefaultLanguage()).getText());
60 }
61 }
62
63 /** {@inheritDoc} */
64 @Override
65 public void handleEvent(Object eventSource) {
66 if (eventSource == selection_derivedUnit) {
67 getEntity().setAssociatedSpecimenOrObservation(
68 selection_derivedUnit.getEntity());
69 } else if (eventSource == text_description) {
70 getEntity().putDescription(CdmStore.getDefaultLanguage(), text_description.getText());
71 }
72
73 }
74 }