use of org.vaadin.patrik.events.CellEditEvent in project GridFastNavigation by TatuLund.
the class FastNavigation method setupFastNavigation.
private void setupFastNavigation(final Grid g, boolean changeColumnOnEnter, boolean dispatchEditEventOnBlur) {
getState().changeColumnOnEnter = changeColumnOnEnter;
getState().dispatchEditEventOnBlur = dispatchEditEventOnBlur;
g.setEditorBuffered(false);
g.setEditorEnabled(true);
registerRpc(new FastNavigationServerRPC() {
@Override
public void rowUpdated(int rowIndex) {
Object itemId = getItemIdByRowIndex(g, rowIndex);
rowEditListeners.dispatch(new RowEditEvent(g, rowIndex, itemId));
}
private Object getItemIdByRowIndex(final Grid g, int rowIndex) {
Indexed ds = g.getContainerDataSource();
Object itemId = null;
if (rowIndex >= 0 && (ds.size() > 0))
itemId = ds.getIdByIndex(rowIndex);
return itemId;
}
@Override
public void cellUpdated(int rowIndex, int colIndex, String newData) {
Object itemId = getItemIdByRowIndex(g, rowIndex);
cellEditListeners.dispatch(new CellEditEvent(g, rowIndex, colIndex, newData, itemId));
}
@Override
public void focusUpdated(int rowIndex, int colIndex) {
Object itemId = getItemIdByRowIndex(g, rowIndex);
if (hasRowFocusListener && rowIndex != lastFocusedRow) {
rowFocusListeners.dispatch(new RowFocusEvent(g, rowIndex, itemId));
}
if (hasCellFocusListener && (rowIndex != lastFocusedRow || colIndex != lastFocusedCol)) {
cellFocusListeners.dispatch(new CellFocusEvent(g, rowIndex, colIndex, lastFocusedRow == rowIndex, lastFocusedCol == colIndex, itemId));
}
lastFocusedRow = rowIndex;
lastFocusedCol = colIndex;
}
@Override
public void editorOpened(int rowIndex, int colIndex, int lockId) {
Object itemId = getItemIdByRowIndex(g, rowIndex);
EditorOpenEvent ev = new EditorOpenEvent(g, rowIndex, colIndex, itemId);
editorOpenListeners.dispatch(ev);
// Update disabled columns or readonly fields status if changed dynamically
ArrayList<Integer> disabledColumns = new ArrayList<Integer>();
for (int i = 0; i < g.getColumns().size(); i++) {
if (!g.getColumns().get(i).isEditable()) {
disabledColumns.add(i);
} else if ((g.getColumns().get(i).getEditorField() != null) && g.getColumns().get(i).getEditorField().isReadOnly()) {
disabledColumns.add(i);
}
}
getRPC().setDisabledColumns(disabledColumns);
getRPC().unlockEditor(lockId);
}
@Override
public void ping() {
getLogger().info("Received ping");
}
@Override
public void editorClosed(int rowIndex, int colIndex, boolean wasCancelled) {
editorCloseListeners.dispatch(new EditorCloseEvent(g, rowIndex, colIndex, wasCancelled));
}
@Override
public void clickOut() {
clickOutListeners.dispatch(new ClickOutEvent(g));
}
}, FastNavigationServerRPC.class);
extend(g);
}
Aggregations