Custom cell, not responding to mouse clicks

55 views
Skip to first unread message

Jonas

unread,
Sep 24, 2011, 3:57:15 PM9/24/11
to google-we...@googlegroups.com
I have a CellTable with a custom cell that extends AbstractCell and overrides the render method for displaying its data. The problem is that I can't click inside the actual cell to select it, I have to click somewhere outside the cell. The default color change on mouse hover also does not work within the actual cell. I am using a SingleSelectionModel to display a popup when I select something in the cell table. What do I need to do to make my cell respond to clicks and handle the mouse over effect?

Sudhakar Abraham

unread,
Sep 26, 2011, 8:00:29 AM9/26/11
to Google Web Toolkit
Override the getConsumedEvents() in AbstractCell<C>, and specify
event type as "click". You might also set preventDefault(),
stopPropagation() property in NativeEvent.


@Override
public Set getConsumedEvents()
{
printNative(" getConsumedEvents() called ");
return Collections.singleton("click");
}

public void onBrowserEvent(Cell.Context context, Element parent,
Object value, NativeEvent event)
{

event.preventDefault();
event.stopPropagation();
printNative("click NativeEvent " + event);

}

S. Abraham
www.DataStoreGwt.com
Persist objects directly in GAE

Jonas

unread,
Sep 26, 2011, 8:36:43 AM9/26/11
to google-we...@googlegroups.com
Hmm, I can't get it to work. Here's my full code:

public class GroupCell extends AbstractCell<GroupDto>
{
    public GroupCell()
    {
        super("click");
    }

    @Override
    public Set<String> getConsumedEvents()
    {
        return Collections.singleton("click");
    }

    @Override
    public void onBrowserEvent(Context context, Element parent, GroupDto value, NativeEvent event,
            ValueUpdater<GroupDto> valueUpdater)
    {
        if (value == null)
        {
            return;
        }

        event.preventDefault();
        event.stopPropagation();

    }

    @Override
    public void render(Context context, GroupDto group, SafeHtmlBuilder sb)
    {
        ...
    }
}

Am I missing something?

Thomas Broyer

unread,
Sep 26, 2011, 9:19:47 AM9/26/11
to google-we...@googlegroups.com


On Monday, September 26, 2011 2:36:43 PM UTC+2, Jonas wrote:
Hmm, I can't get it to work. Here's my full code:

public class GroupCell extends AbstractCell<GroupDto>
{
    public GroupCell()
    {
        super("click");
    }

    @Override
    public Set<String> getConsumedEvents()
    {
        return Collections.singleton("click");
    }

super("click") is redundant with the getConsumedEvents override.

 


    @Override
    public void onBrowserEvent(Context context, Element parent, GroupDto value, NativeEvent event,
            ValueUpdater<GroupDto> valueUpdater)
    {
        if (value == null)
        {
            return;
        }

        event.preventDefault();
        event.stopPropagation();

    }

    @Override
    public void render(Context context, GroupDto group, SafeHtmlBuilder sb)
    {
        ...
    }
}

Am I missing something?

Doing something on click in onBrowserEvent? How are you testing things? What's the expected behavior?
 

Jonas

unread,
Sep 26, 2011, 10:20:41 AM9/26/11
to google-we...@googlegroups.com
I just want to make it possible to select the cell by clicking somewhere inside it like a normal TextColumn for example. My cell just displays data using a table with an image and some headers but I can't select a row in the cell table by clicking somewhere on the image for example. If I change back to a normal TextColumn it works fine.

Do I need to call my selectionmodel from onBrowserEvent to make the cell selectable?

Thomas Broyer

unread,
Sep 26, 2011, 11:04:12 AM9/26/11
to google-we...@googlegroups.com
The problem is that you use a table in your rendering: http://code.google.com/p/google-web-toolkit/issues/detail?id=6750
Despite the issue status, I believe this is fixed (for 2.5) though: http://code.google.com/p/google-web-toolkit/issues/detail?id=5714
Reply all
Reply to author
Forward
0 new messages