You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Edvin Syse <ed...@sysedata.no> on 2008/10/30 09:27:44 UTC

Double-click to select row -> inmethod grid

Hi,

I subclassed the AbstractGrid class to enable double-click to select a 
row instead of single-click, since it is handy to be able to click in a 
row to copy text etc, and then use double-click to select instead. 
Wouldn't this be a nice addition to the AbstractGrid class? Here is my 
quick/dirty implementation:

public class MyDataGrid extends DefaultDataGrid {
    /* Constructors */
    public MyDataGrid(String id, IModel model, List<IGridColumn> columns) {
        super(id, model, columns);
    }

    public MyDataGrid(String id, IDataSource dataSource, 
List<IGridColumn> columns) {
        super(id, dataSource, columns);
    }

    /* We want double-click to trigger ajax-call, not the default 
single-click */
    protected boolean disableRowClickNotifications() {
        return true;
    }

    /* Add ajax-behavior for double-click */
    protected void onRowPopulated(final WebMarkupContainer rowComponent) {
        super.onRowPopulated(rowComponent);

        rowComponent.add(new AjaxFormSubmitBehavior(getForm(), 
"ondblclick") {
            private static final long serialVersionUID = 1L;
           
            protected void onSubmit(AjaxRequestTarget target) {
            }

            protected void onError(AjaxRequestTarget target) {
            }

            protected void onEvent(AjaxRequestTarget target) {
                onRowDblClicked(target, rowComponent.getModel());
            }

            public CharSequence getCallbackUrl() {
                return super.getCallbackUrl() + "&column='+col+'";
            }

            protected IAjaxCallDecorator getAjaxCallDecorator() {
                return new AjaxCallDecorator() {
                    public CharSequence decorateScript(CharSequence 
script) {
                        return super.decorateScript("if 
(InMethod.XTable.canSelectRow(event)) { "
                                + "var col=(this.imxtClickedColumn || 
''); this.imxtClickedColumn='';" + script
                                + " }");
                    }
                };
            }
        });

    }

    /* Override this to implement the double-click action */
    protected void onRowDblClicked(AjaxRequestTarget target, IModel 
rowModel) {
    }
}

-- 
Med vennlig hilsen

Edvin Syse
Programutvikler

www.sysedata.no / edvin@sysedata.no
Tlf: 333 49700  / Faks: 333 49701
Adresse: Møllegaten 12, 3111 Tønsberg

Syse Data AS -Profesjonelle IT-tjenester 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org