How can I create a widget add it to a CellTable and perform some action when it's clicked?

609 views
Skip to first unread message

nacho

unread,
Aug 17, 2011, 4:29:52 PM8/17/11
to google-we...@googlegroups.com
I need to put some kind of Button in a CellTable column.

I created a class that extends AbstractCell:

public class AnchorCell extends AbstractCell<Anchor> {
   
    @Override
    public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context,
            Element parent, Anchor value, NativeEvent event,
            ValueUpdater<Anchor> valueUpdater) {
       
        Window.alert("hello");

    }

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, Anchor h, SafeHtmlBuilder sb) {
        sb.append(SafeHtmlUtils.fromTrustedString(h.toString()));
    }

}

And then, when I am working with my CellTable, I create a column in this way:

Column<CompanyModel, Anchor> actionsColumn = new Column<CompanyModel, Anchor>(new AnchorCell()) {

            @Override
            public Anchor getValue(CompanyModel company) {
                Anchor h = new ActionsButton(company.getCompanyId(), "Acciones " + company.getCompanyId());
                return h;
            }
           
        };

But I can't get the browser events.. How can I perform some action when my widget is clicked?

Chris

unread,
Aug 17, 2011, 4:36:04 PM8/17/11
to Google Web Toolkit
Are you sure you don't want to use a ButtonCell? Seems to be way more
convenient ;)

nacho

unread,
Aug 17, 2011, 6:47:39 PM8/17/11
to google-we...@googlegroups.com
Looks i was trying to reinvent the wheel :D

Thanks!

Sudhakar Abraham

unread,
Aug 18, 2011, 8:09:30 AM8/18/11
to Google Web Toolkit
Here is what I did for a similar problem. I added a ClickableTextCell
in the Column Header.

CellTable studentTable = new CellTable<Student>();
Column<Student, String> feesColumn = new FeesColumn();
Header<String> header = new Header<String>(new
ClickableTextCell())
{
@Override
public String getValue() {
return "MyHeader";
}
@Override
public void onBrowserEvent(Context context, Element parent,
NativeEvent event) {
PopuppanelDemo popup = new PopuppanelDemo();
int left = parent.getAbsoluteLeft();
Console.print("left"+left);
int top = parent.getAbsoluteTop();
Console.print("top"+left);
popup.setAnimationEnabled(true);
popup.setAutoHideEnabled(true);
popup.setSize("20ex", "15ex");
TextArea area = new TextArea();
area.setSize("20ex", "15ex");
area.setText("Searchterrain ,
DocAtwill,Datastoregwt,Linebalance,ecutplan");
area.setVisible(true);
popup.add(area);
popup.setPopupPosition(left+20, top+30);
popup.show();
}
};
studentTable.addColumn(feesColumn, header , new
TextHeader("footer"));

private class FeesColumn extends Column<Student, String>
{
public FeesColumn()
{
super(new EditTextCellforNumber());
}
@Override
public String getValue(Student object)
{
// TODO Auto-generated method stub
}
}

S.Abraham
www.DataStoreGwt.com
Reply all
Reply to author
Forward
0 new messages