number.toString(), "Hyperlink", "img/down.gif"
});
}
// Now configure the table
ColumnLayout layout = new ColumnLayout(columns);
final PagingTable table = new PagingTable(layout, new PagingBar(0, TOTAL_SIZE, 10, new int[] { 5, 10, 20, 50, 100 }));
ContentProvider provider = new ContentProvider() {
// Simulate retrieval of sample data, in requested sort order
public void load(int begin, int end, final int sortId, boolean ascending) {
final int sign = ascending ? 1 : -1;
Row[] tmp = new Row[rows.length];
for(int i = 0; i < rows.length; ++i) tmp[i] = rows[i];
switch(sortId) {
case 1:
Arrays.sort(tmp, new Comparator<Row>() {
public int compare(Row o1, Row o2) {
String v1 = (String)o1.getValue(sortId);
String v2 = (String)o2.getValue(sortId);
return sign * (v1.compareTo(v2));
}
});
break;
case 4:
Arrays.sort(tmp, new Comparator<Row>() {
public int compare(Row o1, Row o2) {
Date v1 = (Date)o1.getValue(sortId);
Date v2 = (Date)o2.getValue(sortId);
return sign * (v1.compareTo(v2));
}
});
break;
case 5:
Arrays.sort(tmp, new Comparator<Row>() {
public int compare(Row o1, Row o2) {
int v1 = ((Integer)o1.getValue(sortId)).intValue();
int v2 = ((Integer)o2.getValue(sortId)).intValue();
return sign * (v1 < v2 ? -1 : (v1 == v2 ? 0 : 1));
}
});
break;
default:
break;
}
Row[] srows = new Row[Math.min(end - begin, tmp.length - begin)];
for(int i = 0; i < srows.length; ++i) srows[i] = tmp[begin + i];
table.onSuccess(new Rows(srows, begin, sortId, ascending));
}
};
table.setContentProvider(provider);
table.addTableListener(new TableListenerAdapter() {
public void onCellClicked(SourcesTableEvents sender, Row row, Column column) {
for(int i = 0; i < columns.length; ++i) columns[i].setState(Column.State.NONE);
column.setState(Column.State.SELECT);
}
public void onRowClicked(SourcesTableEvents sender, Row row) {
GWT.log("Row clicked (id " + row.getId() + ")", null);
for(int i = 0; i < rows.length; ++i) rows[i].setState(Row.State.NONE);
row.setState(Row.State.SELECT);
table.refreshRowState();
}
public void onClick(SourcesTableEvents sender, Row row, Column column, Widget widget) {
GWT.log("Renderer widget clicked", null);
if(widget instanceof CheckBox) {
row.setValue(0, new Boolean(((CheckBox)widget).getValue()));
} else if (widget instanceof Button) {
Window.alert(((Button)widget).getHTML());
} else if (widget instanceof Hyperlink) {
Window.alert(((Hyperlink)widget).getHTML());
} else if (widget instanceof Image) {
Window.alert(((Image)widget).getUrl());
}
}
public void onChange(SourcesTableEvents sender, Row row, Column column, Widget widget) {
GWT.log("Renderer widget changed", null);
if(widget instanceof ListBox) {
ListBox listBox = (ListBox)widget;
row.setValue(6, listBox.getValue(listBox.getSelectedIndex()));
} else if(widget instanceof TextBox) {
row.setValue(8, ((TextBox)widget).getText());
}
}
});
checkAll.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
for(int i = 0; i < rows.length; ++i) rows[i].setValue(0, new Boolean(checkAll.getValue()));
table.update();
}
});
table.update();
return table;
}