Search in sources :

Example 1 with AbstractSelectAllCheckBoxHeader

use of org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader in project ovirt-engine by oVirt.

the class EntityModelCellTable method addCheckBoxColumn.

private void addCheckBoxColumn(boolean hideCheckbox, boolean showSelectAllCheckbox) {
    if (!hideCheckbox) {
        // Add selection column
        Column<EntityModel, Boolean> checkColumn = null;
        if (getSelectionModel() instanceof SingleSelectionModel) {
            checkColumn = new Column<EntityModel, Boolean>(new RadioboxCell(true, false)) {

                @Override
                public Boolean getValue(EntityModel object) {
                    return getSelectionModel().isSelected(object);
                }
            };
            addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(constants.htmlNonBreakingSpace()));
        } else if (getSelectionModel() instanceof MultiSelectionModel) {
            checkColumn = new Column<EntityModel, Boolean>(new CheckboxCell(true, false)) {

                @Override
                public Boolean getValue(EntityModel object) {
                    return getSelectionModel().isSelected(object);
                }
            };
            if (showSelectAllCheckbox) {
                AbstractSelectAllCheckBoxHeader<EntityModel> selectAllHeader = new AbstractSelectAllCheckBoxHeader<EntityModel>() {

                    @Override
                    protected void selectionChanged(Boolean value) {
                        if (getListModel() == null || getListModel().getItems() == null) {
                            return;
                        }
                        handleSelection(value, getListModel(), getSelectionModel());
                    }

                    @Override
                    public Boolean getValue() {
                        if (getListModel() == null || getListModel().getItems() == null) {
                            return false;
                        }
                        return getCheckValue(getListModel().getItems(), getSelectionModel());
                    }
                };
                addColumn(checkColumn, selectAllHeader);
            } else {
                addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(constants.htmlNonBreakingSpace()));
            }
        }
        if (checkColumn != null) {
            setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX);
            selectionColumnPresent = true;
        }
        addCellPreviewHandler(event -> {
            int columnIndex = event.getColumn();
            Cell<?> cell = getColumn(columnIndex).getCell();
            if (cell instanceof EventHandlingCell && ((EventHandlingCell) cell).handlesEvent(event)) {
                return;
            }
            if (BrowserEvents.CLICK.equals(event.getNativeEvent().getType()) && !(getSelectionModel() instanceof NoSelectionModel)) {
                // Let the selection column deal with this
                if (event.getColumn() == 0) {
                    return;
                }
                getSelectionModel().setSelected(event.getValue(), !getSelectionModel().isSelected(event.getValue()));
            }
        });
    }
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) RadioboxCell(org.ovirt.engine.ui.common.widget.table.cell.RadioboxCell) AbstractSelectAllCheckBoxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader) Column(com.google.gwt.user.cellview.client.Column) EventHandlingCell(org.ovirt.engine.ui.common.widget.table.cell.EventHandlingCell) CheckboxCell(org.ovirt.engine.ui.common.widget.table.cell.CheckboxCell)

Example 2 with AbstractSelectAllCheckBoxHeader

use of org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader in project ovirt-engine by oVirt.

the class ImportIscsiStorageView method addTargetsSelectionColumn.

private void addTargetsSelectionColumn() {
    AbstractSelectAllCheckBoxHeader<SanTargetModel> selectAllHeader = new AbstractSelectAllCheckBoxHeader<SanTargetModel>() {

        @Override
        protected void selectionChanged(Boolean value) {
            ListModel listModel = targetsTable.asEditor().flush();
            if (listModel == null || listModel.getItems() == null) {
                return;
            }
            handleSelection(value, listModel, targetsTable.getSelectionModel());
        }

        @Override
        public void handleSelection(Boolean value, ListModel listModel, SelectionModel selectionModel) {
            if (!listModel.getItems().iterator().hasNext()) {
                return;
            }
            ArrayList<SanTargetModel> selectedItems = new ArrayList<>();
            for (SanTargetModel entity : (Iterable<SanTargetModel>) listModel.getItems()) {
                if (!entity.getIsLoggedIn()) {
                    if (value) {
                        selectedItems.add(entity);
                    }
                    selectionModel.setSelected(entity, value);
                }
            }
            listModel.setSelectedItems(selectedItems);
        }

        @Override
        public Boolean getValue() {
            ListModel listModel = targetsTable.asEditor().flush();
            if (listModel == null || listModel.getItems() == null) {
                return false;
            }
            return getCheckValue(listModel.getItems(), targetsTable.getSelectionModel());
        }
    };
    AbstractCheckboxColumn<SanTargetModel> checkColumn = new AbstractCheckboxColumn<SanTargetModel>() {

        @Override
        protected boolean canEdit(SanTargetModel object) {
            return !object.getIsLoggedIn();
        }

        @Override
        public Boolean getValue(SanTargetModel object) {
            return targetsTable.getSelectionModel().isSelected(object) || object.getIsLoggedIn();
        }
    };
    // $NON-NLS-1$
    targetsTable.addColumn(checkColumn, selectAllHeader, "25px");
}
Also used : AbstractSelectAllCheckBoxHeader(org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader) SanTargetModel(org.ovirt.engine.ui.uicommonweb.models.storage.SanTargetModel) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ArrayList(java.util.ArrayList) SelectionModel(com.google.gwt.view.client.SelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) AbstractCheckboxColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn)

Aggregations

MultiSelectionModel (com.google.gwt.view.client.MultiSelectionModel)2 AbstractSelectAllCheckBoxHeader (org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader)2 Column (com.google.gwt.user.cellview.client.Column)1 NoSelectionModel (com.google.gwt.view.client.NoSelectionModel)1 SelectionModel (com.google.gwt.view.client.SelectionModel)1 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)1 ArrayList (java.util.ArrayList)1 CheckboxCell (org.ovirt.engine.ui.common.widget.table.cell.CheckboxCell)1 EventHandlingCell (org.ovirt.engine.ui.common.widget.table.cell.EventHandlingCell)1 RadioboxCell (org.ovirt.engine.ui.common.widget.table.cell.RadioboxCell)1 AbstractCheckboxColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn)1 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)1 ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)1 SanTargetModel (org.ovirt.engine.ui.uicommonweb.models.storage.SanTargetModel)1