Lior Vernia has uploaded a new change for review. Change subject: webadmin: Render widgets more responsive in a generic way ......................................................................
webadmin: Render widgets more responsive in a generic way Several widgets have implemented "increased responsiveness" - firing value change events whenever a key is pressed - independently, while using similar logic. This patch aims to implement it higher up in the widget hierarchy, so that this responsiveness could be "turned on" by a simple method invocation. Change-Id: Iedad481e878e1a9122d6efec0339bf3ffa4d36ca Signed-off-by: Lior Vernia <[email protected]> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AbstractValidatedWidgetWithLabel.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/AbstractValueBoxWithLabelEditor.java M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/provider/DnsServerEditor.java M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.java 4 files changed, 32 insertions(+), 32 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/53/29453/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AbstractValidatedWidgetWithLabel.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AbstractValidatedWidgetWithLabel.java index b22aac0..fa615b4 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AbstractValidatedWidgetWithLabel.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AbstractValidatedWidgetWithLabel.java @@ -6,17 +6,23 @@ import org.ovirt.engine.ui.common.widget.editor.EditorWidget; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.LabelElement; import com.google.gwt.event.dom.client.HasAllKeyHandlers; +import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.dom.client.KeyPressHandler; import com.google.gwt.event.dom.client.KeyUpHandler; +import com.google.gwt.event.logical.shared.HasValueChangeHandlers; +import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.resources.client.CssResource; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.TakesValue; import com.google.gwt.user.client.ui.Focusable; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.SimplePanel; @@ -27,7 +33,7 @@ * @param <W> * Content widget type. */ -public abstract class AbstractValidatedWidgetWithLabel<T, W extends EditorWidget<T, ?>> extends AbstractValidatedWidget +public abstract class AbstractValidatedWidgetWithLabel<T, W extends EditorWidget<T, ?> & TakesValue<T> & HasValueChangeHandlers<T>> extends AbstractValidatedWidget implements HasLabel, HasEnabledWithHints, HasAccess, HasAllKeyHandlers, HasElementId, Focusable, FocusableComponentsContainer { interface WidgetUiBinder extends UiBinder<Widget, AbstractValidatedWidgetWithLabel<?, ?>> { @@ -124,6 +130,26 @@ } } + /** + * Render widget more responsive, by firing {@link ValueChangeEvent} on each {@link KeyDownEvent}. + */ + public void fireValueChangeOnKeyDown() { + getContentWidget().addKeyDownHandler(new KeyDownHandler() { + + @Override + public void onKeyDown(KeyDownEvent event) { + // deferring is required to allow the widget's internal value to update according to key press + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + + @Override + public void execute() { + ValueChangeEvent.fire(getContentWidget(), getContentWidget().getValue()); + } + }); + } + }); + } + protected W getContentWidget() { return contentWidget; } diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/AbstractValueBoxWithLabelEditor.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/AbstractValueBoxWithLabelEditor.java index 1b01d5e..e42da82 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/AbstractValueBoxWithLabelEditor.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/AbstractValueBoxWithLabelEditor.java @@ -5,6 +5,8 @@ import com.google.gwt.editor.client.IsEditor; import com.google.gwt.editor.ui.client.adapters.ValueBoxEditor; +import com.google.gwt.event.logical.shared.HasValueChangeHandlers; +import com.google.gwt.user.client.TakesValue; /** * Base class for composite Editors that use text input widget with a label. @@ -14,7 +16,7 @@ * @param <W> * Text input widget type. */ -public abstract class AbstractValueBoxWithLabelEditor<T, W extends EditorWidget<T, ValueBoxEditor<T>>> extends AbstractValidatedWidgetWithLabel<T, W> +public abstract class AbstractValueBoxWithLabelEditor<T, W extends EditorWidget<T, ValueBoxEditor<T>> & TakesValue<T> & HasValueChangeHandlers<T>> extends AbstractValidatedWidgetWithLabel<T, W> implements IsEditor<WidgetWithLabelEditor<T, AbstractValueBoxWithLabelEditor<T, W>>> { private final WidgetWithLabelEditor<T, AbstractValueBoxWithLabelEditor<T, W>> editor; diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/provider/DnsServerEditor.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/provider/DnsServerEditor.java index ddcad6f..5570515 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/provider/DnsServerEditor.java +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/provider/DnsServerEditor.java @@ -4,13 +4,9 @@ import org.ovirt.engine.ui.common.widget.uicommon.popup.AbstractModelBoundPopupWidget; import org.ovirt.engine.ui.uicommonweb.models.EntityModel; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.editor.client.SimpleBeanEditorDriver; -import com.google.gwt.event.dom.client.KeyPressEvent; -import com.google.gwt.event.dom.client.KeyPressHandler; import com.google.gwt.event.logical.shared.HasValueChangeHandlers; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; @@ -37,17 +33,7 @@ @Override public void edit(final EntityModel<String> model) { driver.edit(model); - stringEditor.addKeyPressHandler(new KeyPressHandler() { - @Override - public void onKeyPress(KeyPressEvent event) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - ValueChangeEvent.fire(stringEditor.asValueBox(), stringEditor.asValueBox().getValue()); - } - }); - } - }); + stringEditor.fireValueChangeOnKeyDown(); stringEditor.asValueBox().addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.java index c366f06..06a9880 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.java +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.java @@ -16,11 +16,7 @@ import org.ovirt.engine.ui.common.widget.Align; import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.editor.client.SimpleBeanEditorDriver; -import com.google.gwt.event.dom.client.KeyPressEvent; -import com.google.gwt.event.dom.client.KeyPressHandler; import com.google.gwt.event.logical.shared.HasValueChangeHandlers; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; @@ -97,17 +93,7 @@ public void edit(final VnicProfileModel model) { driver.edit(model); publicInfo.setVisible(model.getPublicUse().getIsAvailable()); - nameEditor.addKeyPressHandler(new KeyPressHandler() { - @Override - public void onKeyPress(KeyPressEvent event) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - ValueChangeEvent.fire(nameEditor.asValueBox(), nameEditor.asValueBox().getValue()); - } - }); - } - }); + nameEditor.fireValueChangeOnKeyDown(); nameEditor.asValueBox().addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { -- To view, visit http://gerrit.ovirt.org/29453 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iedad481e878e1a9122d6efec0339bf3ffa4d36ca Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
