Project

General

Profile

Revision b32cbeab

IDb32cbeab9266e20daa3f8c65ce4aad1729d98554
Parent 3c6ff11f
Child a4fdf878

Added by Katja Luther over 3 years ago

fix #6918: use comparator in rank combobox if sortRankHierarchically is set

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java
42 42

  
43 43
	private Comparator<T> termComparator;
44 44

  
45
	public Comparator<T> getTermComparator() {
46
		return termComparator;
47
	}
48

  
49
	public void setTermComparator(Comparator<T> termComparator) {
50
		this.termComparator = termComparator;
51
		List<T> termsWithoutNull = terms.subList(1, terms.size());
52
		
53
		populateTerms(termsWithoutNull);
54
		
55
	}
56

  
45 57
	private final TermType termType;
46 58
	private final TermVocabulary termVocabulary;
47 59
	private final Class<T> termClass;
......
53 65

  
54 66
	public TermComboElement(CdmFormFactory formFactory,
55 67
			ICdmFormElement parentElement, TermType termType, String labelString, T selection, boolean addEmptyElement,
56
			int style, boolean useAbbrevLabel) {
57
		this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
68
			int style, boolean useAbbrevLabel, Comparator<T> comparator) {
69
		this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
58 70
	}
59 71

  
60 72
	public TermComboElement(CdmFormFactory formFactory,
61 73
	        ICdmFormElement parentElement, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
62
	        int style, boolean useAbbrevLabel) {
63
	    this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel);
74
	        int style, boolean useAbbrevLabel, Comparator<T> comparator) {
75
	    this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
64 76
	}
65 77

  
66 78
    public TermComboElement(CdmFormFactory formFactory,
67 79
            ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
68 80
            int style) {
69
        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false);
81
        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false, null);
70 82
    }
71 83
    public TermComboElement(CdmFormFactory formFactory,
72 84
            ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
73 85
            int style, boolean useAbbrevLabel) {
74
        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
86
        this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
75 87

  
76 88
    }
77 89

  
78 90
	private TermComboElement(CdmFormFactory formFactory,
79 91
	        ICdmFormElement parentElement, Class<T> termClass, TermType termType, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
80
	        int style, boolean useAbbrevLabel) {
92
	        int style, boolean useAbbrevLabel, Comparator<T> comparator) {
81 93
        super(formFactory, parentElement);
82 94

  
83 95
        this.termType = termType;
......
85 97
        this.termClass = termClass;
86 98
        this.addEmptyElement = addEmptyElement;
87 99
        this.useAbbrevLabel = useAbbrevLabel;
100
        this.termComparator = comparator;
88 101
        if (labelString != null) {
89 102
            label.setText(labelString);
90 103
        }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
52 52
import eu.etaxonomy.cdm.model.agent.Person;
53 53
import eu.etaxonomy.cdm.model.agent.Team;
54 54
import eu.etaxonomy.cdm.model.common.Annotation;
55
import eu.etaxonomy.cdm.model.common.AnnotationType;
55 56
import eu.etaxonomy.cdm.model.common.CdmBase;
56 57
import eu.etaxonomy.cdm.model.common.Credit;
57 58
import eu.etaxonomy.cdm.model.common.DefinedTerm;
......
919 920
            ICdmFormElement parentElement,
920 921
            String labelString,
921 922
            T selection,
922
            int style) {
923
        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false);
923
            int style, 
924
            Comparator<T> comparator) {
925
        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false, comparator);
924 926
    }
925 927

  
926 928
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
......
930 932
			T selection,
931 933
			boolean addEmptyElement,
932 934
			int style) {
933
        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, false);
935
        return this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, false, null);
936
	}
937
    
938
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
939
			TermType termType,
940
			ICdmFormElement parentElement,
941
			String labelString,
942
			T selection, 
943
			int style) {
944
		return  this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false, null);
934 945
	}
935 946
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
936 947
			TermType termType,
......
940 951
			boolean addEmptyElement,
941 952
			int style,
942 953
			boolean useAbbrevLabel) {
943
		return createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel);
954
		return createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
944 955
	}
945 956

  
946 957

  
......
950 961
            String labelString,
951 962
            T selection,
952 963
            int style) {
953
        return this.createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, true, style, false);
964
        return this.createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, true, style, false, null);
954 965
    }
955 966

  
956 967
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
......
961 972
	        boolean addEmptyElement,
962 973
	        int style,
963 974
	        boolean useAbbrevLabel) {
964
	    return createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel);
975
	    return createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
965 976
	}
966 977

  
967 978
	private <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
......
972 983
	        T selection,
973 984
	        boolean addEmptyElement,
974 985
	        int style,
975
	        boolean useAbbrevLabel) {
986
	        boolean useAbbrevLabel,
987
	        Comparator<T> comparator) {
976 988
	    if(termType!=null){
977
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel);
989
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
990
	        if (comparator!= null){
991
	        	element.setTermComparator(comparator);
992
	        }
978 993
	        adapt(element);
979 994
	        parentElement.addElement(element);
980 995
	        return element;
981 996
	    }
982 997
	    else if(termVocabulary!=null){
983
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel);
998
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
999
	        if (comparator!= null){
1000
	        	element.setTermComparator(comparator);
1001
	        }
984 1002
	        adapt(element);
985 1003
	        parentElement.addElement(element);
986 1004
	        return element;
......
3005 3023
        return section;
3006 3024
    }
3007 3025

  
3026

  
3027

  
3008 3028
//	public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
3009 3029
//		 RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
3010 3030
//				 initialText, textHeight, style);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameDetailElement.java
11 11

  
12 12
import java.util.Arrays;
13 13
import java.util.Collection;
14
import java.util.Comparator;
14 15

  
15 16
import org.apache.log4j.Logger;
16 17
import org.eclipse.swt.SWT;
......
77 78
	/** {@inheritDoc} */
78 79
	@Override
79 80
	protected void createControls(ICdmFormElement formElement, INonViralName nonViralName, int style) {
81
		Comparator<Rank> comparator = null;
82
		if(PreferencesUtil.getSortRanksHierarchichally()){
83
			comparator = new Comparator<Rank>(){
80 84

  
85
			@Override
86
			public int compare(Rank o1, Rank o2) {
87
				return o2.compareTo(o1);
88
			}
89

  
90
		};
91
		}
81 92
	    if (isAdvancedView){
82 93
	    	toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
83
	    	combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
94
	    	
95
	    	combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style, comparator);
84 96
	    	createGenusOrUninomialControls(this, nonViralName, style);
85 97
            createInfragenerericEpithetControls(this, nonViralName, style);
86 98
            createSpecificEpithetControls(this, nonViralName, style);
......
93 105
        	}
94 106

  
95 107
    	    if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK)){
96
    	        combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
108
    	        combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style, comparator);
97 109
    	    }
98 110

  
99 111
    		if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS)){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)