001: package org.swingml.tablebrowser.ext;
002:
003: import java.util.ArrayList;
004: import java.util.BitSet;
005: import java.util.List;
006:
007: import org.swingml.model.TableDataModel;
008:
009: /**
010: * @author dpitt
011: */
012: public class TableBrowserContract implements BrowserContract {
013:
014: BitSet columnSortType = new BitSet(3);
015: private List headings = new ArrayList();
016: // default sorted column
017: int sortedColumn = 1;
018: private Object[][] values = null;
019:
020: public TableBrowserContract(Object[][] d) {
021: values = d;
022: }
023:
024: public int compareValues(Object a, Object b, int column) {
025: int returnValue = 0;
026: switch (column) {
027: case 0:
028: case 1:
029: case 2:
030: }
031: return returnValue;
032: }
033:
034: public String editValue(String column, int row, Object value) {
035: String result = value.toString();
036: return result;
037: }
038:
039: public void filter(String colname, String value) {
040: }
041:
042: public String[] getHeadings() {
043: String[] result = new String[headings.size()];
044: for (int i = 0; i < headings.size(); i++) {
045: result[i] = (String) headings.get(i);
046: }
047: return result;
048: }
049:
050: public Object getModelAt(int row, int col) {
051: Object result = null;
052: if (values.length >= row) {
053: Object[] cols = values[row];
054: if (cols.length >= col) {
055: result = values[row][col];
056: }
057: }
058: return result;
059: }
060:
061: /**
062: * Try the text field first, if its null, try the value field.
063: */
064: public String getText(int row, int col) {
065: String result = "";
066: TableDataModel tdm = (TableDataModel) values[row][col];
067: if (tdm.getText() != null) {
068: result = tdm.getText();
069: } else {
070: if (tdm.getValue() != null) {
071: result = tdm.getValue().toString();
072: }
073: }
074: return result;
075: }
076:
077: /**
078: * Try the value field first, if its null, try the text field.
079: */
080: public String getValue(int row, int col) {
081: String result = "";
082: TableDataModel tdm = (TableDataModel) values[row][col];
083: if (tdm.getValue() != null) {
084: result = tdm.getValue().toString();
085: } else {
086: if (tdm.getText() != null) {
087: result = tdm.getText();
088: }
089: }
090: return result;
091: }
092:
093: /**
094: * Returns the values.
095: *
096: * @return Object[][]
097: */
098: public Object[][] getValues() {
099: return values;
100: }
101:
102: public boolean hasMore(int row) {
103: if (values == null) {
104: return false;
105: }
106: return row < values.length;
107: }
108:
109: public boolean isEditable(int row, int col) {
110: TableDataModel dm = (TableDataModel) values[row][col];
111: return dm.isEditable();
112: }
113:
114: /**
115: * Sets the headings.
116: *
117: * @param headings
118: * The headings to set
119: */
120: public void setHeadings(List headings) {
121: this .headings = headings;
122: }
123:
124: /**
125: * Sets the values.
126: *
127: * @param values
128: * The values to set
129: */
130: public void setValues(Object[][] values) {
131: this.values = values;
132: }
133: }
|