Project

General

Profile

Download (4.86 KB) Statistics
| Branch: | Tag: | Revision:
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.event.EventUtility;
17
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
18
import eu.etaxonomy.taxeditor.model.ColorResources;
19
import eu.etaxonomy.taxeditor.preference.Resources;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
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
	}
68

    
69
	@Override
70
	protected void updateControlStates() {
71
	    super.updateControlStates();
72
	}
73

    
74
	@Override
75
	public void handleEvent(Object eventSource) {
76
	    if (eventSource == element_Representation) {
77
//	            getEntity().setTitleCache(titleCacheText.getText());
78
	    	Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
79
            if(selectedRepresentation!=null){
80
                Language representationLanguage = selectedRepresentation.getLanguage();
81
                if(representationLanguage==null){
82
                    representationLanguage = Language.getDefaultLanguage();
83
                }
84
//                getEntity().setLabel(selectedRepresentation.getLabel(),  representationLanguage);
85
                Representation rep = getEntity().getRepresentation(representationLanguage);
86
                if (rep == null){
87
                	rep = new Representation(selectedRepresentation.getDescription(), selectedRepresentation.getLabel(), selectedRepresentation.getAbbreviatedLabel(), representationLanguage);
88
                	getEntity().addRepresentation(rep);
89
                }else{
90
                	getEntity().getRepresentation(representationLanguage).setLabel(selectedRepresentation.getLabel());
91
                	getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
92
                	getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
93
                }
94
            }
95
            getEntity().setTitleCache(null);
96
        }
97
	    else
98
	    if (eventSource == allowDuplicates) {
99
	        getEntity().setAllowDuplicate(allowDuplicates.getSelection());
100
	    }
101
	    else if (eventSource == orderRelevant) {
102
	        getEntity().setOrderRelevant(orderRelevant.getSelection());
103
	    }
104
	    else if (eventSource == isFlat) {
105
	        getEntity().setFlat(isFlat.getSelection());
106
	    }
107
	    EventUtility.postEvent(WorkbenchEventConstants.ADD_SAVE_CANDIDATE, getEntity());
108
	}
109
}
(25-25/28)