3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.view
.datasource
;
13 import org
.eclipse
.jface
.viewers
.Viewer
;
14 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
16 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
21 * @created Dec 8, 2010
24 public class CdmDataSourceViewerComparator
extends ViewerComparator
{
26 private int propertyIndex
;
27 private static final int DESCENDING
= 1;
28 private int direction
= DESCENDING
;
30 public CdmDataSourceViewerComparator() {
31 this.propertyIndex
= 1;
32 direction
= DESCENDING
;
35 public void setColumn(int column
) {
36 if (column
== this.propertyIndex
) {
37 // Same column as last sort; toggle the direction
38 direction
= 1 - direction
;
40 // New column; do an ascending sort
41 this.propertyIndex
= column
;
42 direction
= DESCENDING
;
47 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
50 public int compare(Viewer viewer
, Object e1
, Object e2
) {
51 CdmMetaDataAwareDataSourceContainer d1
= (CdmMetaDataAwareDataSourceContainer
) e1
;
52 CdmMetaDataAwareDataSourceContainer d2
= (CdmMetaDataAwareDataSourceContainer
) e2
;
56 switch (propertyIndex
) {
58 result
= d1
.getMetaData(MetaDataPropertyName
.DB_CREATE_NOTE
).compareTo(d2
.getMetaData(MetaDataPropertyName
.DB_CREATE_NOTE
));
64 result
= d1
.getMetaData(MetaDataPropertyName
.DB_SCHEMA_VERSION
).compareTo(d2
.getMetaData(MetaDataPropertyName
.DB_SCHEMA_VERSION
));
67 result
= d1
.getMetaData(MetaDataPropertyName
.DB_CREATE_DATE
).compareTo(d2
.getMetaData(MetaDataPropertyName
.DB_CREATE_DATE
));
73 NomenclaturalCode code1
= d1
.getDataSource().getNomenclaturalCode();
74 NomenclaturalCode code2
= d2
.getDataSource().getNomenclaturalCode();
75 if (code1
!= null && code2
!= null) {
76 result
= code1
.compareTo(code2
);
80 result
= d1
.getDataSource().getDatabase().compareTo(d2
.getDataSource().getDatabase());
83 result
= d1
.getDataSource().getDatabaseType().getName().compareTo(d2
.getDataSource().getDatabaseType().getName());
86 String server1
= d1
.getDataSource().getServer();
87 String server2
= d2
.getDataSource().getServer();
88 if(server1
!= null && server2
!= null){
89 result
= server1
.compareTo(server2
);
91 // h2 databases do not have server entries
94 result
= d1
.getDataSource().getName().compareTo(d2
.getDataSource().getName());
97 // If descending order, flip the direction
98 if (direction
== DESCENDING
) {