Greg Sheremeta has uploaded a new change for review.

Change subject: userportal, webadmin: show tooltips on cropped input boxes
......................................................................

userportal, webadmin: show tooltips on cropped input boxes

In General tabs and a few other places, input text boxes are
used as labels. When the text is longer than the text box width,
we want a tooltip with the full value to pop up.

The full value is still available by clicking on the 'label' and
horizontally scrolling.

Change-Id: Ie6713b4aa624948477e295db0a95f24fbf251ca4
Bug-Url: https://bugzilla.redhat.com/1205309
Signed-off-by: Greg Sheremeta <gsher...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ElementUtils.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/label/TextBoxLabelBase.java
2 files changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/21/39121/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ElementUtils.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ElementUtils.java
index 2339472..84701e9 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ElementUtils.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/ElementUtils.java
@@ -37,6 +37,40 @@
     }
 
     /**
+     * Detect if the text in an input box is not fully shown, i.e. the input 
box is smaller
+     * than the text inside it.
+     *
+     * This works by copying the text from an Element (input type=text) into a 
span, and detecting
+     * if the span is wider than the input box is.
+     *
+     * @see http://stackoverflow.com/questions/4834445
+     *
+     * @param element the input[type=text] we're checking
+     * @return if the text doesn't fit in the input box
+     */
+    public static native boolean detectOverflowUsingPixelWidth(Element element)
+    /*-{
+        var $element = $wnd.jQuery(element);
+        var $span = $wnd.jQuery('<span>' + $element.val() + '</span>');
+        $span.css({
+            position: 'absolute',
+            left: -9999,
+            top: -9999,
+            'font-family': $element.css('font-family'),
+            'font-size': $element.css('font-size'),
+            'font-weight': $element.css('font-weight'),
+            'font-style': $element.css('font-style')
+        });
+        $wnd.jQuery('body').append($span);
+        var result = $span.width() >= $element.width();
+        console.log($element);
+        console.log($span.width());
+        console.log($element.width());
+        $span.remove();
+        return result;
+    }-*/;
+
+    /**
      * Check up this Element's ancestor tree, and return true if we find a 
null parent.
      * @return true if a null parent is found, false if this Element has body 
as an ancestor
      * (meaning it's still attached).
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/label/TextBoxLabelBase.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/label/TextBoxLabelBase.java
index 7185918..23ecd4a 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/label/TextBoxLabelBase.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/label/TextBoxLabelBase.java
@@ -2,13 +2,21 @@
 
 import java.text.ParseException;
 
+import org.ovirt.engine.ui.common.utils.ElementUtils;
+import org.ovirt.engine.ui.common.widget.tooltip.WidgetTooltip;
+
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.event.dom.client.MouseDownEvent;
 import com.google.gwt.event.dom.client.MouseDownHandler;
+import com.google.gwt.event.logical.shared.ResizeEvent;
+import com.google.gwt.event.logical.shared.ResizeHandler;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.text.shared.Parser;
 import com.google.gwt.text.shared.Renderer;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.ValueBoxBase;
 
 /**
@@ -27,12 +35,14 @@
 public abstract class TextBoxLabelBase<T> extends ValueBoxBase<T> {
 
     private T value;
+    private WidgetTooltip tooltip;;
 
     private TextBoxLabelBase(Renderer<T> renderer, Parser<T> parser) {
         super(Document.get().createTextInputElement(), renderer, parser);
         setReadOnly(true);
         initStyles();
         addHandlers();
+        tooltip = new WidgetTooltip(this);
     }
 
     @SuppressWarnings("unchecked")
@@ -55,6 +65,18 @@
     @Override
     public void setText(String text) {
         super.setText(text);
+        setTooltip(SafeHtmlUtils.fromString(text));
+    }
+
+    protected void setTooltip(SafeHtml tooltipText) {
+        if (ElementUtils.detectOverflowUsingPixelWidth(getElement())) {
+            tooltip.setHtml(tooltipText);
+            tooltip.reconfigure();
+        }
+        else {
+            tooltip.setHtml(null);
+            tooltip.reconfigure();
+        }
     }
 
     @Override
@@ -79,5 +101,13 @@
                 }
             }
         }, MouseDownEvent.getType());
+
+        Window.addResizeHandler(new ResizeHandler() {
+            @Override
+            public void onResize(ResizeEvent event) {
+                setTooltip(SafeHtmlUtils.fromString(getText()));
+            }
+        });
+
     }
 }


-- 
To view, visit https://gerrit.ovirt.org/39121
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6713b4aa624948477e295db0a95f24fbf251ca4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Greg Sheremeta <gsher...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to