Kanagaraj M has uploaded a new change for review. Change subject: webadmin: Adding "Select All" checkbox header to CellTable ......................................................................
webadmin: Adding "Select All" checkbox header to CellTable EntityModelCellTable and IVdcQueryableCellTable are enhanced to support a "Select All" functionality by providing a Checkbox in the header of the selection column. The Checkbox will be shown only if the CellTable supports multiselection and the showSelectAllCheckbox is true. Change-Id: I7f9f303143ecb322a6d325a56c3b97a23b3253c6 Signed-off-by: Kanagaraj M <kmayi...@redhat.com> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/IVdcQueryableCellTable.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/header/SelectAllCheckBoxHeader.java 3 files changed, 139 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/82/8282/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java index e515e25..f702547 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/EntityModelCellTable.java @@ -10,6 +10,7 @@ import org.ovirt.engine.ui.common.widget.HasEditorDriver; import org.ovirt.engine.ui.common.widget.table.ElementIdCellTable; import org.ovirt.engine.ui.common.widget.table.column.RadioboxCell; +import org.ovirt.engine.ui.common.widget.table.header.SelectAllCheckBoxHeader; import org.ovirt.engine.ui.uicommonweb.models.EntityModel; import org.ovirt.engine.ui.uicommonweb.models.ListModel; @@ -92,7 +93,7 @@ * Whether to hide selection column or not. */ public EntityModelCellTable(SelectionMode selectionMode, boolean hideCheckbox) { - this(selectionMode, (Resources) GWT.create(PopupTableResources.class), hideCheckbox); + this(selectionMode, (Resources) GWT.create(PopupTableResources.class), hideCheckbox, false); } /** @@ -110,13 +111,27 @@ /** * Create a new {@link EntityModelCellTable}. * + * @param isMultiple + * Whether to allow multiple ({@code true}) or single ({@code false}) selection mode. + * @param hideCheckbox + * Whether to hide selection column or not. + * @param showSelectAllCheckbox + * Whether to show the SelectAll Checkbox in the header or not. + */ + public EntityModelCellTable(boolean isMultiple, boolean hideCheckbox, boolean showSelectAllCheckbox) { + this(isMultiple, (Resources) GWT.create(PopupTableResources.class), hideCheckbox, showSelectAllCheckbox); + } + + /** + * Create a new {@link EntityModelCellTable}. + * * @param selectionMode * Table selection mode. * @param resources * Table resources. */ public EntityModelCellTable(SelectionMode selectionMode, Resources resources) { - this(selectionMode, resources, false); + this(selectionMode, resources, false, false); } /** @@ -128,14 +143,24 @@ * Table resources. */ public EntityModelCellTable(boolean isMultiple, Resources resources) { - this(isMultiple, resources, false); + this(isMultiple, resources, false, false); } public EntityModelCellTable(boolean isMultiple, Resources resources, boolean hideCheckbox) { - this(isMultiple ? SelectionMode.MULTIPLE : SelectionMode.SINGLE, resources, hideCheckbox); + this(isMultiple ? SelectionMode.MULTIPLE : SelectionMode.SINGLE, resources, hideCheckbox, false); } - public EntityModelCellTable(SelectionMode selectionMode, Resources resources, boolean hideCheckbox) { + public EntityModelCellTable(boolean isMultiple, + Resources resources, + boolean hideCheckbox, + boolean showSelectAllCheckbox) { + this(isMultiple ? SelectionMode.MULTIPLE : SelectionMode.SINGLE, resources, hideCheckbox, showSelectAllCheckbox); + } + + public EntityModelCellTable(SelectionMode selectionMode, + Resources resources, + boolean hideCheckbox, + boolean showSelectAllCheckbox) { super(DEFAULT_PAGESIZE, resources); // Configure table selection model @@ -200,6 +225,7 @@ return getSelectionModel().isSelected(object); } }; + addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); //$NON-NLS-1$ } else if (getSelectionModel() instanceof MultiSelectionModel) { checkColumn = new Column<EntityModel, Boolean>( new CheckboxCell(true, false)) { @@ -208,10 +234,33 @@ return getSelectionModel().isSelected(object); } }; + if (showSelectAllCheckbox) { + final SelectAllCheckBoxHeader<EntityModel> selectAllHeader = new SelectAllCheckBoxHeader<EntityModel>() { + + @Override + protected void selectionChanged(Boolean value) { + if (listModel == null || listModel.getItems() == null) { + return; + } + handleSelection(value, listModel, getSelectionModel()); + } + + @Override + public Boolean getValue() { + if (listModel == null || EntityModelCellTable.this.listModel.getItems() == null) { + return false; + } + return getCheckValue(listModel.getItems(), getSelectionModel()); + } + }; + addColumn(checkColumn, selectAllHeader); + } + else { + addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); //$NON-NLS-1$ + } } if (checkColumn != null) { - addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); //$NON-NLS-1$ setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX); } diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/IVdcQueryableCellTable.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/IVdcQueryableCellTable.java index 86bcf39..a45b80e 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/IVdcQueryableCellTable.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/IVdcQueryableCellTable.java @@ -9,6 +9,7 @@ import org.ovirt.engine.ui.common.PopupTableResources; import org.ovirt.engine.ui.common.widget.HasEditorDriver; import org.ovirt.engine.ui.common.widget.table.column.RadioboxCell; +import org.ovirt.engine.ui.common.widget.table.header.SelectAllCheckBoxHeader; import org.ovirt.engine.ui.uicommonweb.models.ListModel; import com.google.gwt.cell.client.CheckboxCell; @@ -46,6 +47,10 @@ } public IVdcQueryableCellTable(boolean multiSelection) { + this(multiSelection, false); + } + + public IVdcQueryableCellTable(boolean multiSelection, boolean showSelectAllCheckbox) { this(); if (!multiSelection) { @@ -92,6 +97,28 @@ return getSelectionModel().isSelected(object); } }; + if (showSelectAllCheckbox) { + final SelectAllCheckBoxHeader<IVdcQueryable> selectAllHeader = new SelectAllCheckBoxHeader<IVdcQueryable>() { + + @Override + protected void selectionChanged(Boolean value) { + if (listModel == null || listModel.getItems() == null) { + return; + } + handleSelection(value, listModel, getSelectionModel()); + } + + @Override + public Boolean getValue() { + if (listModel == null || listModel.getItems() == null) { + return false; + } + return getCheckValue(listModel.getItems(), getSelectionModel()); + } + }; + addColumn(checkColumn, selectAllHeader); + setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX); + } } else { checkColumn = new Column<IVdcQueryable, Boolean>( new RadioboxCell(true, false)) { @@ -101,8 +128,10 @@ } }; } - addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); //$NON-NLS-1$ - setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX); + if (!showSelectAllCheckbox) { + addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); //$NON-NLS-1$ + setColumnWidth(checkColumn, CHECK_COLUMN_WIDTH, Unit.PX); + } } @Override diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/header/SelectAllCheckBoxHeader.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/header/SelectAllCheckBoxHeader.java new file mode 100644 index 0000000..a5c467d --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/header/SelectAllCheckBoxHeader.java @@ -0,0 +1,53 @@ +package org.ovirt.engine.ui.common.widget.table.header; + +import java.util.ArrayList; + +import org.ovirt.engine.ui.uicommonweb.models.ListModel; + +import com.google.gwt.cell.client.CheckboxCell; +import com.google.gwt.cell.client.ValueUpdater; +import com.google.gwt.user.cellview.client.Header; +import com.google.gwt.view.client.SelectionModel; + +public abstract class SelectAllCheckBoxHeader<T> extends Header<Boolean> { + + public SelectAllCheckBoxHeader() { + super(new CheckboxCell(true, true)); + setUpdater(new ValueUpdater<Boolean>() { + @Override + public void update(Boolean value) { + selectionChanged(value); + } + }); + } + + protected abstract void selectionChanged(Boolean value); + + public void handleSelection(Boolean value, ListModel listModel, SelectionModel selectionModel) { + if (!listModel.getItems().iterator().hasNext()) { + return; + } + ArrayList<T> selectedItems = new ArrayList<T>(); + for (T entity : (Iterable<T>) listModel.getItems()) { + if (value) { + selectedItems.add(entity); + } + selectionModel.setSelected(entity, value); + } + listModel.setSelectedItems(selectedItems); + } + + public boolean getCheckValue(Iterable<T> items, SelectionModel selectionModel) { + if (!items.iterator().hasNext()) { + return false; + } + + boolean allSelected = true; + for (T entity : items) { + if (!selectionModel.isSelected(entity)) { + allSelected = false; + } + } + return allSelected; + } +} -- To view, visit http://gerrit.ovirt.org/8282 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7f9f303143ecb322a6d325a56c3b97a23b3253c6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Kanagaraj M <kmayi...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches