Project

General

Profile

Download (1.49 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2021 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.termtree.e4;
10

    
11
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.ViewerComparator;
13

    
14
import eu.etaxonomy.cdm.common.CdmUtils;
15
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
16
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
17
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18

    
19

    
20
/**
21
 * @author k.luther
22
 * @since Mar 1, 2021
23
 */
24
public class TermTreeSorter extends ViewerComparator {
25

    
26

    
27
    @Override
28
    public int compare(Viewer viewer, Object e1, Object e2) {
29
        if (e1 instanceof TermNodeDto && e2 instanceof TermNodeDto){
30
            boolean showIdInVoc = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS, true);
31
            String label1 = ((TermNodeDto) e1).getTerm().getRepresentation_L10n();
32
            String label2 = ((TermNodeDto) e2).getTerm().getRepresentation_L10n();
33
            if(showIdInVoc){
34
                label1 = CdmUtils.concat(" : ", ((TermNodeDto) e1).getTerm().getIdInVocabulary(), label1);
35
                label2 = CdmUtils.concat(" : ", ((TermNodeDto) e1).getTerm().getIdInVocabulary(), label2);
36
            }
37
            return label1.compareTo(label2);
38
        }
39
        return super.compare(viewer, e1, e2);
40
    }
41
}
(10-10/10)