如何在箭头键上关注网格,并希望在按向上箭头或向下箭头时给出列表框的功能

时间:2014-05-13 11:37:08

标签: java gwt grid

我正在制作搜索模块我希望在单击向上箭头键或向下箭头键时关注文本框的键向上处理程序上的网格然后它将焦点放在网格上并按下箭头键向上键盘或箭头键向下工作....并在该行的双击事件中获取特定行的值..

import java.util.ArrayList;
import com.google.gwt.core.client.EntryPoint;  
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;  
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.gwtext.client.core.EventObject;  
import com.gwtext.client.data.*;  
import com.gwtext.client.widgets.Panel;  
import com.gwtext.client.widgets.grid.ColumnConfig;  
import com.gwtext.client.widgets.grid.ColumnModel;  
import com.gwtext.client.widgets.grid.GridPanel;  

public class imagegrid1 implements EntryPoint 
{  
TextBox textbox=new TextBox();
Label l = new Label("search");
Panel panel = new Panel();  
VerticalPanel vp=new VerticalPanel();
Label label=new Label();

GridPanel grid = new GridPanel();  

String name="";
int i=1;

private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

public void onModuleLoad() 
{  
    textbox.addKeyUpHandler(new AlphaKeyPress());
    textbox.setPixelSize(250, 30);

    RootPanel.get().add(l);
    RootPanel.get().add(textbox);
    RootPanel.get().add(vp);
}  
public class AlphaKeyPress implements KeyUpHandler
{
    @Override
    public void onKeyUp(KeyUpEvent event)
    {
        String ab =textbox.getText();

// Window.alert(“”+ ab.length());

        if(ab.length()>0 && !(event.isDownArrow()||event.isUpArrow()))
        {
            greetingService.server(ab,new AsyncCallback<String>()
            {

                    @Override
                    public void onFailure(Throwable caught) 
                    {
                        Window.alert("Invalid");
                    }

                    @Override
                    public void onSuccess(String result) 
                    { 
                        System.out.println("At the client side..."+result);
                        vp.clear();




                        if(result.isEmpty())
                        { 
                            label.setText("not found");
                            vp.add(label);


                        }
                        else
                        {
                            vp.clear();
                            String match=textbox.getText();


                            panel.setPixelSize(260, 90);

// panel.setBorder(false);

                            RecordDef recordDef = new RecordDef
                            (  
                                    new FieldDef[]
                                    {  
                                        new StringFieldDef("company"),  

                                    }  
                            );  

                            Object[][] data = getCompanyData(result); 
                            MemoryProxy proxy = new MemoryProxy(data); 
                            ArrayReader reader = new ArrayReader(recordDef); 
                            Store store = new Store(proxy, reader);  
                            ColumnConfig[] columns = new ColumnConfig[]
                                                                {  

                                                                        new ColumnConfig("", "company", 300, true, null, "company"),  

                                                                };  
                            ColumnModel columnModel = new ColumnModel(columns);

                            System.out.println("datalength="+data.length);



                            System.out.println("GETCOMPANYDATA=+"+getCompanyData(result));



                            System.out.println("proxyyyy="+proxy.toString());




                            if(i==1)
                            {
                                store.load();  
                                grid.setStore(store);  
                                grid.setColumnModel(columnModel);
                                i++;
                            }
                            else
                            {
                                store.load();
                                grid.reconfigure(store, columnModel);
                            }





                            grid.setHeight(90);  
                            grid.setWidth(258);  



                          panel.add(grid); 
                          vp.add(panel);




                        }

                    }
                });
        }

    }
}

private Object[][] getCompanyData(String result) 
{ 
    ArrayList <String> al;
    al=new ArrayList<String>();
    String[] temp = null;

    System.out.println("object data"+result);

    for (String retval: result.split("/"))
    {
        System.out.println(retval);
        al.add(retval);
    }
    int siz=al.size();
    System.out.println(siz);
    temp = new String[siz];
    for (int i = 0; i < siz; i++)
    {
        temp[i] = al.get(i);

    }


    String[][] kk = new String[temp.length][1];
    for(int i=0;i<temp.length;i++)
    {
        kk[i][0]=temp[i];
        System.out.println("temp data"+kk[i][0]);

    }
    return kk;
 }             

}

1 个答案:

答案 0 :(得分:0)

您希望将SuggestBox与自定义SuggestionDisplay一起使用(包含VerticalPanel的{​​{1}},并在GridPanel中显示数据,而不是默认弹出窗口-menu行为)