Lior Vernia has uploaded a new change for review. Change subject: webadmin: Change checkbox column to radio button column ......................................................................
webadmin: Change checkbox column to radio button column The semantics when managing cluster networks were those of a radio button column implemented through a checkbox column, so now the view is changed to also look like radio buttons. This was done by extending the capabilities of CheckboxColumn, to also function as a radio button column when needed. Change-Id: I6576b816c53e482b54d49877eaa04088aa9f5960 Bug-Url: https://bugzilla.redhat.com/1023722 Signed-off-by: Lior Vernia <lver...@redhat.com> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/cluster/ClusterManageNetworkPopupView.java 2 files changed, 61 insertions(+), 44 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/64/22464/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java index 67a818d..6753bc6 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/CheckboxColumn.java @@ -2,7 +2,6 @@ import org.ovirt.engine.ui.uicommonweb.models.EntityModel; -import com.google.gwt.cell.client.Cell; import com.google.gwt.cell.client.Cell.Context; import com.google.gwt.cell.client.CheckboxCell; import com.google.gwt.cell.client.FieldUpdater; @@ -17,6 +16,7 @@ public abstract class CheckboxColumn<T> extends Column<T, Boolean> { private boolean isCentralized = false; + private boolean multipleSelectionAllowed = true; static class EnabledDisabledCheckboxCell extends CheckboxCell implements EventHandlingCell { @@ -24,41 +24,39 @@ super(true, false); } - public void renderEditable(Context context, - Boolean value, - boolean canEdit, - SafeHtmlBuilder sb, - String disabledMessage) { - if (!canEdit) { - sb.append(INPUT_CHECKBOX_DISABLED_PREFIX); - if (value) { - sb.append(CHECKED_ATTR); - } - if (disabledMessage != null && !disabledMessage.isEmpty()) { - sb.append(TITLE_ATTR_START); - sb.append(SafeHtmlUtils.fromString(disabledMessage)); - sb.append(TITLE_ATTR_END); - } - sb.append(TAG_CLOSE); - } else { - super.render(context, value, sb); - } - } - @Override public boolean handlesEvent(CellPreviewEvent<EntityModel> event) { - NativeEvent nativeEvent = event.getNativeEvent(); - if (!"click".equals(nativeEvent.getType().toLowerCase())) { //$NON-NLS-1$ - return false; - } - Element target = nativeEvent.getEventTarget().cast(); - return "input".equals(target.getTagName().toLowerCase()); //$NON-NLS-1$ + return CheckboxColumn.handlesEvent(event); } } + static class EnabledDisabledRadioCell extends RadioboxCell implements EventHandlingCell { + + public EnabledDisabledRadioCell() { + super(true, false); + } + + @Override + public boolean handlesEvent(CellPreviewEvent<EntityModel> event) { + return CheckboxColumn.handlesEvent(event); + } + + } + + private static boolean handlesEvent(CellPreviewEvent<EntityModel> event) { + NativeEvent nativeEvent = event.getNativeEvent(); + if (!"click".equals(nativeEvent.getType().toLowerCase())) { //$NON-NLS-1$ + return false; + } + Element target = nativeEvent.getEventTarget().cast(); + return "input".equals(target.getTagName().toLowerCase()); //$NON-NLS-1$ + } + private static final SafeHtml INPUT_CHECKBOX_DISABLED_PREFIX = SafeHtmlUtils.fromTrustedString("<input type=\"checkbox\" tabindex=\"-1\" disabled"); //$NON-NLS-1$ + private static final SafeHtml INPUT_RADIO_DISABLED_PREFIX = + SafeHtmlUtils.fromTrustedString("<input type=\"radio\" tabindex=\"-1\" disabled"); //$NON-NLS-1$ private static final SafeHtml CHECKED_ATTR = SafeHtmlUtils.fromTrustedString(" checked"); //$NON-NLS-1$ private static final SafeHtml TITLE_ATTR_START = SafeHtmlUtils.fromTrustedString(" title=\""); //$NON-NLS-1$ private static final SafeHtml TITLE_ATTR_END = SafeHtmlUtils.fromTrustedString("\""); //$NON-NLS-1$ @@ -78,26 +76,37 @@ setFieldUpdater(fieldUpdater); } + public CheckboxColumn(boolean multipleSelectionAllowed, FieldUpdater<T, Boolean> fieldUpdater) { + super(multipleSelectionAllowed ? new EnabledDisabledCheckboxCell() : new EnabledDisabledRadioCell()); + this.multipleSelectionAllowed = multipleSelectionAllowed; + setFieldUpdater(fieldUpdater); + } + @Override public void render(Context context, T object, SafeHtmlBuilder sb) { - Cell<Boolean> cell = getCell(); - if (cell instanceof EnabledDisabledCheckboxCell) { - if (isCentralized) { - sb.appendHtmlConstant("<div style='text-align: center'>"); //$NON-NLS-1$ - } + if (isCentralized) { + sb.appendHtmlConstant("<div style='text-align: center'>"); //$NON-NLS-1$ + } - ((EnabledDisabledCheckboxCell) cell).renderEditable(context, - getValue(object), - canEdit(object), - sb, - getDisabledMessage(object)); - - if (isCentralized) { - sb.appendHtmlConstant("</div>"); //$NON-NLS-1$ + if (!canEdit(object)) { + sb.append(multipleSelectionAllowed ? INPUT_CHECKBOX_DISABLED_PREFIX : INPUT_RADIO_DISABLED_PREFIX); + if (getValue(object)) { + sb.append(CHECKED_ATTR); } + String disabledMessage = getDisabledMessage(object); + if (disabledMessage != null && !disabledMessage.isEmpty()) { + sb.append(TITLE_ATTR_START); + sb.append(SafeHtmlUtils.fromString(disabledMessage)); + sb.append(TITLE_ATTR_END); + } + sb.append(TAG_CLOSE); } else { super.render(context, object, sb); } + + if (isCentralized) { + sb.appendHtmlConstant("</div>"); //$NON-NLS-1$ + } } protected abstract boolean canEdit(T object); diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/cluster/ClusterManageNetworkPopupView.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/cluster/ClusterManageNetworkPopupView.java index 5735d44..85465ca 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/cluster/ClusterManageNetworkPopupView.java +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/cluster/ClusterManageNetworkPopupView.java @@ -38,13 +38,17 @@ @UiField(provided = true) EntityModelCellTable<ClusterNetworkManageModel> networks; + private final ApplicationConstants constants; + private final ApplicationTemplates templates; + @Inject public ClusterManageNetworkPopupView(EventBus eventBus, ApplicationResources resources, ApplicationConstants constants, ApplicationTemplates templates) { super(eventBus, resources); + this.constants = constants; + this.templates = templates; this.networks = new EntityModelCellTable<ClusterNetworkManageModel>(SelectionMode.NONE, true); initWidget(ViewUiBinder.uiBinder.createAndBindUi(this)); - initEntityModelCellTable(constants, templates); } @SuppressWarnings("unchecked") @@ -59,6 +63,7 @@ void initEntityModelCellTable(final ApplicationConstants constants, final ApplicationTemplates templates) { networks.enableColumnResizing(); + boolean multipleSelectionAllowed = networks.asEditor().flush().isMultiCluster(); CheckboxHeader assignAllHeader = new CheckboxHeader(templates.textForCheckBoxHeader(constants.assignAll())) { @Override @@ -205,7 +210,8 @@ }, constants.vmNetwork(), "80px"); //$NON-NLS-1$ - networks.addColumn(new CheckboxColumn<EntityModel>(new FieldUpdater<EntityModel, Boolean>() { + networks.addColumn(new CheckboxColumn<EntityModel>(multipleSelectionAllowed, + new FieldUpdater<EntityModel, Boolean>() { @Override public void update(int index, EntityModel model, Boolean value) { ClusterNetworkModel clusterNetworkManageModel = (ClusterNetworkModel) model; @@ -226,7 +232,8 @@ } }, constants.displayNetwork(), "100px"); //$NON-NLS-1$ - networks.addColumn(new CheckboxColumn<EntityModel>(new FieldUpdater<EntityModel, Boolean>() { + networks.addColumn(new CheckboxColumn<EntityModel>(multipleSelectionAllowed, + new FieldUpdater<EntityModel, Boolean>() { @Override public void update(int index, EntityModel model, Boolean value) { ClusterNetworkModel clusterNetworkManageModel = (ClusterNetworkModel) model; @@ -254,6 +261,7 @@ @Override public void edit(ClusterNetworkManageModel model) { networks.asEditor().edit(model); + initEntityModelCellTable(constants, templates); } @Override -- To view, visit http://gerrit.ovirt.org/22464 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6576b816c53e482b54d49877eaa04088aa9f5960 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.3 Gerrit-Owner: Lior Vernia <lver...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches