package org.swingml.tablebrowser.ext;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import org.swingml.model.TableDataModel;
/**
* @author dpitt
*/
public class TableBrowserContract implements BrowserContract {
BitSet columnSortType = new BitSet(3);
private List headings = new ArrayList();
// default sorted column
int sortedColumn = 1;
private Object[][] values = null;
public TableBrowserContract(Object[][] d) {
values = d;
}
public int compareValues(Object a, Object b, int column) {
int returnValue = 0;
switch (column) {
case 0:
case 1:
case 2:
}
return returnValue;
}
public String editValue(String column, int row, Object value) {
String result = value.toString();
return result;
}
public void filter(String colname, String value) {
}
public String[] getHeadings() {
String[] result = new String[headings.size()];
for (int i = 0; i < headings.size(); i++) {
result[i] = (String) headings.get(i);
}
return result;
}
public Object getModelAt(int row, int col) {
Object result = null;
if (values.length >= row) {
Object[] cols = values[row];
if (cols.length >= col) {
result = values[row][col];
}
}
return result;
}
/**
* Try the text field first, if its null, try the value field.
*/
public String getText(int row, int col) {
String result = "";
TableDataModel tdm = (TableDataModel) values[row][col];
if (tdm.getText() != null) {
result = tdm.getText();
} else {
if (tdm.getValue() != null) {
result = tdm.getValue().toString();
}
}
return result;
}
/**
* Try the value field first, if its null, try the text field.
*/
public String getValue(int row, int col) {
String result = "";
TableDataModel tdm = (TableDataModel) values[row][col];
if (tdm.getValue() != null) {
result = tdm.getValue().toString();
} else {
if (tdm.getText() != null) {
result = tdm.getText();
}
}
return result;
}
/**
* Returns the values.
*
* @return Object[][]
*/
public Object[][] getValues() {
return values;
}
public boolean hasMore(int row) {
if (values == null) {
return false;
}
return row < values.length;
}
public boolean isEditable(int row, int col) {
TableDataModel dm = (TableDataModel) values[row][col];
return dm.isEditable();
}
/**
* Sets the headings.
*
* @param headings
* The headings to set
*/
public void setHeadings(List headings) {
this.headings = headings;
}
/**
* Sets the values.
*
* @param values
* The values to set
*/
public void setValues(Object[][] values) {
this.values = values;
}
}