Example usage for com.google.gwt.view.client CellPreviewEvent getNativeEvent

List of usage examples for com.google.gwt.view.client CellPreviewEvent getNativeEvent

Introduction

In this page you can find the example usage for com.google.gwt.view.client CellPreviewEvent getNativeEvent.

Prototype

public NativeEvent getNativeEvent() 

Source Link

Document

Get the NativeEvent to preview.

Usage

From source file:com.agnie.gwt.common.client.rpc.MultiSelectEventTranslator.java

License:Open Source License

@Override
public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if ("click".equals(nativeEvent.getType())) {

        // Determine if we clicked on a checkbox.
        Element target = nativeEvent.getEventTarget().cast();
        if ("input".equals(target.getTagName().toLowerCase())) {
            final InputElement input = target.cast();
            if ("checkbox".equals(input.getType().toLowerCase())) {
                // Synchronize the checkbox with the current selection state.
                input.setChecked(event.getDisplay().getSelectionModel().isSelected(event.getValue()));
                return SelectAction.TOGGLE;
            }//from w  w  w.j  ava2 s. co m
        } else if (cmd != null) {
            cmd.setSelected(event.getValue());
            Scheduler.get().scheduleDeferred(cmd);
        }
    }
    return SelectAction.IGNORE;
}

From source file:com.bearsoft.gwt.ui.widgets.grid.GridSection.java

public GridSection(ProvidesKey<T> keyProvider) {
    super(15, ThemedGridResources.instance, keyProvider, null, true, false);
    setKeyboardPagingPolicy(HasKeyboardPagingPolicy.KeyboardPagingPolicy.CURRENT_PAGE);
    setLoadingIndicator(null);//from  w ww  .j  a v  a2s  .c o m
    setEmptyTableWidget(null);
    getElement().getStyle().setProperty("borderCollapse", "collapse");
    setKeyboardSelectionHandler(new CellTableKeyboardSelectionHandler<T>(this) {

        @Override
        public void onCellPreview(CellPreviewEvent<T> event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            String eventType = event.getNativeEvent().getType();
            if (BrowserEvents.KEYDOWN.equals(eventType) && !event.isCellEditing()) {
                /*
                 * Handle keyboard navigation, unless the cell is being
                 * edited. If the cell is being edited, we do not want to
                 * change rows.
                 * 
                 * Prevent default on navigation events to prevent default
                 * scrollbar behavior.
                 */
                int oldRow = GridSection.this.getKeyboardSelectedRow();
                int oldColumn = GridSection.this.getKeyboardSelectedColumn();
                boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
                int keyCodeLineEnd = isRtl ? KeyCodes.KEY_LEFT : KeyCodes.KEY_RIGHT;
                int keyCodeLineStart = isRtl ? KeyCodes.KEY_RIGHT : KeyCodes.KEY_LEFT;
                int keyCode = nativeEvent.getKeyCode();
                super.onCellPreview(event);
                if (keyCode == keyCodeLineEnd) {
                    GridSection.this.setKeyboardSelectedRow(oldRow);
                    if (GridSection.this.getKeyboardSelectedColumn() < oldColumn)
                        GridSection.this.setKeyboardSelectedColumn(oldColumn);
                } else if (keyCode == keyCodeLineStart) {
                    GridSection.this.setKeyboardSelectedRow(oldRow);
                    if (GridSection.this.getKeyboardSelectedColumn() > oldColumn)
                        GridSection.this.setKeyboardSelectedColumn(oldColumn);
                }
            } else
                super.onCellPreview(event);
        }
    });
}

From source file:com.google.gwt.sample.showcase.client.content.cell.CustomKeyboardHandler.java

@Override
public void onCellPreview(CellPreviewEvent<ContactInfo> event) {
    if (Settings.get().getKeyHandling()) {
        NativeEvent nativeEvent = event.getNativeEvent();

        if (nativeEvent.getType() == BrowserEvents.KEYDOWN) { // A key was pushed down
            if (nativeEvent.getShiftKey() || nativeEvent.getAltKey() || nativeEvent.getCtrlKey()
                    || nativeEvent.getMetaKey()) {
                // Ignore if a modifier key is down
                return;
            }//from w ww . jav  a2 s.c  om

            switch (nativeEvent.getKeyCode()) {
            case KeyCodes.KEY_DOWN: // The down arrow key
            case KeyCodes.KEY_J:
                setCurrentRow(cellList.getKeyboardSelectedRow() + 1);
                cancelEvent(event);
                break;
            case KeyCodes.KEY_UP: // The up arrow key
            case KeyCodes.KEY_K:
                if (cellList.getKeyboardSelectedRow() < 1) {
                    goAboveList(event.getValue());
                } else {
                    setCurrentRow(cellList.getKeyboardSelectedRow() - 1);
                }
                cancelEvent(event);
                break;
            case KeyCodes.KEY_PAGEDOWN:
            case KeyCodes.KEY_SPACE:
                setCurrentRow(cellList.getKeyboardSelectedRow() + PAGE_INCREMENT);
                cancelEvent(event);
                break;
            case KeyCodes.KEY_PAGEUP:
                setCurrentRow(cellList.getKeyboardSelectedRow() - PAGE_INCREMENT);
                cancelEvent(event);
                break;
            case KeyCodes.KEY_HOME:
                setCurrentRow(cellList.getPageStart());
                cancelEvent(event);
                break;
            case KeyCodes.KEY_END:
                goToVeryEnd();
                cancelEvent(event);
                break;
            }

            // Bypass the default handler (super-class) for all keydown events.
            // For keys not handled here, let the browser handle them.
            return;
        }
    }

    // Should get here only if event was not handled above.  Send the event to
    // the default handler.
    super.onCellPreview(event);
}

From source file:com.google.gwt.sample.showcase.client.content.cell.CustomKeyboardHandler.java

void cancelEvent(CellPreviewEvent<ContactInfo> event) {
    event.setCanceled(true);
    event.getNativeEvent().preventDefault();
}

From source file:com.jitlogic.zico.client.views.admin.TraceTemplatePanel.java

License:Open Source License

private void createTemplateListGrid() {
    templateGrid = new DataGrid<TraceTemplateInfo>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<TraceTemplateInfo>(KEY_PROVIDER);
    templateGrid.setSelectionModel(selectionModel);

    Column<TraceTemplateInfo, TraceTemplateInfo> colOrder = new IdentityColumn<TraceTemplateInfo>(ORDER_CELL);
    templateGrid.addColumn(colOrder, new ResizableHeader<TraceTemplateInfo>("Order", templateGrid, colOrder));
    templateGrid.setColumnWidth(colOrder, 80, Style.Unit.PX);

    Column<TraceTemplateInfo, TraceTemplateInfo> colCondition = new IdentityColumn<TraceTemplateInfo>(
            CONDITION_CELL);// www  . j  a v  a 2s.co m
    templateGrid.addColumn(colCondition,
            new ResizableHeader<TraceTemplateInfo>("Condition", templateGrid, colCondition));
    templateGrid.setColumnWidth(colCondition, 250, Style.Unit.PX);

    Column<TraceTemplateInfo, TraceTemplateInfo> colTemplate = new IdentityColumn<TraceTemplateInfo>(
            TEMPLATE_CELL);
    templateGrid.addColumn(colTemplate, "Description Template");
    templateGrid.setColumnWidth(colTemplate, 100, Style.Unit.PCT);

    templateStore = new ListDataProvider<TraceTemplateInfo>(KEY_PROVIDER);
    templateStore.addDataDisplay(templateGrid);

    templateGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<TraceTemplateInfo>() {
        @Override
        public void onCellPreview(CellPreviewEvent<TraceTemplateInfo> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                selectionModel.setSelected(event.getValue(), true);
                editTemplate(null);
            }
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
                selectionModel.setSelected(event.getValue(), true);
                if (event.getValue() != null) {
                    contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),
                            event.getNativeEvent().getClientY());
                    contextMenu.show();
                }
            }

        }
    });

    templateGrid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());

    templateGrid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());
}

From source file:com.jitlogic.zico.client.views.admin.UserManagementPanel.java

License:Open Source License

private void createUserGrid() {
    userGrid = new DataGrid<UserInfo>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<UserInfo>(KEY_PROVIDER);
    userGrid.setSelectionModel(selectionModel);

    Column<UserInfo, UserInfo> colUsername = new IdentityColumn<UserInfo>(USERNAME_CELL);
    userGrid.addColumn(colUsername, new ResizableHeader<UserInfo>("Username", userGrid, colUsername));
    userGrid.setColumnWidth(colUsername, 128, Style.Unit.PX);

    Column<UserInfo, UserInfo> colUserRole = new IdentityColumn<UserInfo>(USERROLE_CELL);
    userGrid.addColumn(colUserRole, new ResizableHeader<UserInfo>("Role", userGrid, colUserRole));
    userGrid.setColumnWidth(colUserRole, 64, Style.Unit.PX);

    Column<UserInfo, UserInfo> colRealName = new IdentityColumn<UserInfo>(REALNAME_CELL);
    userGrid.addColumn(colRealName, new ResizableHeader<UserInfo>("Real Name", userGrid, colRealName));
    userGrid.setColumnWidth(colRealName, 256, Style.Unit.PX);

    Column<UserInfo, UserInfo> colUserHosts = new IdentityColumn<UserInfo>(USERHOSTS_CELL);
    userGrid.addColumn(colUserHosts, "Allowed hosts");
    userGrid.setColumnWidth(colUserHosts, 100, Style.Unit.PCT);

    userStore = new ListDataProvider<UserInfo>(KEY_PROVIDER);
    userStore.addDataDisplay(userGrid);//  w  w  w . j  a  v a  2s . c  om

    userGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<UserInfo>() {
        @Override
        public void onCellPreview(CellPreviewEvent<UserInfo> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                selectionModel.setSelected(event.getValue(), true);
                editUser(null);
            }
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
                selectionModel.setSelected(event.getValue(), true);
                if (event.getValue() != null) {
                    contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),
                            event.getNativeEvent().getClientY());
                    contextMenu.show();
                }
            }

        }
    });

    userGrid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());
    userGrid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());
}

From source file:com.jitlogic.zico.client.views.hosts.HostListPanel.java

License:Open Source License

private void createHostGrid() {

    hostGrid = new DataGrid<HostListObject>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<HostListObject>(KEY_PROVIDER);
    hostGrid.setSelectionModel(selectionModel);

    Column<HostListObject, HostListObject> colExpand = new IdentityColumn<HostListObject>(EXPAND_CELL);
    hostGrid.addColumn(colExpand, new ResizableHeader<HostListObject>("#", hostGrid, colExpand));
    hostGrid.setColumnWidth(colExpand, 36, Style.Unit.PX);

    Column<HostListObject, HostListObject> colName = new IdentityColumn<HostListObject>(NAME_CELL);
    hostGrid.addColumn(colName, new ResizableHeader<HostListObject>("Name", hostGrid, colName));
    hostGrid.setColumnWidth(colName, 140, Style.Unit.PX);

    Column<HostListObject, HostListObject> colAddr = new IdentityColumn<HostListObject>(ADDRESS_CELL);
    hostGrid.addColumn(colAddr, "Address");
    hostGrid.setColumnWidth(colAddr, 60, Style.Unit.PCT);

    hostGrid.setSkipRowHoverStyleUpdate(true);
    hostGrid.setSkipRowHoverFloatElementCheck(true);
    hostGrid.setSkipRowHoverCheck(true);
    hostGrid.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    hostGridStore = new ListDataProvider<HostListObject>();
    hostGridStore.addDataDisplay(hostGrid);

    hostGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<HostListObject>() {
        @Override//  www.j a  v  a  2  s. c  o m
        public void onCellPreview(CellPreviewEvent<HostListObject> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                selectionModel.setSelected(event.getValue(), true);

                enableSelectionDependentControls(event.getValue());

                if (event.getValue() instanceof HostInfo) {
                    listTraces(null);
                } else {
                    HostGroup hg = (HostGroup) event.getValue();
                    hg.toggleExpanded();
                    redrawHostList();
                }
            }
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
                selectionModel.setSelected(event.getValue(), true);
                if (event.getValue() != null) {
                    contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),
                            event.getNativeEvent().getClientY());
                    contextMenu.show();
                }
            }

            // TODO update toolbar icons and context menu on element selection
        }
    });

    hostGrid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());

    hostGrid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());

    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            enableSelectionDependentControls(selectionModel.getSelectedObject());
        }
    });
}

From source file:com.jitlogic.zico.client.views.traces.TraceCallTreePanel.java

License:Open Source License

private void createCallTreeGrid() {
    grid = new DataGrid<TraceRecordInfo>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selection = new SingleSelectionModel<TraceRecordInfo>(KEY_PROVIDER);
    grid.setSelectionModel(selection);/*from  w  w w  .ja v a2 s  .c  o  m*/

    Column<TraceRecordInfo, TraceRecordInfo> colExpander = new IdentityColumn<TraceRecordInfo>(
            DETAIL_EXPANDER_CELL);
    grid.addColumn(colExpander, "#");
    grid.setColumnWidth(colExpander, 32, Style.Unit.PX);

    Column<TraceRecordInfo, TraceRecordInfo> colMethodName = new IdentityColumn<TraceRecordInfo>(
            METHOD_TREE_CELL);
    grid.addColumn(colMethodName, new ResizableHeader<TraceRecordInfo>("Method", grid, colMethodName));
    grid.setColumnWidth(colMethodName, 100, Style.Unit.PCT);

    Column<TraceRecordInfo, TraceRecordInfo> colTime = new IdentityColumn<TraceRecordInfo>(METHOD_TIME_CELL);
    grid.addColumn(colTime, new ResizableHeader<TraceRecordInfo>("Time", grid, colTime));
    grid.setColumnWidth(colTime, 60, Style.Unit.PX);
    colTime.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    Column<TraceRecordInfo, TraceRecordInfo> colCTime = new IdentityColumn<TraceRecordInfo>(METHOD_CTIME_CELL);
    grid.addColumn(colCTime, new ResizableHeader<TraceRecordInfo>("CTime", grid, colTime));
    grid.setColumnWidth(colCTime, 60, Style.Unit.PX);
    colCTime.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    Column<TraceRecordInfo, TraceRecordInfo> colCalls = new IdentityColumn<TraceRecordInfo>(METHOD_CALLS_CELL);
    grid.addColumn(colCalls, new ResizableHeader<TraceRecordInfo>("Calls", grid, colCalls));
    grid.setColumnWidth(colCalls, 60, Style.Unit.PX);

    Column<TraceRecordInfo, TraceRecordInfo> colErrors = new IdentityColumn<TraceRecordInfo>(
            METHOD_ERRORS_CELL);
    grid.addColumn(colErrors, new ResizableHeader<TraceRecordInfo>("Errors", grid, colErrors));
    grid.setColumnWidth(colErrors, 60, Style.Unit.PX);

    Column<TraceRecordInfo, TraceRecordInfo> colPct = new IdentityColumn<TraceRecordInfo>(METHOD_PCT_CELL);
    grid.addColumn(colPct, new ResizableHeader<TraceRecordInfo>("Pct", grid, colPct));
    grid.setColumnWidth(colPct, 60, Style.Unit.PX);

    rowBuilder = new TraceCallTableBuilder(grid, expandedDetails);
    grid.setTableBuilder(rowBuilder);

    // Disable hovering "features" overall to improve performance on big trees.
    grid.setSkipRowHoverStyleUpdate(true);
    grid.setSkipRowHoverFloatElementCheck(true);
    grid.setSkipRowHoverCheck(true);
    grid.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    grid.addCellPreviewHandler(new CellPreviewEvent.Handler<TraceRecordInfo>() {
        @Override
        public void onCellPreview(CellPreviewEvent<TraceRecordInfo> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                TraceRecordInfo tr = event.getValue();
                panelFactory.methodAttrsDialog(trace.getHostName(), trace.getDataOffs(), tr.getPath(), 0L)
                        .asPopupWindow().show();
            }
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
                selection.setSelected(event.getValue(), true);
                contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),
                        event.getNativeEvent().getClientY());
                contextMenu.show();
            }
        }
    });

    grid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());

    grid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());

    data = new ListDataProvider<TraceRecordInfo>();
    data.addDataDisplay(grid);
}

From source file:com.jitlogic.zico.client.views.traces.TraceRecordSearchDialog.java

License:Open Source License

private void createResultsGrid() {

    resultsGrid = new DataGrid<TraceRecordInfo>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<TraceRecordInfo>(KEY_PROVIDER);
    resultsGrid.setSelectionModel(selectionModel);

    Column<TraceRecordInfo, TraceRecordInfo> colExpander = new IdentityColumn<TraceRecordInfo>(
            DETAIL_EXPANDER_CELL);//from   w  w  w .j  ava 2  s .co  m
    resultsGrid.addColumn(colExpander, "#");
    resultsGrid.setColumnWidth(colExpander, 32, Style.Unit.PX);

    Column<TraceRecordInfo, TraceRecordInfo> colMethod = new IdentityColumn<TraceRecordInfo>(METHOD_CELL);
    resultsGrid.addColumn(colMethod, new ResizableHeader<TraceRecordInfo>("Method", resultsGrid, colMethod));
    resultsGrid.setColumnWidth(colMethod, 100, Style.Unit.PCT);

    Column<TraceRecordInfo, String> colTime = new Column<TraceRecordInfo, String>(new TextCell()) {
        @Override
        public String getValue(TraceRecordInfo rec) {
            return ClientUtil.formatDuration(rec.getTime());
        }
    };
    resultsGrid.addColumn(colTime, new ResizableHeader<TraceRecordInfo>("Time", resultsGrid, colTime));
    resultsGrid.setColumnWidth(colTime, 50, Style.Unit.PX);

    Column<TraceRecordInfo, String> colCalls = new Column<TraceRecordInfo, String>(new TextCell()) {
        @Override
        public String getValue(TraceRecordInfo rec) {
            return "" + rec.getCalls();
        }
    };
    resultsGrid.addColumn(colCalls, new ResizableHeader<TraceRecordInfo>("Calls", resultsGrid, colCalls));
    resultsGrid.setColumnWidth(colCalls, 50, Style.Unit.PX);

    Column<TraceRecordInfo, String> colErrors = new Column<TraceRecordInfo, String>(new TextCell()) {
        @Override
        public String getValue(TraceRecordInfo rec) {
            return "" + rec.getErrors();
        }
    };
    resultsGrid.addColumn(colErrors, new ResizableHeader<TraceRecordInfo>("Errors", resultsGrid, colErrors));
    resultsGrid.setColumnWidth(colErrors, 50, Style.Unit.PX);

    Column<TraceRecordInfo, TraceRecordInfo> colPct = new IdentityColumn<TraceRecordInfo>(METHOD_PCT_CELL);
    resultsGrid.addColumn(colPct, new ResizableHeader<TraceRecordInfo>("Pct", resultsGrid, colPct));
    resultsGrid.setColumnWidth(colPct, 50, Style.Unit.PX);

    rowBuilder = new TraceCallTableBuilder(resultsGrid, expandedDetails);
    resultsGrid.setTableBuilder(rowBuilder);

    resultsGrid.setSkipRowHoverStyleUpdate(true);
    resultsGrid.setSkipRowHoverFloatElementCheck(true);
    resultsGrid.setSkipRowHoverCheck(true);
    resultsGrid.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    resultsGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<TraceRecordInfo>() {
        @Override
        public void onCellPreview(CellPreviewEvent<TraceRecordInfo> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                doGoTo();
            }
            //if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
            //    selection.setSelected(event.getValue(), true);
            //    contextMenu.showAt(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
            //}
        }
    });

    resultsGrid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());
    resultsGrid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());

    resultsStore = new ListDataProvider<TraceRecordInfo>();
    resultsStore.addDataDisplay(resultsGrid);
}

From source file:com.jitlogic.zico.client.views.traces.TraceSearchPanel.java

License:Open Source License

private void createTraceGrid() {
    grid = new DataGrid<TraceInfo>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selection = new SingleSelectionModel<TraceInfo>(KEY_PROVIDER);
    grid.setSelectionModel(selection);/*from   w w w  .j  a  v  a  2 s  .  c om*/

    data = new ListDataProvider<TraceInfo>();
    data.addDataDisplay(grid);

    sortHandler = new ColumnSortEvent.ListHandler<TraceInfo>(data.getList());
    grid.addColumnSortHandler(sortHandler);

    Column<TraceInfo, TraceInfo> colExpander = new IdentityColumn<TraceInfo>(DETAIL_EXPANDER_CELL);
    grid.addColumn(colExpander, "#");
    grid.setColumnWidth(colExpander, 32, Style.Unit.PX);

    Column<TraceInfo, TraceInfo> colTraceClock = new IdentityColumn<TraceInfo>(TRACE_CLOCK_CELL);
    grid.addColumn(colTraceClock, new ResizableHeader<TraceInfo>("Clock", grid, colTraceClock));
    grid.setColumnWidth(colTraceClock, 140, Style.Unit.PX);

    colTraceClock.setSortable(true);
    sortHandler.setComparator(colTraceClock, new Comparator<TraceInfo>() {
        @Override
        public int compare(TraceInfo o1, TraceInfo o2) {
            return (int) (o1.getClock() - o2.getClock());
        }
    });

    Column<TraceInfo, TraceInfo> colTraceType = new IdentityColumn<TraceInfo>(TRACE_TYPE_CELL);
    grid.addColumn(colTraceType, new ResizableHeader<TraceInfo>("Type", grid, colTraceType));
    grid.setColumnWidth(colTraceType, 60, Style.Unit.PX);

    Column<TraceInfo, TraceInfo> colTraceDuration = new IdentityColumn<TraceInfo>(TRACE_DURATION_CELL);
    grid.addColumn(colTraceDuration, new ResizableHeader<TraceInfo>("Time", grid, colTraceDuration));
    grid.setColumnWidth(colTraceDuration, 64, Style.Unit.PX);
    colTraceDuration.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    colTraceDuration.setSortable(true);
    sortHandler.setComparator(colTraceDuration, new Comparator<TraceInfo>() {
        @Override
        public int compare(TraceInfo o1, TraceInfo o2) {
            return (int) ((o1.getExecutionTime() - o2.getExecutionTime()) / 1000000L);
        }
    });

    Column<TraceInfo, TraceInfo> colTraceCalls = new IdentityColumn<TraceInfo>(TRACE_CALLS_CELL);
    grid.addColumn(colTraceCalls, new ResizableHeader<TraceInfo>("Calls", grid, colTraceCalls));
    grid.setColumnWidth(colTraceCalls, 50, Style.Unit.PX);

    colTraceCalls.setSortable(true);
    sortHandler.setComparator(colTraceCalls, new Comparator<TraceInfo>() {
        @Override
        public int compare(TraceInfo o1, TraceInfo o2) {
            return (int) (o1.getCalls() - o2.getCalls());
        }
    });

    Column<TraceInfo, TraceInfo> colTraceErrors = new IdentityColumn<TraceInfo>(TRACE_ERRORS_CELL);
    grid.addColumn(colTraceErrors, new ResizableHeader<TraceInfo>("Errs", grid, colTraceErrors));
    grid.setColumnWidth(colTraceErrors, 50, Style.Unit.PX);

    colTraceErrors.setSortable(true);
    sortHandler.setComparator(colTraceErrors, new Comparator<TraceInfo>() {
        @Override
        public int compare(TraceInfo o1, TraceInfo o2) {
            return (int) (o1.getErrors() - o2.getErrors());
        }
    });

    Column<TraceInfo, TraceInfo> colTraceRecords = new IdentityColumn<TraceInfo>(TRACE_RECORDS_CELL);
    grid.addColumn(colTraceRecords, new ResizableHeader<TraceInfo>("Recs", grid, colTraceRecords));
    grid.setColumnWidth(colTraceRecords, 50, Style.Unit.PX);

    colTraceRecords.setSortable(true);
    sortHandler.setComparator(colTraceRecords, new Comparator<TraceInfo>() {
        @Override
        public int compare(TraceInfo o1, TraceInfo o2) {
            return (int) (o1.getRecords() - o2.getRecords());
        }
    });

    Column<TraceInfo, TraceInfo> colTraceDesc = new IdentityColumn<TraceInfo>(TRACE_NAME_CELL);
    grid.addColumn(colTraceDesc, "Description");
    grid.setColumnWidth(colTraceDesc, 100, Style.Unit.PCT);

    rowBuilder = new TraceSearchTableBuilder(grid, expandedDetails);
    grid.setTableBuilder(rowBuilder);

    grid.setSkipRowHoverStyleUpdate(true);
    grid.setSkipRowHoverFloatElementCheck(true);
    grid.setSkipRowHoverCheck(true);
    grid.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    grid.addCellPreviewHandler(new CellPreviewEvent.Handler<TraceInfo>() {
        @Override
        public void onCellPreview(CellPreviewEvent<TraceInfo> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if ((BrowserEvents.KEYDOWN.equals(eventType) && nev.getKeyCode() == KeyCodes.KEY_ENTER)
                    || BrowserEvents.DBLCLICK.equals(nev.getType())) {
                selection.setSelected(event.getValue(), true);
                openDetailView();
            }
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
                selection.setSelected(event.getValue(), true);
                if (selection.getSelectedObject() != null) {
                    contextMenu.setPopupPosition(event.getNativeEvent().getClientX(),
                            event.getNativeEvent().getClientY());
                    contextMenu.show();
                }
            }
        }
    });

    grid.addDomHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
        }
    }, DoubleClickEvent.getType());
    grid.addDomHandler(new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
        }
    }, ContextMenuEvent.getType());
}