Alona Kaplan has uploaded a new change for review.

Change subject: webadmin: adding label tag to Host->Interface subtab
......................................................................

webadmin: adding label tag to Host->Interface subtab

If there is a label on the interface/bond there will be a label tag next to
its name.
On mouse over there will be a tooltip with all the labels on the interface/
bond.

Change-Id: I997d85d894d79f14402157fcc51a0cdbfe2ff056
Bug-Url: https://bugzilla.redhat.com/10638021
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/host/SubTabHostInterfaceView.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/BondPanel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/HostInterfaceForm.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/InterfacePanel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/label/LabelWithToolTip.java
5 files changed, 83 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/98/27898/1

diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/host/SubTabHostInterfaceView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/host/SubTabHostInterfaceView.java
index c870593..b8a5063 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/host/SubTabHostInterfaceView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/host/SubTabHostInterfaceView.java
@@ -63,10 +63,8 @@
                         clientStorage);
         ViewIdHandler.idHandler.generateAndSetIds(this);
         initTable(constants, templates);
-        table.setWidth("100%", false); //$NON-NLS-1$
 
         contentPanel = new VerticalPanel();
-        contentPanel.setWidth("100%"); //$NON-NLS-1$
         contentPanel.add(table);
         contentPanel.add(new Label(constants.emptyInterface()));
         initWidget(contentPanel);
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/BondPanel.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/BondPanel.java
index 07e15af..c91a848 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/BondPanel.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/BondPanel.java
@@ -27,19 +27,24 @@
         style.setBorderStyle(BorderStyle.SOLID);
 
         if (lineModel.getIsBonded()) {
-            if (isSelectionEnabled){
+            if (isSelectionEnabled) {
                 add(getCheckBox());
+                setCellWidth(getCheckBox(), "12%"); //$NON-NLS-1$
             }
 
             // Bond icon
+            Image bondIcon;
             if 
(InterfaceStatus.UP.equals(lineModel.getInterface().getStatistics().getStatus()))
 {
-                add(new 
Image(ClientGinjectorProvider.getApplicationResources().splitUpImage()));
+                bondIcon = new 
Image(ClientGinjectorProvider.getApplicationResources().splitUpImage());
             } else {
-                add(new 
Image(ClientGinjectorProvider.getApplicationResources().splitDownImage()));
+                bondIcon = new 
Image(ClientGinjectorProvider.getApplicationResources().splitDownImage());
             }
 
+            add(bondIcon);
+            setCellWidth(bondIcon, "20%"); //$NON-NLS-1$
+
             // Bond name
-            add(new Label(lineModel.getBondName()));
+            
add(HostInterfaceForm.createInterfaceLabel(lineModel.getInterface()));
         } else {
             add(new Label("")); //$NON-NLS-1$
         }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/HostInterfaceForm.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/HostInterfaceForm.java
index 4aaecda..379e8e0 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/HostInterfaceForm.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/HostInterfaceForm.java
@@ -1,14 +1,24 @@
 package org.ovirt.engine.ui.webadmin.widget.host;
 
 import java.util.List;
+import java.util.Set;
 
+import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.ui.uicommonweb.models.hosts.HostInterfaceLineModel;
 import org.ovirt.engine.ui.uicommonweb.models.hosts.HostInterfaceListModel;
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.IEventListener;
 import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
+import org.ovirt.engine.ui.webadmin.ApplicationResources;
+import org.ovirt.engine.ui.webadmin.ApplicationTemplates;
+import org.ovirt.engine.ui.webadmin.widget.label.LabelWithToolTip;
 
+import com.google.gwt.core.client.GWT;
+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.Composite;
 import com.google.gwt.user.client.ui.Grid;
 import com.google.gwt.user.client.ui.Widget;
@@ -17,6 +27,11 @@
 
     private final Grid grid;
     private boolean isSelectionAvailable;
+
+    private final static ApplicationResources resources = 
GWT.create(ApplicationResources.class);
+    private final static ApplicationTemplates templates = 
GWT.create(ApplicationTemplates.class);
+    private final static SafeHtml labelImage =
+            
SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(resources.tagImage()).getHTML());;
 
     @SuppressWarnings("unchecked")
     public HostInterfaceForm(final HostInterfaceListModel listModel) {
@@ -51,7 +66,7 @@
                 if ("isSelectionAvailable".equals(propName)) { //$NON-NLS-1$
                     isSelectionAvailable = listModel.getIsSelectionAvailable();
 
-                    if (listModel.getItems()!=null){
+                    if (listModel.getItems() != null) {
                         showModels((List<HostInterfaceLineModel>) 
listModel.getItems());
                     }
                 }
@@ -109,4 +124,37 @@
         grid.getCellFormatter().setHeight(row, col, "100%"); //$NON-NLS-1$
     }
 
+    static LabelWithToolTip createInterfaceLabel(VdsNetworkInterface iface) {
+        boolean hasLabels = iface.getLabels() != null
+                && !iface.getLabels().isEmpty();
+        LabelWithToolTip interfaceNameWithLabel =
+                new LabelWithToolTip(hasLabels ? 
templates.textImageLabels(iface.getName(), labelImage)
+                        : SafeHtmlUtils.fromString(iface.getName()));
+
+        interfaceNameWithLabel.setTitle(createLabelToolTip(iface.getLabels()));
+
+        return interfaceNameWithLabel;
+    }
+
+    private static SafeHtml createLabelToolTip(Set<String> labels) {
+        SafeHtmlBuilder tooltip = new SafeHtmlBuilder(); //$NON-NLS-1$
+        boolean isFirst = true;
+
+        if (labels == null) {
+            return null;
+        }
+
+        for (String label : labels) {
+            if (isFirst) {
+                isFirst = false;
+            } else {
+                tooltip = tooltip.appendHtmlConstant("<BR>"); //$NON-NLS-1$
+            }
+
+            tooltip = tooltip.appendEscaped(label);
+        }
+
+        return tooltip.toSafeHtml();
+    }
+
 }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/InterfacePanel.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/InterfacePanel.java
index 6ba130f..daad0d3 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/InterfacePanel.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/host/InterfacePanel.java
@@ -8,9 +8,8 @@
 import com.google.gwt.dom.client.Style;
 import com.google.gwt.dom.client.Style.BorderStyle;
 import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.Grid;
-import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.VerticalPanel;
 
 public class InterfacePanel extends VerticalPanel {
@@ -53,7 +52,7 @@
         row.getColumnFormatter().setWidth(1, "210px"); //$NON-NLS-1$
 
         // Check box and interface status icon
-        row.setWidget(0, 0, new FlowPanel() {
+        row.setWidget(0, 0, new HorizontalPanel() {
             {
                 if (isSelectionAvailable) {
                     add(getCheckBox());
@@ -64,7 +63,7 @@
         });
 
         // Name
-        row.setWidget(0, 1, new Label(hostInterface.getName()));
+        row.setWidget(0, 1, 
HostInterfaceForm.createInterfaceLabel(hostInterface.getInterface()));
 
         return row;
     }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/label/LabelWithToolTip.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/label/LabelWithToolTip.java
index 50549d9..28dd3f7 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/label/LabelWithToolTip.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/label/LabelWithToolTip.java
@@ -1,29 +1,41 @@
 package org.ovirt.engine.ui.webadmin.widget.label;
 
+import org.ovirt.engine.ui.uicompat.external.StringUtils;
+
 import com.google.gwt.event.dom.client.MouseOutEvent;
 import com.google.gwt.event.dom.client.MouseOutHandler;
 import com.google.gwt.event.dom.client.MouseOverEvent;
 import com.google.gwt.event.dom.client.MouseOverHandler;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.user.client.ui.DecoratedPopupPanel;
 import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Label;
 
-public class LabelWithToolTip extends Label {
+public class LabelWithToolTip extends HTML {
 
     private final HTML tooltip = new HTML();
     private final DecoratedPopupPanel tooltipPanel = new DecoratedPopupPanel();
-    private String title;
+    private SafeHtml title;
 
     public LabelWithToolTip() {
-        this("", -1); //$NON-NLS-1$
+        this("");
     }
 
     public LabelWithToolTip(String text, int length) {
-        super(text);
+        this(text);
 
         if (length > -1 && text.length() > length) {
             setText(text.substring(0, length - 3) + "..."); //$NON-NLS-1$
         }
+    }
+
+    public LabelWithToolTip(String text) {
+        this(SafeHtmlUtils.fromTrustedString(text));
+    }
+
+    public LabelWithToolTip(SafeHtml text) {
+        super(text);
+
         tooltipPanel.setWidget(tooltip);
         tooltipPanel.getElement().getStyle().setZIndex(1);
         setTitle(text);
@@ -35,7 +47,7 @@
 
             @Override
             public void onMouseOver(MouseOverEvent event) {
-                if(!"".equals(title)){ //$NON-NLS-1$
+                if (title != null && StringUtils.isNotEmpty(title.asString())) 
{
                     tooltip.setHTML(title);
                     tooltipPanel.showRelativeTo(LabelWithToolTip.this);
                 }
@@ -50,12 +62,12 @@
         });
     }
 
-    public LabelWithToolTip(String text) {
-        this(text, -1);
-    }
-
     @Override
     public void setTitle(String text) {
+        this.title = SafeHtmlUtils.fromTrustedString(text);
+    }
+
+    public void setTitle(SafeHtml text) {
         this.title = text;
     }
 }


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

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

Reply via email to