fix #4249
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / vocabulary / AbstractTermBaseDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 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.vocabulary;
11
12 import eu.etaxonomy.cdm.model.common.Language;
13 import eu.etaxonomy.cdm.model.common.Representation;
14 import eu.etaxonomy.cdm.model.common.TermBase;
15 import eu.etaxonomy.cdm.model.common.TermVocabulary;
16 import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
17 import eu.etaxonomy.taxeditor.store.CdmStore;
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.element.UriWithLabelElement;
22 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
23
24 /**
25 * @author l.morris
26 * @date 20 Dec 2011
27 *
28 */
29 public abstract class AbstractTermBaseDetailElement<T extends TermBase> extends AbstractCdmDetailElement<T> {
30
31 protected TextWithLabelElement text_label;
32 protected TextWithLabelElement text_description;
33 protected UriWithLabelElement uri_uri;
34 protected TextWithLabelElement text_abbreviatedLabel;
35
36 /**
37 * @param formFactory
38 * @param formElement
39 */
40 public AbstractTermBaseDetailElement(CdmFormFactory formFactory,
41 ICdmFormElement formElement) {
42 super(formFactory, formElement);
43 }
44
45 /* (non-Javadoc)
46 * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement#createControls(eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement, java.lang.Object, int)
47 */
48 @Override
49 protected void createControls(ICdmFormElement formElement,
50 T entity, int style) {
51
52 Representation representation = getEntity().getRepresentation(CdmStore.getDefaultLanguage());
53
54 if(representation == null){
55 //formFactory.createLabel(formElement, "No represantation for the current default Language, english version is used.");
56 representation = getEntity().getRepresentation(Language.ENGLISH());
57 }
58
59 text_label = formFactory.createTextWithLabelElement(formElement, "Label", representation.getLabel(), style);
60 text_abbreviatedLabel = formFactory.createTextWithLabelElement(formElement, "Abbrev. Label", representation.getAbbreviatedLabel(), style);
61 text_description = formFactory.createMultilineTextWithLabel(formElement, "Description", 100, style);
62 text_description.setText(representation.getDescription());
63 uri_uri = formFactory.createUriWithLabelElement(formElement, "URI", getEntity().getUri(), style);
64
65 }
66
67 @Override
68 public void setEntity(T entity) {
69 super.setEntity(entity);
70 setEnabled(TermBasePropertyTester.isModifiable(entity));
71 }
72
73 protected void handleRepresentation(Object eventSource){
74 T entity = getEntity();
75 Representation representation = entity.getRepresentation(CdmStore.getDefaultLanguage());
76
77 if (representation == null){
78 return;
79 }
80
81 if (eventSource == text_label){
82 representation.setLabel(text_label.getText());
83 entity.setLabel(text_label.getText());
84 }else if (eventSource == text_abbreviatedLabel){
85 representation.setAbbreviatedLabel(text_abbreviatedLabel.getText());
86 }else if (eventSource == text_description){
87 representation.setText(text_description.getText());
88 }
89 }
90
91 public abstract TermVocabulary getVocabulary();
92
93 }