Gwt 指定单元格表中下一个应接收焦点的单元格

Gwt 指定单元格表中下一个应接收焦点的单元格,gwt,Gwt,我正在使用GWT2.1.0 我有一个CellTable,其中填充了使用不同单元格编辑不同类型值(例如日期、字符串等)的列。我希望用户能够在单元格中单击,键入值,然后按enter键直接向下编辑下一个单元格,或按tab键直接向下编辑下一个单元格 我一直在查看Cell和CellTable接口,但找不到任何相关的内容。如何实现这种效果?我也有类似的要求,但我找不到现成的解决方案。我最终将TextInputCell子类化,并自己添加了tabIndex支持 下面是子类的一些部分(希望它能够编译,太懒了,无法

我正在使用GWT2.1.0

我有一个CellTable,其中填充了使用不同单元格编辑不同类型值(例如日期、字符串等)的列。我希望用户能够在单元格中单击,键入值,然后按enter键直接向下编辑下一个单元格,或按tab键直接向下编辑下一个单元格


我一直在查看Cell和CellTable接口,但找不到任何相关的内容。如何实现这种效果?

我也有类似的要求,但我找不到现成的解决方案。我最终将TextInputCell子类化,并自己添加了tabIndex支持

下面是子类的一些部分(希望它能够编译,太懒了,无法检查)。不幸的是,我不能发布整个子类,因为它可能有很多其他与当前问题无关的东西。此解决方案负责切换到下一个单元格,但对于enter支持,您可能需要覆盖onBrowserEvent

public class EditTextInputCell extends TextInputCell
{
    int startTabIndex;

    interface TabbedTemplate extends SafeHtmlTemplates
    {
        @Template( "<input type=\"text\" value=\"{0}\" tabindex=\"{1}\" class=\"{2}\" title=\"{3}\"></input>" )
        SafeHtml input( String value, String tabindex, String styleClass, String title );
    }

    private static TabbedTemplate template;

    public EditTextInputCell( int startTabIndex )
    {
        this.startTabIndex = startTabIndex;
    }

    @Override
    public boolean isEditing( Context context, Element parent, String value )
    {
        return true;
    }

    @Override
    public void render( Context context, String value, SafeHtmlBuilder sb )
    {
        // Get the view data.
        Object key = context.getKey( );
        ValidationData viewData = getViewData( key );
        if ( viewData != null && value.equals( viewData.getCurrentValue( ) ) )
        {
            clearViewData( key );
            viewData = null;
        }

        String strToDisp = ( viewData != null && viewData.getCurrentValue( ) != null ) ? viewData.getCurrentValue( ) : value;
        String tabIndex = "" + startTabIndex + context.getIndex( ) + context.getColumn( );
        boolean invalid = ( viewData == null ) ? false : viewData.isInvalid( );
        String styleClass = "cellTableCell-valid";
        String errorMessage = "";
        if ( invalid )
        {
            styleClass = "cellTableCell-invalid";
            errorMessage = viewData.getMessage( );
        }

        if ( strToDisp != null )
        {
            SafeHtml html = SimpleSafeHtmlRenderer.getInstance( ).render( strToDisp );
            // Note: template will not treat SafeHtml specially
            sb.append( getTemplate( ).input( html.asString( ), tabIndex, styleClass, errorMessage ) );
        }
        else
        {
            sb.appendHtmlConstant( "<input type=\"text\" tabindex=\"" + tabIndex + "\" class=\"" + styleClass + "\" title=\"" + errorMessage + "\"></input>" );
        }
    }   
        private TabbedTemplate getTemplate( )
    {
        if ( template == null )
        {
            template = GWT.create( TabbedTemplate.class );
        }

        return template;
    }}
公共类EditTextInputCell扩展了TextInputCell
{
int startTabIndex;
接口选项卡模板扩展了安全HtmlTemplates
{
@模板(“”)
安全HTML输入(字符串值、字符串选项卡索引、字符串样式类、字符串标题);
}
私有静态选项卡模板;
公共EditTextInputCell(int startTabIndex)
{
this.startTabIndex=startTabIndex;
}
@凌驾
公共布尔isEditing(上下文上下文、元素父级、字符串值)
{
返回true;
}
@凌驾
公共void呈现(上下文上下文、字符串值、安全HtmlBuilder sb)
{
//获取视图数据。
objectkey=context.getKey();
ValidationData viewData=getViewData(键);
if(viewData!=null&&value.equals(viewData.getCurrentValue())
{
clearViewData(键);
viewData=null;
}
字符串strtdisp=(viewData!=null&&viewData.getCurrentValue()!=null)?viewData.getCurrentValue():value;
字符串tabIndex=“”+startTabIndex+context.getIndex()+context.getColumn();
布尔值无效=(viewData==null)?false:viewData.isInvalid();
字符串styleClass=“cellTableCell-valid”;
字符串errorMessage=“”;
如果(无效)
{
styleClass=“cellTableCell无效”;
errorMessage=viewData.getMessage();
}
if(strToDisp!=null)
{
SafeHtml html=SimpleSafeHtmlRenderer.getInstance().render(strToDisp);
//注意:模板不会特别处理SafeHtml
append(getTemplate().input(html.asString(),tabIndex,styleClass,errorMessage));
}
其他的
{
某人以““””号结尾;
}
}   
私有选项卡模板getTemplate()
{
如果(模板==null)
{
template=GWT.create(TabbedTemplate.class);
}
返回模板;
}}