Here's my implementation to handle column resizing.
I created the CellTable class in my SourceTree with same package name
as Google named it.
I extended the onBrowserEvent2 function with my resizing function:
....
// Forward the event to the associated header, footer, or column.
boolean isClick = "click".equals(eventType);
int col = tableCell.getCellIndex();
// Control resizing of columns
boolean resizing = resizeColumns(event, target, col,
tableCell);
if (resizing) {
return;
}
if (section == thead) {
....
The resizing function looks like this. I added a function to calculate
the column width if no with are set. Setting width must be done with
Unit.PX at the moment.
/** The mouse down. */
private boolean mouseDown = false;
/** The resize value. */
private int oldXValue = -1;
/** The column to resize. */
private int columnToResize = -1;
/**
* Resize columns.
*
* @param event
* the event
* @param target
* the target
* @param col
* the col
* @param tableCell
* the table cell
* @return true, if successful
*/
private boolean resizeColumns(Event event, Element target, int
col, TableCellElement tableCell) {
String eventType = event.getType();
int xValue = event.getClientX();
int offsetRight = xValue - (tableCell.getAbsoluteLeft() +
tableCell.getClientWidth());
int offsetLeft = xValue - tableCell.getAbsoluteLeft();
boolean resize = false;
if (offsetRight > -10) {
resize = true;
} else {
resize = false;
}
if (resize || mouseDown) {
DOM.setStyleAttribute((com.google.gwt.user.client.Element)
target, "cursor", "col-resize");
} else {
DOM.setStyleAttribute((com.google.gwt.user.client.Element)
target, "cursor", "auto");
return false;
}
if ("mousedown".equals(eventType)) {
mouseDown = !mouseDown;
if (mouseDown && columnToResize == -1 && oldXValue == -1)
{
columnToResize = col;
oldXValue = xValue;
} else {
calculateActualColumnWidths();
int offset = 0;
offset = xValue - oldXValue;
if (offset != 0 && columnToResize > -1) {
this.setColumnWidth(
columns.get(columnToResize),
Double.valueOf(columnWidths.get(columns.get(columnToResize)).replace(Unit.PX.getType(),
""))
+ offset, Unit.PX);
}
this.redraw();
columnToResize = -1;
oldXValue = -1;
}
}
return true;
}
/**
*
*/
private void calculateActualColumnWidths() {
if (columnWidths.size() == 0) {
GWT.log("Calculate column width");
int width = this.getOffsetWidth() / columns.size();
for (Column<T, ?> col : columns) {
this.setColumnWidth(col, width, Unit.PX);
}
}
}
Resizing is done at the last 10 px of each column. No other actions
are performed in this area.
First click activated resizing, set the column index for resizing and
takes the actual x value.
Second click releases resizing, calculates the offset of saved x value
and actual x value and set the width of saved column index.
Not very nice, but the celltable don't fire mouseup event. Other
solutions are welcome.
Perhaps we could create a nice and performant column resizing
together.
I'd like to show resizing with a small line. Some ideas how to draw a
line at a given position with GWT?
On 9 Apr., 13:02, meyertee <
meyer...@gmail.com> wrote:
> I'll have to implement the same in pure html/js soon, my strategy so far was
> to put some markup in the table header that creates an element on the right
> side of the header to trigger the resize-cursor and the mouse-events.
> I saw the same thing here <
http://bz.var.ru/comp/web/resizable.html> and in