views:

21

answers:

2

What is the event type for the control click in a table cell in a GWT application? I want to basically change the color of the background when the user does this action.

This part of my code basically just looks like:

public void onBrowserEvent(Event event) {
        Element td = getEventTargetCell(event);

        if (td == null) return;
        Element tr = DOM.getParent(td);

        System.out.println("Event " + Event.getCurrentEvent());
        switch (DOM.eventGetType(event)) {
        case Event.ONMOUSEDOWN: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            onRowClick(tr);
            break;
        }
        case Event.ONMOUSEUP: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffffff");
            break;
        }
        case Event.ONMOUSEOVER: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            onRowRollover(tr);
            break;
        }
        case Event.ONMOUSEOUT: {
            //DOM.setStyleAttribute(td, "backgroundColor","#ffffff");
            break;
        }
        /*case Event.ONCLICK: {
            DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }*/
        case Event.ONDBLCLICK: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffffff");
            break;
        }
        case Event.KEYEVENTS: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }
        case Event.ONFOCUS: {
            //DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }
        /*case Event. {
            DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
            break;
        }*/
        }

    }

What do I need to do to capture this event?

Thanks

A: 

How about wrapping the contents of the cell in a FocusPanel and adding the appropriate handler (most likely MouseDownHandler)? (tip: create the handler once and add it to all the related cells)
You can also add key handlers, etc. to FocusPanel so you won't need to dabble in native browser events (which could lead to some trouble, browser-specific code, etc.), let GWT do that for you :)

Igor Klimer
+1  A: 

The http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/Event.html object passed into onBrowserEvent has methods. Methods such as boolean getCtrlKey().

case Event.ONCLICK: {
    if (event.getCtrlKey()) {
        DOM.setStyleAttribute(td, "backgroundColor", "#ffce00");
    }
    break;
}

This will work for Windows, not sure about Mac and Linux. On OS X you might check getMetaKey() instead, since Command is normally used where Control is used on Windows.

darkporter