PDA

View Full Version : Walking EditorGrid Cells



Matt Kleweno
17 Jun 2009, 10:57 AM
Does anyone know how to easily walk the selectable cells of an EditorGrid?

It seems like this should be pretty easy to do. The base library has a function walkCells(). But it is protected and I cannot access it from my objects.

If someone knows how, can you please post a snippet on how this can be done?

What I am trying to do is skip skip over certain cells where the editor would normally stop in the TAB sequence but based on a defined row type (a value defined in the ModelData) I want to skip that cell and proceed on to the next cell in the tab sequence.

sven
17 Jun 2009, 11:00 AM
You can extened EditorGrid and than simple override that method to fit your needs.

Matt Kleweno
17 Jun 2009, 11:06 AM
Any chance you can post a small example? I have tried doing that and must be missing something.

sven
17 Jun 2009, 11:13 AM
MyEditorGridd<M extends ModelData> extends EditorGrid<M>{

protected Cell walkCells(int row, int col, int step, Callback callback, boolean acceptNavs) {
//Your actions here
}

}

Matt Kleweno
17 Jun 2009, 11:20 AM
Thanks.

Where is the class "Cell" defined?

in

protected Cell walkCells(int row...

sven
17 Jun 2009, 12:03 PM
I just commited a patch to SVN for 1.2 that make you able to access the Cell class.

Matt Kleweno
18 Jun 2009, 6:04 AM
Just an update...I was able to solve this by doing 2 things.

1. Adding a listener to the field on each of the editable cell columns and firing the SpecialKey event when the ENTER key is pressed in that field.



_gridKeyListener = new Listener<FieldEvent>() {
public void handleEvent(FieldEvent be) {
// If ENTER key pressed we need to fire the SpecialKey event
// this will allow the enter key to act like a TAB and go to the next field
if(be.getKeyCode() == 13) {
_directGrid.getColumnModel().getEditor(_activeEditorColumn).fireEvent(Events.SpecialKey, be);
}
}
};

2. Overriding the onEditorKey function in the CellSelectionModel to handle the ENTER key like the TAB key.


@Override
protected void onEditorKey(DomEvent e) {
EditorGrid editGrid = (EditorGrid) grid;
int k = e.getKeyCode();

int c = selection.cell;

Cell newCell = null;

CellEditor editor = editGrid.cm.getEditor(c);

//MessageBox.alert("here", "onEditorKey keyCode=" + k, null);

switch (k) {
case KeyboardListener.KEY_ENTER:
case KeyboardListener.KEY_TAB:
e.stopEvent();
editor.completeEdit();
if ((k == KeyboardListener.KEY_ENTER) || k == KeyboardListener.KEY_TAB) {
if (e.isShiftKey()) {
newCell = grid.walkCells(editor.row, editor.col - 1, -1, callback, true);
} else {
newCell = grid.walkCells(editor.row, editor.col + 1, 1, callback, true);
}
}
break;
case KeyboardListener.KEY_ESCAPE:
editor.cancelEdit();
break;
}
if (newCell != null) {
editGrid.startEditing(newCell.row, newCell.cell);
} else {
if (k == KeyboardListener.KEY_ENTER || k == KeyboardListener.KEY_TAB || k == KeyboardListener.KEY_ESCAPE) {
grid.getView().focusCell(editor.row, editor.col, false);
}
}
}