2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.feature
;
11 import org
.eclipse
.swt
.widgets
.Label
;
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
;
32 public class TermTreeDetailElement
extends AbstractCdmDetailElement
<TermTreeDto
> {
34 private CheckboxElement allowDuplicates
;
35 private CheckboxElement orderRelevant
;
36 private CheckboxElement isFlat
;
38 private TextWithLabelElement titleCacheText
;
39 protected RepresentationElement element_Representation
;
41 public TermTreeDetailElement(CdmFormFactory formFactory
,
42 ICdmFormElement formElement
) {
43 super(formFactory
, formElement
);
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
));
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);
61 orderRelevant
= formFactory
.createCheckbox(formElement
, "Order relevant", entity
.isOrderRelevant(), style
);
63 isFlat
= formFactory
.createCheckbox(formElement
, "Is flat", entity
.isFlat(), style
);
64 if (entity
.containsSubtrees()){
65 isFlat
.setEnabled(false);
67 if (!TermBasePropertyTester
.isModifiable(entity
)) {
68 this.setEnabled(false);
73 protected void updateControlStates() {
74 super.updateControlStates();
78 public void handleEvent(Object eventSource
) {
79 if (eventSource
== titleCacheText
) {
80 getEntity().setTitleCache(titleCacheText
.getText());
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();
90 // getEntity().setLabel(selectedRepresentation.getLabel(), representationLanguage);
91 Representation rep
= getEntity().getRepresentation(representationLanguage
);
93 rep
= new Representation(selectedRepresentation
.getDescription(), selectedRepresentation
.getLabel(), selectedRepresentation
.getAbbreviatedLabel(), representationLanguage
);
94 getEntity().addRepresentation(rep
);
96 getEntity().getRepresentation(representationLanguage
).setLabel(selectedRepresentation
.getLabel());
97 getEntity().getRepresentation(representationLanguage
).setAbbreviatedLabel(selectedRepresentation
.getAbbreviatedLabel());
98 getEntity().getRepresentation(representationLanguage
).setText(selectedRepresentation
.getDescription());
101 //getEntity().setTitleCache(null);
104 if (eventSource
== allowDuplicates
) {
105 getEntity().setAllowDuplicate(allowDuplicates
.getSelection());
107 else if (eventSource
== orderRelevant
) {
108 getEntity().setOrderRelevant(orderRelevant
.getSelection());
110 else if (eventSource
== isFlat
) {
111 getEntity().setFlat(isFlat
.getSelection());
113 EventUtility
.postEvent(WorkbenchEventConstants
.ADD_SAVE_CANDIDATE
, getEntity());
117 public void fillFields() {
119 allowDuplicates
.setSelection(getEntity().isAllowDuplicate());
120 orderRelevant
.setSelection(getEntity().isOrderRelevant());
121 isFlat
.setSelection(getEntity().isFlat());
122 element_Representation
.setTermDto(getEntity(), enabled
);