01: package org.dbbrowser.ui.helper;
02:
03: import org.dbbrowser.db.engine.model.ColumnInfo;
04:
05: import java.util.Comparator;
06:
07: /**
08: * Sorts the list of column info by name
09: */
10: public class ColumnInfoComparator implements Comparator {
11: /**
12: * Returns 1 if firstObject(ColumnInfo) is before secondObject(ColumnInfo)
13: * @param firstObject
14: * @param secondObject
15: * @return
16: */
17: public int compare(Object firstObject, Object secondObject) {
18: int valueToReturn = 0;
19: ColumnInfo ci1 = (ColumnInfo) firstObject;
20: ColumnInfo ci2 = (ColumnInfo) secondObject;
21:
22: String columnName1 = ci1.getColumnName();
23: String columnName2 = ci2.getColumnName();
24:
25: //if either of the columns is a primary key, it appears first
26: if (ci1.isPrimaryKeyColumn().booleanValue()) {
27: valueToReturn = -1;
28: } else if (ci2.isPrimaryKeyColumn().booleanValue()) {
29: valueToReturn = 1;
30: } else {
31: valueToReturn = columnName1.compareTo(columnName2);
32: }
33:
34: return valueToReturn;
35:
36: }
37: }
|