Tomas Jelinek has uploaded a new change for review. Change subject: webadmin,userportal: [WIP] change suggest box event handling ......................................................................
webadmin,userportal: [WIP] change suggest box event handling The problem was that the ListModelTypeAheadListBox could be closed only by either selecting one of the values or clicking somewhere outside of it, but not by clicking inside it again or clicking to the drop down triangle. Fixed by disabling the auto-hide feature of the suggest box and handling this events by hand. The handler methods are colocated in VisibilityHandlingEventHandlers class. The most hacky part is the mouseDownOnDropDownImage field. The reason this field is needed is that it is important to handle the hiding of the suggestions only onece (otherwise first they would be hidden by mouse down and second by blur). This events are called in order: onMouseDown onBlur onMouseUp makeing the onBlur bordered between the mouse events and enabled/disabled. using the mouseDownOnDropDownImage field. Change-Id: Ib73fa0160ea1a80246bb8e9cc9a6052fad63f1fe Bug-Url: https://bugzilla.redhat.com/987845 Signed-off-by: Tomas Jelinek <[email protected]> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java 2 files changed, 85 insertions(+), 42 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/17327/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java index 9546343..87626a1 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/BaseListModelSuggestBox.java @@ -52,6 +52,10 @@ suggestionDisplay.hide(); } + protected boolean isSuggestionListShowing() { + return suggestionDisplay.isSuggestionListShowing(); + } + @Override public TakesConstrainedValueEditor<T> asEditor() { if (editor == null) { @@ -95,7 +99,7 @@ @Override public void setFocus(boolean focused) { - asSuggestBox().setFocus(focused); + asSuggestBox().getValueBox().setFocus(focused); } @Override @@ -120,6 +124,10 @@ public void setValue(T value, boolean fireEvents) { this.value = value; render(value, fireEvents); + } + + public void setAutoHideEnabled(boolean enabled) { + suggestionDisplay.setAutoHideEnabled(enabled); } /** @@ -171,5 +179,9 @@ public void hide() { getPopupPanel().hide(); } + + public void setAutoHideEnabled(boolean enabled) { + getPopupPanel().setAutoHideEnabled(enabled); + } } } diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java index 0ff2ef8..4ee74b3 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/editor/ListModelTypeAheadListBox.java @@ -1,5 +1,10 @@ package org.ovirt.engine.ui.common.widget.editor; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.event.dom.client.MouseDownEvent; +import com.google.gwt.event.dom.client.MouseDownHandler; +import com.google.gwt.event.dom.client.MouseUpEvent; +import com.google.gwt.event.dom.client.MouseUpHandler; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -70,64 +75,48 @@ this.renderer = renderer; suggestBox = asSuggestBox(); + + // this needs to be handled by focus on text box and clicks on drop down image + setAutoHideEnabled(false); initWidget(ViewUiBinder.uiBinder.createAndBindUi(this)); registerListeners(); } private void registerListeners() { - dropDownImage.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - showAllSuggestions(); - } - }); + VisibilityHandlingEventHandlers handlers = new VisibilityHandlingEventHandlers(); + suggestBox.getValueBox().addBlurHandler(handlers); + suggestBox.getValueBox().addFocusHandler(handlers); // not listening to focus because it would show the suggestions also after the whole browser // gets the focus back (after loosing it) if this was the last element with focus - suggestBox.getTextBox().addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - showAllSuggestions(); - } - }); + suggestBox.getValueBox().addClickHandler(handlers); - // make sure that after leaving the text box a valid value or empty value will be rendered in the text box - suggestBox.getTextBox().addBlurHandler(new BlurHandler() { - - @Override - public void onBlur(BlurEvent event) { - if (eventHandler != null) { - eventHandler.removeHandler(); - } - - adjustSelectedValue(); - } - - }); - - suggestBox.getTextBox().addFocusHandler(new FocusHandler() { - - @Override - public void onFocus(FocusEvent event) { - eventHandler = - Event.addNativePreviewHandler(new EnterIgnoringNativePreviewHandler<T>(ListModelTypeAheadListBox.this)); - } - }); + dropDownImage.addMouseDownHandler(handlers); + dropDownImage.addMouseUpHandler(handlers); } - private void showAllSuggestions() { + private void switchSuggestions() { if (!isEnabled()) { return; } - // show all the suggestions even if there is already something filled - // otherwise it is not obvious that there are more options - suggestBox.setText(null); - suggestBox.showSuggestionList(); - setFocus(true); + if (isSuggestionListShowing()) { + hideSuggestions(); + adjustSelectedValue(); + } else { + // show all the suggestions even if there is already something filled + // otherwise it is not obvious that there are more options + suggestBox.setText(null); + suggestBox.showSuggestionList(); + + Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { + public void execute () { + setFocus(true); + } + }); + } } private void adjustSelectedValue() { @@ -236,6 +225,48 @@ mainPanel.getElement().replaceClassName(style.enabledMainPanel(), style.disabledMainPanel()); } } + + class VisibilityHandlingEventHandlers implements FocusHandler, BlurHandler, MouseDownHandler, MouseUpHandler, ClickHandler { + + private boolean mouseDownOnDropDownImage = false; + + @Override + public void onMouseDown(MouseDownEvent mouseDownEvent) { + mouseDownOnDropDownImage = true; + switchSuggestions(); + } + + // make sure that after leaving the text box a valid value or empty value will be rendered in the text box + @Override + public void onBlur(BlurEvent blurEvent) { + if (eventHandler != null) { + eventHandler.removeHandler(); + } + + // process only if it will not be processed by the drop down + if (!mouseDownOnDropDownImage) { + hideSuggestions(); + adjustSelectedValue(); + } + + } + + @Override + public void onMouseUp(MouseUpEvent mouseUpEvent) { + mouseDownOnDropDownImage = false; + } + + @Override + public void onFocus(FocusEvent event) { + eventHandler = + Event.addNativePreviewHandler(new EnterIgnoringNativePreviewHandler<T>(ListModelTypeAheadListBox.this)); + } + + @Override + public void onClick(ClickEvent event) { + switchSuggestions(); + } + } } class RenderableSuggestion<T> extends MultiWordSuggestion { -- To view, visit http://gerrit.ovirt.org/17327 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib73fa0160ea1a80246bb8e9cc9a6052fad63f1fe Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tomas Jelinek <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
