Search in sources :

Example 1 with SelectionModel

use of com.google.gwt.view.client.SelectionModel in project ovirt-engine by oVirt.

the class EntityModelCellTable method addSelectionChangeHandler.

public void addSelectionChangeHandler() {
    // Handle selection
    getSelectionModel().addSelectionChangeHandler(new Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            if (getListModel() == null || getListModel().getItems() == null) {
                return;
            }
            // Clear "IsSelected"
            for (EntityModel entity : (List<EntityModel>) getListModel().getItems()) {
                entity.setIsSelected(false);
            }
            // Set "IsSelected"
            SelectionModel<? super EntityModel> selectionModel = EntityModelCellTable.this.getSelectionModel();
            if (selectionModel instanceof SingleSelectionModel) {
                EntityModel selectedObject = ((SingleSelectionModel<EntityModel>) selectionModel).getSelectedObject();
                clearCurrentSelectedItems();
                if (selectedObject != null) {
                    selectedObject.setIsSelected(true);
                    getListModel().setSelectedItem(selectedObject);
                }
            } else if (selectionModel instanceof MultiSelectionModel) {
                List<EntityModel> selectedItems = new ArrayList<>();
                for (EntityModel entity : ((MultiSelectionModel<EntityModel>) selectionModel).getSelectedSet()) {
                    entity.setIsSelected(true);
                    selectedItems.add(entity);
                }
                clearCurrentSelectedItems();
                getListModel().setSelectedItems(selectedItems);
            }
        }

        private void clearCurrentSelectedItems() {
            getListModel().setSelectedItems(null);
            getListModel().setSelectedItem(null);
        }
    });
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) Handler(com.google.gwt.view.client.SelectionChangeEvent.Handler) SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) SelectionModel(com.google.gwt.view.client.SelectionModel) NoSelectionModel(com.google.gwt.view.client.NoSelectionModel) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 2 with SelectionModel

use of com.google.gwt.view.client.SelectionModel 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 SelectionModel (com.google.gwt.view.client.SelectionModel)2 ArrayList (java.util.ArrayList)2 NoSelectionModel (com.google.gwt.view.client.NoSelectionModel)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 Handler (com.google.gwt.view.client.SelectionChangeEvent.Handler)1 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)1 AbstractCheckboxColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractCheckboxColumn)1 AbstractSelectAllCheckBoxHeader (org.ovirt.engine.ui.common.widget.table.header.AbstractSelectAllCheckBoxHeader)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