PDA

View Full Version : Custom Widgets in Table



bparker11
5 May 2008, 7:01 AM
I am using the TableItem to insert custom widgets into a Table. The problem I'm having is that my custom widgets are not receiving any of the events that they need to handle. For example, I have a TextBox with a button next to it to launch the DatePicker. When I click this button inside the Table, nothing happens. The Table catches and handles the event and my widget is never notified. This widget works just fine outside the Table. Is there any way to make it work inside the Table?

I am calling table.disableEvents(false) but that doesn't help.

Thanks,

Brock

mjlecomte
5 May 2008, 8:42 AM
Providing code illustrating the situation is usually a good way to get help.

bparker11
5 May 2008, 9:49 AM
Here's what I'm trying to do.

public class CustomWidgetTable implements EntryPoint, KeyboardListener
{
private Table<RowSelectionModel> table;

public void onModuleLoad()
{
List<TableColumn> columns = new ArrayList<TableColumn>();

int columnWidth = 150;
TableColumn column = new TableColumn("Fields", columnWidth);
column.setMinWidth(20);
column.setMaxWidth(500);
columns.add(column);

TableColumnModel<TableColumn> cm = new TableColumnModel<TableColumn>(columns);
this.table = new Table<RowSelectionModel>(cm);
this.table.setSize(200, 200);

// Add 3 rows to the table
for (int i = 0; i < 3; i++)
{
TableItem tableItem = new TableItem(new Object[1]);
TextBox textBox = new TextBox();
textBox.addKeyboardListener(this);
tableItem.setWidget(0, textBox);

this.table.add(tableItem);
}

Viewport viewport = new Viewport();
viewport.add(this.table);
RootPanel.get().add(viewport);
}

public void onKeyDown(Widget sender, char keyCode, int modifiers)
{
MessageBox.alert("KeyboardListener - onKeyDown", "It worked", new Listener<BaseEvent>()
{
public void handleEvent(BaseEvent be)
{
}
});
}

public void onKeyPress(Widget sender, char keyCode, int modifiers)
{
MessageBox.alert("KeyboardListener - onKeyPress", "It worked", new Listener<BaseEvent>()
{
public void handleEvent(BaseEvent be)
{
}
});
}

public void onKeyUp(Widget sender, char keyCode, int modifiers)
{
MessageBox.alert("KeyboardListener - onKeyUp", "It worked", new Listener<BaseEvent>()
{
public void handleEvent(BaseEvent be)
{
}
});
}

}


Thanks,

Brock

andrey
9 May 2008, 11:40 AM
I can also confirm that this is a problem. I tried creating a Table from TableItems (without the viewer) and then setting the widget to a CheckBox (both GWT's and Ext GWT's). The widget renders in the table fine and you can check/uncheck the widget, but the listener is not being called:


TableItem item = new TableItem(new Object[1]);
CheckBox cb = new CheckBox();
cb.addListener(Events.Change, new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent be) {
// Never called - even though CheckBox can be checked/unchecked
}
});
item.setWidget(0, cb);
table.add(item);


Thanks,
Andre

bparker11
9 May 2008, 11:53 AM
I was able to get around the problem by changing the workflow. The key thing that I had to do was add the widgets to the table after the table had been added to its parent. In reference to my code above, I created a new method called populateTable. Inside that method, I create the TableItems and add them to the table. I call this method after RootPanel.get().add(viewport).

I also wrapped this call in a DeferredCommand to make sure it happened after all the rendering takes place. That part may not be necessary.

If this doesn't make sense, let me know and I can post code.

Brock

andrey
11 May 2008, 6:31 PM
I understand what you are saying you did for a work-around, but it doesn't make sense to me that you had to do this work-around. Seems like a bug in Ext GWT to me.