// Prepare the header and data tables
prepareTable(dataTable, "dataTable");
prepareTable(headerTable, "headerTable");
// Create the main div container
Element mainElem = DOM.createDiv();
setElement(mainElem);
setStylePrimaryName(DEFAULT_STYLE_NAME);
DOM.setStyleAttribute(mainElem, "padding", "0px");
DOM.setStyleAttribute(mainElem, "overflow", "hidden");
DOM.setStyleAttribute(mainElem, "position", "relative");
// Create the table wrapper and spacer
headerWrapper = createWrapper("headerWrapper");
headerSpacer = createSpacer(headerWrapper);
dataWrapper = createWrapper("dataWrapper");
// Create image to fill width
fillWidthImage = new Image() {
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if (DOM.eventGetType(event) == Event.ONCLICK) {
fillWidth();
}
}
};
fillWidthImage.setTitle("Shrink/Expand to fill visible area");
images.scrollTableFillWidth().applyTo(fillWidthImage);
Element fillWidthImageElem = fillWidthImage.getElement();
DOM.setStyleAttribute(fillWidthImageElem, "cursor", "pointer");
DOM.setStyleAttribute(fillWidthImageElem, "position", "absolute");
DOM.setStyleAttribute(fillWidthImageElem, "top", "0px");
DOM.setStyleAttribute(fillWidthImageElem, "right", "0px");
DOM.setStyleAttribute(fillWidthImageElem, "zIndex", "1");
add(fillWidthImage, getElement());
// Adopt the header and data tables into the panel
adoptTable(headerTable, headerWrapper, 1);
adoptTable(dataTable, dataWrapper, 2);
// Create the sort indicator Image
sortedColumnWrapper = DOM.createSpan();
DOM.setInnerHTML(sortedColumnWrapper, " ");
DOM.appendChild(sortedColumnWrapper, sortedColumnIndicator.getElement());
// Add some event handling
sinkEvents(Event.ONMOUSEOUT);
DOM.setEventListener(dataWrapper, this);
DOM.sinkEvents(dataWrapper, Event.ONSCROLL);
DOM.setEventListener(headerWrapper, this);
DOM.sinkEvents(headerWrapper, Event.ONMOUSEMOVE | Event.ONMOUSEDOWN
| Event.ONMOUSEUP | Event.ONCLICK | Event.ONDBLCLICK);
// Listen for sorting events in the data table
dataTable.addSortableColumnsListener(new SortableColumnsListener() {
public void onColumnSorted(ColumnSortList sortList) {
// Get the primary column and sort order
int column = -1;
boolean ascending = true;
if (sortList != null) {
column = sortList.getPrimaryColumn();
ascending = sortList.isPrimaryAscending();
}
// Remove the sorted column indicator
if (isColumnSortable(column)) {
Element parent = DOM.getParent(sortedColumnWrapper);
if (parent != null) {
DOM.removeChild(parent, sortedColumnWrapper);
}
// Re-add the sorted column indicator