4910a83a53c8db3babb15e62f815e2c1c6c14e18
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / TermTreeDetailElement.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.feature;
10
11 import org.eclipse.swt.widgets.Label;
12
13 import eu.etaxonomy.cdm.model.common.Language;
14 import eu.etaxonomy.cdm.model.term.Representation;
15 import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
16 import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
17 import eu.etaxonomy.taxeditor.event.EventUtility;
18 import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
19 import eu.etaxonomy.taxeditor.model.ColorResources;
20 import eu.etaxonomy.taxeditor.preference.Resources;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
25 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
26 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
27
28 /**
29 * @author pplitzner
30 * @since Dec 21, 2017
31 */
32 public class TermTreeDetailElement extends AbstractCdmDetailElement<TermTreeDto> {
33
34 private CheckboxElement allowDuplicates;
35 private CheckboxElement orderRelevant;
36 private CheckboxElement isFlat;
37
38 private TextWithLabelElement titleCacheText;
39 protected RepresentationElement element_Representation;
40
41 public TermTreeDetailElement(CdmFormFactory formFactory,
42 ICdmFormElement formElement) {
43 super(formFactory, formElement);
44 }
45
46 @Override
47 protected void createControls(ICdmFormElement formElement, TermTreeDto entity, int style) {
48 Label lblTermType = new Label(formElement.getLayoutComposite(), style);
49 lblTermType.setText("Term Type");
50 Label lblStructureText = new Label(formElement.getLayoutComposite(), style);
51 lblStructureText.setText(entity.getTermType().getLabel());
52 lblStructureText.setForeground(ColorResources.getColor(Resources.BLACK));
53
54 titleCacheText = formFactory.createTextWithLabelElement(
55 formElement, "Title Cache", entity.getTitleCache(), style);
56 //element_Representation = formFactory.createTranslatableRepresentationElementDto(formElement, entity.getPreferredRepresentation(CdmStore.getDefaultLanguage()),entity, 100, style, true);
57 allowDuplicates = formFactory.createCheckbox(formElement, "Allow duplicates", entity.isAllowDuplicate(), style);
58 if (entity.isContainsDuplicates() && entity.isAllowDuplicate()){
59 allowDuplicates.setEnabled(false);
60 }
61 orderRelevant = formFactory.createCheckbox(formElement, "Order relevant", entity.isOrderRelevant(), style);
62
63 isFlat = formFactory.createCheckbox(formElement, "Is flat", entity.isFlat(), style);
64 if (entity.containsSubtrees()){
65 isFlat.setEnabled(false);
66 }
67 if (!TermBasePropertyTester.isModifiable(entity)) {
68 this.setEnabled(false);
69 }
70 }
71
72 @Override
73 protected void updateControlStates() {
74 super.updateControlStates();
75 }
76
77 @Override
78 public void handleEvent(Object eventSource) {
79 if (eventSource == titleCacheText) {
80 getEntity().setTitleCache(titleCacheText.getText());
81 }
82 if (eventSource == element_Representation) {
83 // getEntity().setTitleCache(titleCacheText.getText());
84 Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
85 if(selectedRepresentation!=null){
86 Language representationLanguage = selectedRepresentation.getLanguage();
87 if(representationLanguage==null){
88 representationLanguage = Language.getDefaultLanguage();
89 }
90 // getEntity().setLabel(selectedRepresentation.getLabel(), representationLanguage);
91 Representation rep = getEntity().getRepresentation(representationLanguage);
92 if (rep == null){
93 rep = new Representation(selectedRepresentation.getDescription(), selectedRepresentation.getLabel(), selectedRepresentation.getAbbreviatedLabel(), representationLanguage);
94 getEntity().addRepresentation(rep);
95 }else{
96 getEntity().getRepresentation(representationLanguage).setLabel(selectedRepresentation.getLabel());
97 getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
98 getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
99 }
100 }
101 //getEntity().setTitleCache(null);
102 }
103 else
104 if (eventSource == allowDuplicates) {
105 getEntity().setAllowDuplicate(allowDuplicates.getSelection());
106 }
107 else if (eventSource == orderRelevant) {
108 getEntity().setOrderRelevant(orderRelevant.getSelection());
109 }
110 else if (eventSource == isFlat) {
111 getEntity().setFlat(isFlat.getSelection());
112 }
113 EventUtility.postEvent(WorkbenchEventConstants.ADD_SAVE_CANDIDATE, getEntity());
114 }
115
116 @Override
117 public void fillFields() {
118
119 allowDuplicates.setSelection(getEntity().isAllowDuplicate());
120 orderRelevant.setSelection(getEntity().isOrderRelevant());
121 isFlat.setSelection(getEntity().isFlat());
122 element_Representation.setTermDto(getEntity(), enabled);
123
124 }
125 }