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
.config
.ICdmSource
;
17 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
18 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
22 * @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 public int compare(Viewer viewer
, Object e1
, Object e2
) {
48 CdmMetaDataAwareDataSourceContainer d1
= (CdmMetaDataAwareDataSourceContainer
) e1
;
49 CdmMetaDataAwareDataSourceContainer d2
= (CdmMetaDataAwareDataSourceContainer
) e2
;
51 ICdmSource cs1
= d1
.getCdmSource();
52 ICdmSource cs2
= d2
.getCdmSource();
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 if(cs1
instanceof ICdmDataSource
&& cs2
instanceof ICdmDataSource
) {
74 result
= ((ICdmDataSource
)cs1
).getDatabase().compareTo(((ICdmDataSource
)cs2
).getDatabase());
79 if(cs1
instanceof ICdmDataSource
&& cs2
instanceof ICdmDataSource
) {
80 result
= ((ICdmDataSource
)cs1
).getDatabaseType().getName().compareTo(((ICdmDataSource
)cs2
).getDatabaseType().getName());
84 String server1
= d1
.getCdmSource().getServer();
85 String server2
= d2
.getCdmSource().getServer();
86 if(server1
!= null && server2
!= null){
87 result
= server1
.compareTo(server2
);
89 // h2 databases do not have server entries
92 result
= d1
.getCdmSource().getName().compareTo(d2
.getCdmSource().getName());
95 // If descending order, flip the direction
96 if (direction
== DESCENDING
) {