Search in sources :

Example 1 with Handle

use of org.rstudio.core.client.command.ShortcutManager.Handle in project rstudio by rstudio.

the class ModifyKeyboardShortcutsWidget method addHandlers.

private void addHandlers() {
    table_.addCellPreviewHandler(new CellPreviewEvent.Handler<KeyboardShortcutEntry>() {

        @Override
        public void onCellPreview(CellPreviewEvent<KeyboardShortcutEntry> preview) {
            Handle shortcutsHandler = shortcuts_.disable();
            int column = preview.getColumn();
            if (column == 0)
                onNameCellPreview(preview);
            else if (column == 1)
                onShortcutCellPreview(preview);
            else if (column == 2)
                onNameCellPreview(preview);
            shortcutsHandler.close();
        }
    });
    table_.addColumnSortHandler(new ColumnSortEvent.Handler() {

        @Override
        public void onColumnSort(ColumnSortEvent event) {
            List<KeyboardShortcutEntry> data = dataProvider_.getList();
            if (event.getColumn().equals(nameColumn_))
                sort(data, 0, event.isSortAscending());
            else if (event.getColumn().equals(shortcutColumn_))
                sort(data, 1, event.isSortAscending());
            else if (event.getColumn().equals(typeColumn_))
                sort(data, 2, event.isSortAscending());
            updateData(data);
        }
    });
    // Fix a bug where clicking on a table header would also
    // select the cell at position [0, 0]. It seems that GWT's
    // DataGrid over-aggressively selects the first cell on the
    // _first_ mouse down event seen; after the first click,
    // cell selection occurs only after full mouse clicks.
    table_.addDomHandler(new MouseDownHandler() {

        @Override
        public void onMouseDown(MouseDownEvent event) {
            Element target = event.getNativeEvent().getEventTarget().cast();
            if (target.hasAttribute("__gwt_header")) {
                event.stopPropagation();
                event.preventDefault();
            }
        }
    }, MouseDownEvent.getType());
}
Also used : Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) MouseDownEvent(com.google.gwt.event.dom.client.MouseDownEvent) AddinsMRUList(org.rstudio.studio.client.workbench.AddinsMRUList) List(java.util.List) ArrayList(java.util.ArrayList) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent) MouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler) CellPreviewEvent(com.google.gwt.view.client.CellPreviewEvent) Handle(org.rstudio.core.client.command.ShortcutManager.Handle)

Aggregations

Element (com.google.gwt.dom.client.Element)1 TableRowElement (com.google.gwt.dom.client.TableRowElement)1 MouseDownEvent (com.google.gwt.event.dom.client.MouseDownEvent)1 MouseDownHandler (com.google.gwt.event.dom.client.MouseDownHandler)1 ColumnSortEvent (com.google.gwt.user.cellview.client.ColumnSortEvent)1 CellPreviewEvent (com.google.gwt.view.client.CellPreviewEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Handle (org.rstudio.core.client.command.ShortcutManager.Handle)1 AddinsMRUList (org.rstudio.studio.client.workbench.AddinsMRUList)1