Merge branch 'release/5.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / vocabulary / AbstractTermBaseDetailElement.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.ui.section.vocabulary;
10
11 import org.eclipse.swt.widgets.Button;
12
13 import eu.etaxonomy.cdm.model.common.Language;
14 import eu.etaxonomy.cdm.model.term.Representation;
15 import eu.etaxonomy.cdm.model.term.TermBase;
16 import eu.etaxonomy.cdm.model.term.TermVocabulary;
17 import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
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.RepresentationElement;
22 import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
23 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
24
25 /**
26 * @author l.morris
27 * @date 20 Dec 2011
28 *
29 */
30 public abstract class AbstractTermBaseDetailElement<T extends TermBase> extends AbstractCdmDetailElement<T> {
31
32 protected UriWithLabelElement uri_uri;
33 protected RepresentationElement element_Representation;
34 private Button button;
35
36
37 public AbstractTermBaseDetailElement(CdmFormFactory formFactory,
38 ICdmFormElement formElement) {
39 super(formFactory, formElement);
40 }
41
42 @Override
43 protected void createControls(ICdmFormElement formElement,
44 T entity, int style) {
45 element_Representation = formFactory.createTranslatableRepresentationElement(formElement, getEntity().getPreferredRepresentation(CdmStore.getDefaultLanguage()),getEntity(), 100, style, true);
46 uri_uri = formFactory.createUriWithLabelElement(formElement, "URI", getEntity().getUri(), style);
47 }
48
49 @Override
50 public void setEntity(T entity) {
51 super.setEntity(entity);
52 setEnabled(TermBasePropertyTester.isModifiable(entity));
53 }
54
55 @Override
56 public void handleEvent(Object eventSource) {
57 if (eventSource == uri_uri) {
58 getEntity().setUri(uri_uri.parseText());
59 }
60 else if (eventSource == element_Representation) {
61 Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
62 if(selectedRepresentation!=null){
63 Language representationLanguage = selectedRepresentation.getLanguage();
64 if(representationLanguage==null){
65 representationLanguage = Language.getDefaultLanguage();
66 }
67 getEntity().setLabel(selectedRepresentation.getLabel(), representationLanguage);
68 getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
69 getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
70 }
71 getEntity().setTitleCache(null);
72 }
73 }
74
75 public abstract TermVocabulary getVocabulary();
76
77 }