Search in sources :

Example 1 with ColumnSortEvent

use of com.google.gwt.user.cellview.client.ColumnSortEvent in project rstudio by rstudio.

the class FilesList method addColumnSortHandler.

private void addColumnSortHandler() {
    filesDataGrid_.addColumnSortHandler(new Handler() {

        @Override
        public void onColumnSort(ColumnSortEvent event) {
            ColumnSortList sortList = event.getColumnSortList();
            // insert the default initial sort order for size and modified
            if (!applyingProgrammaticSort_) {
                if (event.getColumn().equals(sizeColumn_) && forceSizeSortDescending) {
                    forceSizeSortDescending = false;
                    forceModifiedSortDescending = true;
                    sortList.insert(0, new com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo(event.getColumn(), false));
                } else if (event.getColumn().equals(modifiedColumn_) && forceModifiedSortDescending) {
                    forceModifiedSortDescending = false;
                    forceSizeSortDescending = true;
                    sortList.insert(0, new com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo(event.getColumn(), false));
                } else {
                    forceModifiedSortDescending = true;
                    forceSizeSortDescending = true;
                }
            }
            // record sort order and fire event to observer
            JsArray<ColumnSortInfo> sortOrder = newSortOrderArray();
            for (int i = 0; i < sortList.size(); i++) {
                // match the column index
                com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo sortInfo = sortList.get(i);
                Object column = sortInfo.getColumn();
                for (int c = 0; c < filesDataGrid_.getColumnCount(); c++) {
                    if (filesDataGrid_.getColumn(c).equals(column)) {
                        boolean ascending = sortInfo.isAscending();
                        sortOrder.push(ColumnSortInfo.create(c, ascending));
                        break;
                    }
                }
            }
            observer_.onColumnSortOrderChanaged(sortOrder);
            // record active sort column ascending state
            activeSortColumnAscending_ = event.isSortAscending();
            // delegate the sort
            sortHandler_.onColumnSort(event);
        }

        private final native JsArray<ColumnSortInfo> newSortOrderArray();

        private boolean forceSizeSortDescending = true;

        private boolean forceModifiedSortDescending = true;
    });
}
Also used : ColumnSortInfo(org.rstudio.core.client.cellview.ColumnSortInfo) JsArray(com.google.gwt.core.client.JsArray) Handler(com.google.gwt.user.cellview.client.ColumnSortEvent.Handler) ResizeHandler(com.google.gwt.event.logical.shared.ResizeHandler) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent) ColumnSortList(com.google.gwt.user.cellview.client.ColumnSortList)

Example 2 with ColumnSortEvent

use of com.google.gwt.user.cellview.client.ColumnSortEvent in project rstudio by rstudio.

the class BrowseAddinsDialog method addColumns.

private void addColumns() {
    // Package ----
    pkgColumn_ = new TextColumn<RAddin>() {

        @Override
        public String getValue(RAddin addin) {
            return addin.getPackage();
        }
    };
    pkgColumn_.setSortable(true);
    table_.addColumn(pkgColumn_, new TextHeader("Package"));
    table_.setColumnWidth(pkgColumn_, "120px");
    // Name ----
    nameColumn_ = new TextColumn<RAddin>() {

        @Override
        public String getValue(RAddin addin) {
            return StringUtil.truncate(addin.getName(), 120, "...");
        }
    };
    nameColumn_.setSortable(true);
    table_.addColumn(nameColumn_, new TextHeader("Name"));
    table_.setColumnWidth(nameColumn_, "120px");
    // Description ----
    descColumn_ = new TextColumn<RAddin>() {

        @Override
        public String getValue(RAddin addin) {
            return addin.getDescription();
        }
    };
    descColumn_.setSortable(true);
    table_.addColumn(descColumn_, new TextHeader("Description"));
    table_.addColumnSortHandler(new ColumnSortEvent.Handler() {

        @Override
        public void onColumnSort(ColumnSortEvent event) {
            int index = -1;
            if (event.getColumn().equals(pkgColumn_))
                index = 0;
            else if (event.getColumn().equals(nameColumn_))
                index = 1;
            else if (event.getColumn().equals(descColumn_))
                index = 2;
            if (index == -1)
                return;
            sort(index, event.isSortAscending());
        }
    });
}
Also used : RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) TextHeader(com.google.gwt.user.cellview.client.TextHeader) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent)

Example 3 with ColumnSortEvent

use of com.google.gwt.user.cellview.client.ColumnSortEvent 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

ColumnSortEvent (com.google.gwt.user.cellview.client.ColumnSortEvent)3 JsArray (com.google.gwt.core.client.JsArray)1 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 ResizeHandler (com.google.gwt.event.logical.shared.ResizeHandler)1 Handler (com.google.gwt.user.cellview.client.ColumnSortEvent.Handler)1 ColumnSortList (com.google.gwt.user.cellview.client.ColumnSortList)1 TextHeader (com.google.gwt.user.cellview.client.TextHeader)1 CellPreviewEvent (com.google.gwt.view.client.CellPreviewEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ColumnSortInfo (org.rstudio.core.client.cellview.ColumnSortInfo)1 Handle (org.rstudio.core.client.command.ShortcutManager.Handle)1 AddinsMRUList (org.rstudio.studio.client.workbench.AddinsMRUList)1 RAddin (org.rstudio.studio.client.workbench.addins.Addins.RAddin)1