use of org.vaadin.patrik.events.EditorCloseEvent in project GridFastNavigation by TatuLund.
the class DemoUI method initNavigation.
private void initNavigation(final Grid grid) {
FastNavigation nav = new FastNavigation(grid, false, true);
nav.setChangeColumnAfterLastRow(true);
nav.addRowEditListener(new RowEditListener() {
@Override
public void onEvent(RowEditEvent event) {
int rowIndex = event.getRowIndex();
if (rowIndex >= 0) {
Indexed ds = grid.getContainerDataSource();
Object itemId = event.getItemId();
printChangedRow(rowIndex, ds, itemId);
}
}
});
// Open with F2
nav.addEditorOpenShortcut(KeyCode.F2);
writeOutput("Editor can also be opened with F2");
// Close with F3
nav.addEditorCloseShortcut(KeyCode.F3);
writeOutput("Editor can also be closed with F3");
// Row focus change
nav.addRowFocusListener(new RowFocusListener() {
@Override
public void onEvent(RowFocusEvent event) {
int row = event.getRow();
writeOutput("Focus moved to row " + event.getRow());
grid.select(event.getItemId());
}
});
writeOutput("Added row focus change listener");
// Cell focus change
nav.addCellFocusListener(new CellFocusListener() {
@Override
public void onEvent(CellFocusEvent event) {
int row = event.getRow();
int col = event.getColumn();
writeOutput("Focus moved to cell [" + row + ", " + col + " ]");
}
});
writeOutput("Added cell focus change listener");
// Listening to opening of editor
nav.addEditorOpenListener(new EditorOpenListener() {
@Override
public void onEvent(EditorOpenEvent event) {
int row = event.getRow();
writeOutput("Editor opened on row " + row + " at column " + event.getColumn());
}
});
writeOutput("Added editor open listener");
// Listening to closing of editor
nav.addEditorCloseListener(new EditorCloseListener() {
@Override
public void onEvent(EditorCloseEvent event) {
writeOutput("Editor closed on row " + event.getRow() + ", column " + event.getColumn() + ", " + (event.wasCancelled() ? "user cancelled change" : "user saved change"));
}
});
writeOutput("Added editor close listener");
nav.addClickOutListener(new ClickOutListener() {
@Override
public void onEvent(ClickOutEvent event) {
writeOutput("User click outside Grid: " + event.getSource().toString());
}
});
}
use of org.vaadin.patrik.events.EditorCloseEvent 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