vendredi 16 mai 2014

set focous on grid from textBox and how focus on move on arrow up or arrow down key


Vote count:

0




i want to set focus on the grid on click arrow up key or arrow down key of the click event of textbox. and move the focus over the grid rows on clicking arrow up key or arrow down key just like listbox and when click on enter get value of column in textbox having focus??



package com.client;

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.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.HTML;
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.util.Format;
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;
import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;

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();
HTML htm;
GridPanel grid = new GridPanel();


String name="";
int i=1;
int select;

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
{
public void onKeyUp(final KeyUpEvent event)
{
String ab =textbox.getText();
if(ab.length()>0)
{
if(event.isDownArrow()||event.isUpArrow())
{
// set focus on the grid

}
else
{
greetingService.server(ab,new AsyncCallback<ArrayList<String>>()
{
public void onFailure(Throwable caught)
{
Window.alert("Invalid");
}

public void onSuccess(final ArrayList<String> result)
{

vp.clear();

if(result.size()==0)
{
label.setText("not found");
vp.add(label);
}
else
{
vp.clear();

panel.setPixelSize(260, 90);

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);

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

else
{
store.load();
grid.reconfigure(store, columnModel);

}


grid.addGridListener(new GridListenerAdapter()
{

public void onKeyDown(EventObject e)
{
System.out.println("GridListener.onKeyDown");
if(e.getCharCode()==13)
{
textbox.setText(result.get(select));

}

}




});


grid.addGridRowListener(new GridRowListenerAdapter()
{
public void onRowClick(GridPanel grid, int rowIndex, EventObject e)
{
System.out.println(Format.format("GridRowListener.onRowClick::rowIndex({0})",
rowIndex));
htm.setStyleName("");
select=rowIndex;
System.out.println(rowIndex);
// textbox.setText(result.get(rowIndex));
}
});
grid.setHeight(90);
grid.setWidth(258);
panel.add(grid);
vp.add(panel);
}

}


});
}
}
}
}

private Object[][] getCompanyData(ArrayList<String> result)
{
htm=new HTML();
htm.setStyleName("green");
String[][] kk = new String[result.size()][1];
int count=1;
for(int i=0;i<result.size();i++)
{

String match=textbox.getText();

String html = result.get(i).replace(match, "<b><i>" + match + "</i></b>");
if(count==1)
{

htm.setText(html);

kk[i][0]=htm.getText();
count++;
}
else
{

kk[i][0]=html.toString();
}
System.out.println("temp data"+kk[i][0]);

}
return kk;
}
}


asked 5 mins ago






Aucun commentaire:

Enregistrer un commentaire