2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.view
.datasource
;
12 import org
.eclipse
.jface
.viewers
.Viewer
;
13 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
15 import eu
.etaxonomy
.cdm
.config
.ICdmSource
;
16 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
17 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
21 * @created Dec 8, 2010
23 public class CdmDataSourceViewerComparator
extends ViewerComparator
{
25 private int propertyIndex
;
26 private static final int DESCENDING
= 1;
27 private int direction
= DESCENDING
;
29 public CdmDataSourceViewerComparator() {
30 this.propertyIndex
= 1;
31 direction
= DESCENDING
;
34 public void setColumn(int column
) {
35 if (column
== this.propertyIndex
) {
36 // Same column as last sort; toggle the direction
37 direction
= 1 - direction
;
39 // New column; do an ascending sort
40 this.propertyIndex
= column
;
41 direction
= DESCENDING
;
46 public int compare(Viewer viewer
, Object e1
, Object e2
) {
47 CdmMetaDataAwareDataSourceContainer d1
= (CdmMetaDataAwareDataSourceContainer
) e1
;
48 CdmMetaDataAwareDataSourceContainer d2
= (CdmMetaDataAwareDataSourceContainer
) e2
;
50 ICdmSource cs1
= d1
.getCdmSource();
51 ICdmSource cs2
= d2
.getCdmSource();
55 switch (propertyIndex
) {
57 result
= d1
.getMetaData(MetaDataPropertyName
.DB_CREATE_NOTE
).compareTo(d2
.getMetaData(MetaDataPropertyName
.DB_CREATE_NOTE
));
61 boolean c1
= d1
.isDataSourceCompatible();
62 boolean c2
= d2
.isDataSourceCompatible();
65 }else if (c1
== true){
72 result
= d1
.getMetaData(MetaDataPropertyName
.DB_SCHEMA_VERSION
).compareTo(d2
.getMetaData(MetaDataPropertyName
.DB_SCHEMA_VERSION
));
75 result
= d1
.getMetaData(MetaDataPropertyName
.DB_CREATE_DATE
).compareTo(d2
.getMetaData(MetaDataPropertyName
.DB_CREATE_DATE
));
78 if(cs1
instanceof ICdmDataSource
&& cs2
instanceof ICdmDataSource
) {
79 result
= ((ICdmDataSource
)cs1
).getDatabase().compareTo(((ICdmDataSource
)cs2
).getDatabase());
84 if(cs1
instanceof ICdmDataSource
&& cs2
instanceof ICdmDataSource
) {
85 result
= ((ICdmDataSource
)cs1
).getDatabaseType().getName().compareTo(((ICdmDataSource
)cs2
).getDatabaseType().getName());
90 boolean r1
= d1
.isRunning();
91 boolean r2
= d2
.isRunning();
94 }else if (r1
== true){
101 String server1
= d1
.getCdmSource().getServer();
102 String server2
= d2
.getCdmSource().getServer();
103 // h2 databases do not have server entries
104 server1
= server1
== null?
"local" : server1
;
105 server2
= server2
== null?
"local" : server2
;
106 result
= server1
.compareTo(server2
);
109 result
= d1
.getCdmSource().getName().compareTo(d2
.getCdmSource().getName());
112 // If descending order, flip the direction
113 if (direction
== DESCENDING
) {