891fadfb164faa412967542684cdef5474010146
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / debug / CdmEntityInfoSorter.java
1 /**
2 * Copyright (C) 2018 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.cdm.vaadin.debug;
10
11 import com.vaadin.data.Container.Sortable;
12 import com.vaadin.data.util.ItemSorter;
13
14 import eu.etaxonomy.cdm.cache.EntityCacherDebugResult.CdmEntityInfo;
15
16 /**
17 * @author a.kohlbecker
18 * @since Jan 23, 2018
19 *
20 */
21 public class CdmEntityInfoSorter implements ItemSorter {
22
23 private static final long serialVersionUID = 1008554008146041297L;
24
25 Object[] propertyId;
26 boolean[] ascending;
27
28 /**
29 * {@inheritDoc}
30 */
31 @Override
32 public void setSortProperties(Sortable container, Object[] propertyId, boolean[] ascending) {
33 this.propertyId = propertyId;
34 this.ascending = ascending;
35
36 }
37
38 /**
39 * {@inheritDoc}
40 */
41 @Override
42 public int compare(Object itemId1, Object itemId2) {
43 if(! (itemId1 instanceof CdmEntityInfo && itemId2 instanceof CdmEntityInfo) ){
44 throw new RuntimeException("Objects must be CdmEntityInfo");
45 }
46 CdmEntityInfo infoItem1 = (CdmEntityInfo)itemId1;
47 CdmEntityInfo infoItem2 = (CdmEntityInfo)itemId2;
48
49 return infoItem1.getField().getName().compareToIgnoreCase(infoItem2.getField().getName());
50
51 }
52
53 }