001: package org.swingml.treetablebrowser.ext;
002:
003: import java.util.*;
004:
005: /**
006: * @author dpitt
007: *
008: * To change this generated comment edit the template variable "typecomment":
009: * Window>Preferences>Java>Templates.
010: * To enable and disable the creation of type comments go to
011: * Window>Preferences>Java>Code Generation.
012: */
013: public class TableBrowserContract implements BrowserContract {
014: private ArrayList columnSortOrder = new ArrayList();
015: BitSet columnSortType = new BitSet(3);
016: private List headings = new ArrayList();
017: //default sorted column
018: int sortedColumn = 1;
019: private Object[][] values = null;
020:
021: public TableBrowserContract(Object[][] d) {
022: values = d;
023: //set the default sorted column to asscending for the last
024: //columnSortType.set(1);
025: }
026:
027: public int compareValues(Object a, Object b, int column) {
028: int returnValue = 0;
029: switch (column) {
030: case 0:
031: case 1:
032: case 2:
033: }
034: return returnValue;
035: }
036:
037: /**
038: * @see com.yellow.common.gui.components.BrowserContract#editValue(String, int, String)
039: */
040: public String editValue(String column, int row, String value) {
041: return null;
042: }
043:
044: /**
045: * @see com.yellow.common.gui.components.BrowserContract#filter(String, String)
046: */
047: public void filter(String colname, String value) {
048: }
049:
050: /**
051: * Returns the columnSortOrder.
052: * @return ArrayList
053: */
054: public ArrayList getColumnSortOrder() {
055: return columnSortOrder;
056: }
057:
058: public boolean getColumnSortType() {
059: return columnSortType.get(sortedColumn);
060: }
061:
062: public boolean getColumnSortType(int col) {
063: return columnSortType.get(col);
064: }
065:
066: /**
067: * @see com.yellow.common.gui.components.BrowserContract#getHeadings()
068: */
069: public String[] getHeadings() {
070: String[] result = new String[headings.size()];
071: for (int i = 0; i < headings.size(); i++) {
072: result[i] = (String) headings.get(i);
073: }
074: return result;
075: }
076:
077: public int getSortedColumn() {
078: return sortedColumn;
079: }
080:
081: /**
082: * @see com.yellow.common.gui.components.BrowserContract#getValue(int, int)
083: */
084: public String getValue(int row, int col) {
085: return (String) values[row][col];
086: }
087:
088: /**
089: * Returns the values.
090: * @return Object[][]
091: */
092: public Object[][] getValues() {
093: return values;
094: }
095:
096: /**
097: * @see com.yellow.common.gui.components.BrowserContract#hasMore(int)
098: */
099: public boolean hasMore(int row) {
100: if (values == null) {
101: return false;
102: }
103: return row < values.length;
104: }
105:
106: public boolean hasSameSortTypeAsPrevious(int theSortedColumn,
107: int theSecondSortedColumn) {
108: return (getColumnSortType(theSortedColumn) == getColumnSortType(theSecondSortedColumn));
109: }
110:
111: public boolean isEditable(int row) {
112: return false;
113: }
114:
115: /**
116: * @see com.yellow.common.gui.components.BrowserContract#isEditable(String)
117: */
118: public boolean isEditable(String heading) {
119: return false;
120: }
121:
122: //we do have to worry about case 0 here because we can sort on the leaf names and the sort order is entirely maintained in the contract
123: public Integer matchColumn(int column) {
124: return new Integer(column);
125: /* switch (column) {
126: case 0 :
127: return new Integer(PREFIX);
128: case 1 :
129: return new Integer(NUMBER);
130: case 2 :
131: return new Integer(STATUS);
132: case 3 :
133: return new Integer(LENGTH);
134:
135:
136: } */
137: // return null;
138: }
139:
140: public void removeColumnFromSortOrder(int column) {
141: columnSortOrder.remove(matchColumn(column));
142: }
143:
144: /**
145: * Sets the columnSortOrder.
146: * @param columnSortOrder The columnSortOrder to set
147: */
148: public void setColumnSortOrder(ArrayList columnSortOrder) {
149: this .columnSortOrder = columnSortOrder;
150: }
151:
152: public void setColumnToPrimarySearch(int column) {
153: Integer columnConstant = matchColumn(column);
154: if (columnSortOrder.contains(columnConstant)) {
155: columnSortOrder.remove(columnConstant);
156: }
157: columnSortOrder.add(columnConstant);
158: }
159:
160: /**
161: * Sets the headings.
162: * @param headings The headings to set
163: */
164: public void setHeadings(List headings) {
165: this .headings = headings;
166: }
167:
168: public void setSortedColumn(int theNewSortedColumn) {
169: sortedColumn = theNewSortedColumn;
170: }
171:
172: /**
173: * Sets the values.
174: * @param values The values to set
175: */
176: public void setValues(Object[][] values) {
177: this .values = values;
178: }
179:
180: public void switchColumnSortType(int column) {
181: if (columnSortType.get(column)) {
182: columnSortType.clear(column);
183: } else {
184: columnSortType.set(column);
185: }
186: }
187: }
|