Search in sources :

Example 1 with SearchableListModel

use of org.ovirt.engine.ui.uicommonweb.models.SearchableListModel in project ovirt-engine by oVirt.

the class AbstractActionStackPanelItem method addDoubleClickHandler.

void addDoubleClickHandler(final W widget, final M modelProvider) {
    if (modelProvider instanceof SearchableTableModelProvider<?, ?>) {
        widget.addDomHandler(event -> {
            SearchableListModel model = ((SearchableTableModelProvider<?, ?>) modelProvider).getModel();
            UICommand command = model.getDoubleClickCommand();
            if (command != null && command.getIsExecutionAllowed()) {
                DeferredModelCommandInvoker invoker = new DeferredModelCommandInvoker(model);
                invoker.invokeCommand(command);
            }
        }, DoubleClickEvent.getType());
    }
}
Also used : SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) DeferredModelCommandInvoker(org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker) SearchableTableModelProvider(org.ovirt.engine.ui.common.uicommon.model.SearchableTableModelProvider) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 2 with SearchableListModel

use of org.ovirt.engine.ui.uicommonweb.models.SearchableListModel in project ovirt-engine by oVirt.

the class ColumnResizeCellTable method applySort.

private void applySort(ColumnSortEvent event, SortedListModel<T> sortedModel) {
    Column<?, ?> column = event.getColumn();
    if (!(column instanceof SortableColumn)) {
        // Column is not sortable, nothing to do
        return;
    }
    SortableColumn<T> sortableColumn = (SortableColumn<T>) column;
    SearchableListModel<?, T> searchableModel = (sortedModel instanceof SearchableListModel) ? (SearchableListModel<?, T>) sortedModel : null;
    boolean sortApplied = false;
    boolean supportsServerSideSorting = searchableModel != null && searchableModel.supportsServerSideSorting();
    // Ensure consistent item order with fallback comparator
    Comparator<? super T> columnComparator = sortableColumn.getComparator();
    Comparator<? super T> realComparator = columnComparator;
    if (sortedModel.useDefaultItemComparator() && columnComparator != null) {
        realComparator = DefaultModelItemComparator.fallbackFor(columnComparator);
    }
    // uses Comparator for client-side sorting, use client-side sorting
    if (supportsServerSideSorting && realComparator != null) {
        sortedModel.setComparator(realComparator, event.isSortAscending());
        sortApplied = true;
    } else // update model's sort options and reload its items via search query
    if (supportsServerSideSorting) {
        sortedModel.setComparator(null);
        if (searchableModel.isSearchValidForServerSideSorting()) {
            searchableModel.updateSortOptions(sortableColumn.getSortBy(), event.isSortAscending());
            sortApplied = true;
        } else {
            // Search string not valid, cannot perform search query
            searchableModel.clearSortOptions();
        }
    } else // Otherwise, fall back to client-side sorting
    if (realComparator != null) {
        sortedModel.setComparator(realComparator, event.isSortAscending());
        sortApplied = true;
        // SortedListModel.setComparator does not sort the items
        if (searchableModel == null) {
            sortedModel.setItems(sortedModel.getItems());
        }
    }
    // Update column sort status, redrawing table headers if necessary
    ColumnSortInfo columnSortInfo = event.getColumnSortList().get(0);
    if (sortApplied) {
        pushColumnSort(columnSortInfo);
    } else {
        clearColumnSort();
    }
}
Also used : SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ColumnSortInfo(com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo) SortableColumn(org.ovirt.engine.ui.common.widget.table.column.SortableColumn)

Aggregations

SearchableListModel (org.ovirt.engine.ui.uicommonweb.models.SearchableListModel)2 ColumnSortInfo (com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo)1 DeferredModelCommandInvoker (org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker)1 SearchableTableModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableTableModelProvider)1 SortableColumn (org.ovirt.engine.ui.common.widget.table.column.SortableColumn)1 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)1