ref #8677: layout and labeling in aggregation config wizard
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / combo / OriginalSourceTypeComparator.java
1 /**
2 * Copyright (C) 2019 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.combo;
10
11 import java.util.Comparator;
12
13 import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
14 import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
15
16 /**
17 * @author pplitzner, k.luther
18 * @since 04.12.2019
19 */
20 /**
21 * Sorts source type combo alphabetically <b>except</b> for PrimaryTaxonomicSource resp.
22 * PrimaryMediaSource which are always on top depending on the IdentifiableSource;
23 * <br>
24 * The last two are always "Other" followed by "Unknown"
25 * @author pplitzner
26 * @date Jan 6, 2017
27 *
28 */
29 public class OriginalSourceTypeComparator implements Comparator<OriginalSourceType>{
30
31 private OriginalSourceBase entity;
32
33 public OriginalSourceTypeComparator(OriginalSourceBase entity) {
34 this.entity = entity;
35 }
36
37 /**
38 * {@inheritDoc}
39 */
40 @Override
41 public int compare(OriginalSourceType o1, OriginalSourceType o2) {
42 if(o1==null){
43 if(o2==null){
44 return 0;
45 }
46 else{
47 return -1;
48 }
49 }
50 if(o2==null){
51 return 1;
52 }
53 //both are either taxonomic or media
54 else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
55 && o2.equals(OriginalSourceType.PrimaryMediaSource)){
56 if(entity != null && entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
57 return 1;
58 }
59 else{
60 return -1;
61 }
62 }
63 else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
64 && o1.equals(OriginalSourceType.PrimaryMediaSource)){
65 if(entity != null && entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
66 return -1;
67 }
68 else{
69 return 1;
70 }
71 }
72 //one is not taxonomic or media
73 else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
74 ||o1.equals(OriginalSourceType.PrimaryMediaSource)){
75 return -1;
76
77 }
78 else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
79 || o2.equals(OriginalSourceType.PrimaryMediaSource)){
80 return 1;
81 }
82 //The last two are always "Other" followed by "Unknown"
83 else if(o1.equals(OriginalSourceType.Other)){
84 if(o2.equals(OriginalSourceType.Unknown)){
85 return -11;
86 }
87 else{
88 return 1;
89 }
90 }
91 if(o2.equals(OriginalSourceType.Other)){
92 return 1;
93 }
94 else{
95 String message1 = o1.getKey();
96 String message2 = o2.getKey();
97 return message1.compareTo(message2);
98 }
99 }
100
101 }