Search in sources :

Example 1 with FastNavigationServerRPC

use of org.vaadin.patrik.shared.FastNavigationServerRPC 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);
}
Also used : RowFocusEvent(org.vaadin.patrik.events.RowFocusEvent) ClickOutEvent(org.vaadin.patrik.events.ClickOutEvent) Grid(com.vaadin.ui.Grid) ArrayList(java.util.ArrayList) RowEditEvent(org.vaadin.patrik.events.RowEditEvent) CellEditEvent(org.vaadin.patrik.events.CellEditEvent) EditorCloseEvent(org.vaadin.patrik.events.EditorCloseEvent) EditorOpenEvent(org.vaadin.patrik.events.EditorOpenEvent) FastNavigationServerRPC(org.vaadin.patrik.shared.FastNavigationServerRPC) Indexed(com.vaadin.data.Container.Indexed) CellFocusEvent(org.vaadin.patrik.events.CellFocusEvent)

Aggregations

Indexed (com.vaadin.data.Container.Indexed)1 Grid (com.vaadin.ui.Grid)1 ArrayList (java.util.ArrayList)1 CellEditEvent (org.vaadin.patrik.events.CellEditEvent)1 CellFocusEvent (org.vaadin.patrik.events.CellFocusEvent)1 ClickOutEvent (org.vaadin.patrik.events.ClickOutEvent)1 EditorCloseEvent (org.vaadin.patrik.events.EditorCloseEvent)1 EditorOpenEvent (org.vaadin.patrik.events.EditorOpenEvent)1 RowEditEvent (org.vaadin.patrik.events.RowEditEvent)1 RowFocusEvent (org.vaadin.patrik.events.RowFocusEvent)1 FastNavigationServerRPC (org.vaadin.patrik.shared.FastNavigationServerRPC)1