PDA

View Full Version : Widgets in a TableViewer like in 0.5.2


kcaseye
05-02-2008, 03:53 PM
I posted this in the old mygwt forum a few weeks ago. I think it got lost back there, so I'm reposting it here.

I believe it would be pretty simple to add Widget support in a TableViewer like there is in 0.5.2 with a few code changes. I'll paste them below. (I'm basically taking code from 0.5.2 and porting it over to 1.0.)

Let me know if this is more complicated than I think it is.

In TableViewer.java:


protected void renderItem(Object element, int index) {
int cols = table.getColumnCount();
Object[] values = new Object[cols];
String[] toolTips = new String[cols];

for (int j = 0; j < cols; j++) {
CellLabelProvider lp = getCellLabelProvider(j);
viewerCell.reset(element, null, j, table.getColumn(j).getId());
lp.update(viewerCell);
Widget widget = viewerCell.getWidget();
if (widget != null) {
values[j] = widget;
} else {
values[j] = viewerCell.getText();
}
toolTips[j] = viewerCell.getToolTipText();
}
TableItem item = new TableItem(values);

item.setData(element);
item.setCellToolTips(toolTips);

table.insert((T)item, index);
update(element);
}
and
private void updateInternal(TableItem item) {
Object elem = getElementFromItem(item);
int cols = table.getColumnCount();;
for (int j = 0; j < cols; j++) {
viewerCell.reset(elem, item, j, table.getColumn(j).getId());
CellLabelProvider lp = getCellLabelProvider(j);
lp.update(viewerCell);
Widget widget = viewerCell.getWidget();
if (widget != null) {
item.setValue(j, widget);
} else {
String text = viewerCell.getText();
item.setValue(j, text);
}
item.setCellToolTip(j, viewerCell.getToolTipText());

String style = viewerCell.getTextStyle();
if (style != null) {
item.setCellStyle(j, style);
}
}
}
In ViewerCell.java:
private Widget widget;
...
/**
* Returns the cell's widget, or null if none has been specified.
*
* @return the cell's widget
*/
public Widget getWidget() {
return widget;
}
...
/**
* Sets the cell's content as a widget (optional). If specified, the cell's text will be
* ignored.
*
* @param widget the widget
*/
public void setWidget(Widget widget) {
this.widget = widget;
}
...
void reset(E element, Component item, int columnIndex, String columnId) {
this.element = element;
this.columnIndex = columnIndex;
this.columnId = columnId;
this.item = item;
text = null;
widget = null;
textStyle = null;
toolTipText = null;
}

kcaseye
05-05-2008, 11:41 AM
Are you planning on putting this code in? What's the status here?

goodwrench
05-07-2008, 12:37 PM
Bumping this up. I'd love to see the widget support in the TableViewer. Is there a reason why it was dropped?

andrey
05-07-2008, 09:46 PM
I had made use of the ViewerCell.setWidget() capability in MyGWT 5.2. Now I'm going through the port to see how viable it is to use ext-gwt and I'm disappointed to see that that are regressions such as this in the feature set. And yes, I will buy a commercial license assuming I get commercial quality software and support, but it's somewhat of a chicken-and-egg problem. Can someone from ext-js please respond to the status of this? Do I need to buy the support to find out?