PDA

View Full Version : big problems with Grid Listener and KeyDown



aminef
15 Dec 2010, 7:58 AM
BasicallyI have a listener on my grid that allows a delete (on pressing "del" key) and an add (using the "+" key) both of them work great!
I wanted to add to the listener that if the key pressed is a letter, then show a dialog. and the problems start...

1) when the last feature is added, I can't navigate with the arrows on my grid, and can't use the "del" and the "+" keys
2) when I press a key to show the dialog, the be.getValue() (witch is supposed to be the letter typed, is always empty string)
3) and finally when I try to use the startsWith() method, it doesn't work...

Here is my code in order:

the grid listener:

grid.addListener(Events.OnKeyDown, new Listener<GridEvent<PersInfo>>() {
@Override
public void handleEvent(GridEvent<PersInfo> be) {
PersInfo rowData = grid.getSelectionModel().getSelectedItem();
if(be.getKeyCode() == KeyCodes.KEY_DELETE && !rowData.isRemoved()){
//delete
}
if(be.getKeyCode() == 107 && rowData.isRemoved()){// press the + key
//add
}
if(be.getKeyCode() >= 49 || be.getKeyCode() <= 90){
showStartWithDialog(grid.getStore(), (String)be.getValue());
}
}
});

and the other isse is :

listStore.getAt(i).getLName().toLowerCase().startsWith(startWithlname)); returns always FALSE
and i have a Info.Display for the 2 Strings and the getLName is "Adair" and startWithlname is "ad" or "ada" or "a" or even "adair"

sven
15 Dec 2010, 8:02 AM
1) What last feature are you refering to?

2) be.getValue() does not return you the char that was pressed.

3) I dont know without a testcase.

But for all of your problems, can you please post a fulyl working testcase implementing EntryPoint that demonstrates your problems? Also with version of GWT are you using?

aminef
15 Dec 2010, 8:18 AM
I can't provide a real testing case (quiet big project), but i think this code demonstrate the problem with the screen shot
GXT: 2.2.0

1) the feature is the last if in the handler, once I add this if, the 2 other if and the keyboard navigation on the grid won't work.
2) how to get the value entered from a keycode?
3) here's the exact code:
I am checking if 'lname' starts with 'startString'

int index = listStore.indexOf(grid.getSelectionModel().getSelectedItem());
for(int i = 0; i < listStore.getCount(); i++){
Info.display(startString+" "+lname.toLowerCase(), Boolean.toString(lname.toLowerCase().startsWith(startString)));

if(!startString.equals("") && lname.toLowerCase().startsWith(startString)){
index = i;
}
}
and here's the result of the info.display (http://img704.imageshack.us/f/startswith.jpg/)

sven
15 Dec 2010, 8:20 AM
I can't provide a real testing case (quiet big project),
You can create a new testcase with just the needed parts. You should not use your current project.

1) and 3) we really need a fully working testcase implmenting EntryPoint for this. You really should take the time, probably 10 minutes, to create one.
2) The browser event has a getter to get the chartcode (you should use KeyPress for this and GWT 2.1)