01: package org.drools.brms.client.table;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: /** This is used to hold the data for sorting in a grid */
23: public class RowData implements Comparable {
24:
25: List columnValues = new ArrayList();
26: int sortColIndex = 0;
27:
28: public void addColumnValue(Comparable value) {
29: this .columnValues.add(value);
30: }
31:
32: public void addColumnValue(int index, Comparable value) {
33: if (index >= this .columnValues.size()) {
34: addNullColumns(index);
35: }
36: this .columnValues.set(index, value);
37: }
38:
39: public Object getColumnValue(int index) {
40: return this .columnValues.get(index);
41: }
42:
43: public List getColumnValues() {
44: return columnValues;
45: }
46:
47: public void setColumnValues(List columnValues) {
48: this .columnValues = columnValues;
49: }
50:
51: public int getSortColIndex() {
52: return sortColIndex;
53: }
54:
55: public void setSortColIndex(int sortColIndex) {
56: this .sortColIndex = sortColIndex;
57: }
58:
59: public int compareTo(Object other) {
60: if (null == other) {
61: return -1;
62: }
63: RowData otherRow = (RowData) other;
64: Comparable obj1 = (Comparable) this
65: .getColumnValue(this .sortColIndex);
66: Comparable obj2 = (Comparable) otherRow
67: .getColumnValue(this .sortColIndex);
68: return obj1.compareTo(obj2);
69: }
70:
71: private void addNullColumns(int index) {
72: for (int nullIndex = this.columnValues.size(); nullIndex <= index; nullIndex++) {
73: columnValues.add(null);
74: }
75: }
76: }
|