View Javadoc

1   // %1126721046088:hoplugins.commons.ui.sorter%
2   /*
3    * Created on 7-apr-2005
4    *
5    * To change the template for this generated file go to
6    * Window>Preferences>Java>Code Generation>Code and Comments
7    */
8   package hoplugins.commons.ui.sorter;
9   
10  import java.util.Iterator;
11  
12  // Helper classes
13  class Row implements Comparable {
14      /*** TODO Missing Parameter Documentation */
15      private final AbstractTableSorter sorter;
16      private int modelIndex;
17  
18      /***
19       * Creates a new Row object.
20       *
21       * @param sorter
22       * @param index
23       */
24      public Row(AbstractTableSorter sorter, int index) {
25          this.modelIndex = index;
26          this.sorter = sorter;
27      }
28  
29      /***
30       * DOCUMENT ME!
31       *
32       * @return
33       */
34      public int getModelIndex() {
35          return modelIndex;
36      }
37  
38      /***
39       * DOCUMENT ME!
40       *
41       * @param o
42       *
43       * @return
44       */
45      public int compareTo(Object o) {
46          int row1 = modelIndex;
47          int row2 = ((Row) o).modelIndex;
48  
49          if (this.sorter.hasHeaderLine()) {
50              if (row1 == 0) {
51                  return -1;
52              }
53  
54              if (row2 == 0) {
55                  return 1;
56              }
57          }
58  
59          for (Iterator it = this.sorter.getSortingColumns().iterator();
60              it.hasNext();) {
61              Directive directive = (Directive) it.next();
62              int column = directive.getColumn();
63              Object o1 = this.sorter.tableModel.getValueAt(row1, column);
64              Object o2 = this.sorter.tableModel.getValueAt(row2, column);
65  
66              int comparison = 0;
67  
68              // Define null less than everything, except null.
69              if ((o1 == null) && (o2 == null)) {
70                  comparison = 0;
71              }
72              else if (o1 == null) {
73                  comparison = -1;
74              }
75              else if (o2 == null) {
76                  comparison = 1;
77              }
78              else {
79                  comparison = this.sorter.getComparator(column).compare(o1, o2);
80              }
81  
82              if (comparison != 0) {
83                  return (directive.getDirection() == AbstractTableSorter.DESCENDING)
84                  ? (-comparison) : comparison;
85              }
86          }
87  
88          return 0;
89      }
90  }