Greg Sheremeta has uploaded a new change for review.

Change subject: webadmin: added DecoratedPopupPanel tooltips to 
StyledImageResourceCell
......................................................................

webadmin: added DecoratedPopupPanel tooltips to StyledImageResourceCell

Changed StyledImageResourceCell to use a DecoratedPopupPanel for its tooptip
instead of plain HTML titles. This makes the tooltip in comment columns (and
other places) match the tooltip styles elsewhere in the application.

Change-Id: I843f7f3baec6abe1695116ae2dc0580d102887b7
Bug-Url: https://bugzilla.redhat.com/990429
Signed-off-by: Greg Sheremeta <[email protected]>
---
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/ElementAwareDecoratedPopupPanel.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/StyledImageResourceCell.java
2 files changed, 74 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/01/20201/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/ElementAwareDecoratedPopupPanel.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/ElementAwareDecoratedPopupPanel.java
new file mode 100644
index 0000000..79da8a2
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/ElementAwareDecoratedPopupPanel.java
@@ -0,0 +1,24 @@
+package org.ovirt.engine.ui.common.widget;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.DecoratedPopupPanel;
+
+/**
+ * DecoratedPopupPanel that can be positioned below and left-aligned with any 
Element.
+ * (Standard DecoratedPopupPanel only works with UIObjects.)
+ *
+ */
+public class ElementAwareDecoratedPopupPanel extends DecoratedPopupPanel {
+
+    public void showRelativeTo(final Element target) {
+        setPopupPositionAndShow(new PositionCallback() {
+            @Override
+            public void setPosition(int offsetWidth, int offsetHeight) {
+                int left = target.getAbsoluteLeft();
+                int top = target.getAbsoluteTop() + target.getOffsetHeight();
+
+                setPopupPosition(left, top);
+            }
+        });
+    }
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/StyledImageResourceCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/StyledImageResourceCell.java
index dbfdbc5..ae65028 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/StyledImageResourceCell.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/StyledImageResourceCell.java
@@ -1,25 +1,44 @@
 package org.ovirt.engine.ui.common.widget.table.column;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import org.ovirt.engine.ui.common.widget.ElementAwareDecoratedPopupPanel;
+
 import com.google.gwt.cell.client.ImageResourceCell;
+import com.google.gwt.cell.client.ValueUpdater;
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.BrowserEvents;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
+import com.google.gwt.user.client.ui.Label;
 
+/**
+ * ImageResourceCell that supports setting a style and displaying a tooltip in 
a
+ * DecoratedPopupPanel.
+ *
+ */
 public class StyledImageResourceCell extends ImageResourceCell {
 
     interface CellTemplate extends SafeHtmlTemplates {
-        @Template("<div title=\"{0}\" style=\"{1}\">{2}</div>")
-        SafeHtml imageContainer(String title, String style, SafeHtml 
imageHtml);
+        @Template("<div style=\"{0}\">{1}</div>")
+        SafeHtml imageContainer(String style, SafeHtml imageHtml);
     }
 
     private String style = "line-height: 100%; text-align: center; 
vertical-align: middle;"; //$NON-NLS-1$
     private String title = ""; //$NON-NLS-1$
 
     private static CellTemplate template;
+
+    private ElementAwareDecoratedPopupPanel titlePanel = new 
ElementAwareDecoratedPopupPanel();
+
+    private Set<String> consumedEvents;
 
     public StyledImageResourceCell() {
         super();
@@ -28,12 +47,21 @@
         if (template == null) {
             template = GWT.create(CellTemplate.class);
         }
+
+        consumedEvents = new HashSet<String>();
+        consumedEvents.add("mouseover"); //$NON-NLS-1$
+        consumedEvents.add("mouseout"); //$NON-NLS-1$
+    }
+
+    @Override
+    public Set<String> getConsumedEvents() {
+        return consumedEvents;
     }
 
     @Override
     public void render(Context context, ImageResource value, SafeHtmlBuilder 
sb) {
         if (value != null) {
-            sb.append(template.imageContainer(title, style,
+            sb.append(template.imageContainer(style,
                     
SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(value).getHTML())));
         }
     }
@@ -42,8 +70,27 @@
         this.style = style;
     }
 
+    /**
+     * Set the text for the tooltip that will show when this cell is hovered 
over.
+     * @param title
+     */
     public void setTitle(String title) {
         this.title = title != null ? title : ""; //$NON-NLS-1$
     }
 
+    @Override
+    public void onBrowserEvent(Context context, Element parent, ImageResource 
value,
+            NativeEvent event, ValueUpdater<ImageResource> valueUpdater) {
+
+        titlePanel.setWidget(new Label(title));
+        String eventType = event.getType();
+
+        if (BrowserEvents.MOUSEOVER.equals(eventType)) {
+            titlePanel.showRelativeTo(parent);
+        }
+        else if (BrowserEvents.MOUSEOUT.equals(eventType)) {
+            titlePanel.hide();
+        }
+    }
+
 }


-- 
To view, visit http://gerrit.ovirt.org/20201
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I843f7f3baec6abe1695116ae2dc0580d102887b7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Greg Sheremeta <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to