Greg Sheremeta has uploaded a new change for review.

Change subject: userportal, webadmin: cleanup cells -- use SafeHtmlTemplates
......................................................................

userportal, webadmin: cleanup cells -- use SafeHtmlTemplates

CLeaned up some Cells and VmTable to use SafeHtmlTemplates instead
of String-building HTML.

Change-Id: Iab169b1daf5974655f90bab47e8ee5286c4f2e51
Signed-off-by: Greg Sheremeta <gsher...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/AbstractImageButtonCell.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/LunSelectionCell.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/SafeHtmlCell.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/resources/VmTable.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/cell/CustomSelectionCell.java
5 files changed, 91 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/10/39110/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/AbstractImageButtonCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/AbstractImageButtonCell.java
index c2412ee..8939c3a 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/AbstractImageButtonCell.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/AbstractImageButtonCell.java
@@ -6,11 +6,13 @@
 import org.ovirt.engine.ui.uicommonweb.UICommand;
 
 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.EventTarget;
 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;
@@ -23,6 +25,13 @@
  *            The data type of the cell (the model)
  */
 public abstract class AbstractImageButtonCell<C> extends AbstractCell<C> {
+
+    interface CellTemplate extends SafeHtmlTemplates {
+        @Template("<span id=\"{0}\" style=\"vertical-align: 
middle;\">{1}</span>")
+        SafeHtml span(String id, SafeHtml imageHtml);
+    }
+
+    private static final CellTemplate templates = 
GWT.create(CellTemplate.class);
 
     private final SafeHtml imageHtml;
 
@@ -54,11 +63,7 @@
 
     @Override
     public void render(Context context, C value, SafeHtmlBuilder sb, String 
id) {
-        sb.appendHtmlConstant("<span id=\"" //$NON-NLS-1$
-                + id
-                + "\" style=\"vertical-align: middle;\">"); //$NON-NLS-1$
-        sb.append(imageHtml);
-        sb.appendHtmlConstant("</span>"); //$NON-NLS-1$
+        sb.append(templates.span(id, imageHtml));
     }
 
     /**
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/LunSelectionCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/LunSelectionCell.java
index cb78e47..9fc0e74 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/LunSelectionCell.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/LunSelectionCell.java
@@ -4,14 +4,36 @@
 import org.ovirt.engine.ui.common.gin.AssetProvider;
 import org.ovirt.engine.ui.uicommonweb.models.storage.LunModel;
 
+import com.google.gwt.core.client.GWT;
+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;
 
 /**
  * LunSelectionCell. Supports tooltips.
  *
  */
 public class LunSelectionCell extends AbstractCell<LunModel> {
+
+    interface CellTemplate extends SafeHtmlTemplates {
+
+        @Template("<span id=\"{0}\" style=\"padding-left: 1px;\">{1}</span>")
+        SafeHtml span(String id, SafeHtml html);
+
+        @Template("<input id=\"{0}\" tabindex='-1' type=\"{1}\" checked />")
+        SafeHtml inputChecked(String id, String type);
+
+        @Template("<input id=\"{0}\" tabindex='-1' type=\"{1}\" checked 
disabled />")
+        SafeHtml inputCheckedDisabled(String id, String type);
+
+        @Template("<input id=\"{0}\" tabindex='-1' type=\"{1}\" />")
+        SafeHtml inputUnchecked(String id, String type);
+
+        @Template("<input id=\"{0}\" tabindex='-1' type=\"{1}\" disabled />")
+        SafeHtml inputUncheckedDisabled(String id, String type);
+    }
+
+    private static final CellTemplate templates = 
GWT.create(CellTemplate.class);
 
     private boolean multiSelection;
 
@@ -36,16 +58,27 @@
             // ImageResourceCell sets the id
             imageCell.render(context, resources.logWarningImage(), sb, id);
         } else {
-            sb.append(SafeHtmlUtils.fromTrustedString("<span id=\"" + id + " 
style=\"padding-left: 1px;\">")); //$NON-NLS-1$ //$NON-NLS-2$
+            boolean checked = value.getIsSelected();
+            boolean disabled = value.getIsGrayedOut();
+            String inputId = id + "_input"; //$NON-NLS-1$
 
-            String type = multiSelection ? "type='checkbox' " : "type='radio' 
"; //$NON-NLS-1$ //$NON-NLS-2$
-            String checked = value.getIsSelected() ? "checked='checked' " : 
""; //$NON-NLS-1$ //$NON-NLS-2$
-            String disabled = value.getIsGrayedOut() ? "disabled='disabled' " 
: ""; //$NON-NLS-1$ //$NON-NLS-2$
-            // include the id
-            String input = "<input id=\"" + id + "_input" + "\" " + type + 
checked + disabled + " tabindex='-1'/>"; //$NON-NLS-1$ //$NON-NLS-2$ 
//$NON-NLS-3$ //$NON-NLS-4$
+            String type = multiSelection ? "checkbox" : "radio"; //$NON-NLS-1$ 
//$NON-NLS-2$
+            SafeHtml input = null;
 
-            sb.append(SafeHtmlUtils.fromTrustedString(input));
-            sb.append(SafeHtmlUtils.fromTrustedString("</span>")); 
//$NON-NLS-1$
+            if (checked && !disabled) {
+                input = templates.inputChecked(inputId, type);
+            }
+            else if (checked && disabled) {
+                input = templates.inputCheckedDisabled(inputId, type);
+            }
+            else if (!checked && !disabled) {
+                input = templates.inputUnchecked(inputId, type);
+            }
+            else {
+                input = templates.inputUncheckedDisabled(inputId, type);
+            }
+
+            sb.append(templates.span(id, input));
         }
     }
 
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/SafeHtmlCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/SafeHtmlCell.java
index 73e3a84..b50dceb 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/SafeHtmlCell.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/SafeHtmlCell.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.ui.common.widget.table.cell;
 
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.safehtml.client.SafeHtmlTemplates;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 
@@ -8,12 +10,17 @@
  */
 public class SafeHtmlCell extends AbstractCell<SafeHtml>  {
 
+    interface CellTemplate extends SafeHtmlTemplates {
+        @Template("<div id=\"{0}\" style='display:block'>{1}</div>")
+        SafeHtml div(String id, SafeHtml html);
+    }
+
+    private static final CellTemplate templates = 
GWT.create(CellTemplate.class);
+
     @Override
     public void render(Context context, SafeHtml value, SafeHtmlBuilder sb, 
String id) {
         if (value != null) {
-            sb.appendHtmlConstant("<div id=\"" + id + "\" 
style='display:block'>"); //$NON-NLS-1$ //$NON-NLS-2$
-            sb.append(value);
-            sb.appendHtmlConstant("</div>"); //$NON-NLS-1$
+            sb.append(templates.div(id, value));
         }
     }
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/resources/VmTable.java
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/resources/VmTable.java
index 869a7b3..2463806 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/resources/VmTable.java
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/resources/VmTable.java
@@ -4,6 +4,8 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
 import org.ovirt.engine.ui.common.SubTableResources;
 import org.ovirt.engine.ui.common.widget.HasEditorDriver;
 import org.ovirt.engine.ui.common.widget.editor.EntityModelCellTable;
@@ -29,6 +31,8 @@
 import com.google.gwt.event.logical.shared.OpenHandler;
 import com.google.gwt.event.shared.HandlerRegistration;
 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.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
@@ -39,9 +43,6 @@
 import com.google.gwt.user.client.ui.TreeItem;
 import com.google.gwt.user.client.ui.Widget;
 import com.google.gwt.view.client.SingleSelectionModel;
-
-import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
 
 public class VmTable extends Composite implements 
HasEditorDriver<ResourcesModel> {
 
@@ -463,6 +464,13 @@
 
 class StyledCompositeCell<T> extends CompositeCell<T> {
 
+    interface CellTemplate extends SafeHtmlTemplates {
+        @Template("<div id=\"{0}\" style=\"{1}\">")
+        SafeHtml div(String id, String style);
+    }
+
+    private static final CellTemplate templates = 
GWT.create(CellTemplate.class);
+
     private final List<HasCell<T, ?>> hasCells;
     private final StyledProvider<T> styleProvider;
 
@@ -475,12 +483,11 @@
     @Override
     public void render(Context context, T value, SafeHtmlBuilder sb, String 
id) {
         int i = 1;
-        // TODO use Template
         for (HasCell<T, ?> hasCell : hasCells) {
-            String style =
-                    styleProvider.styleStringOf(hasCell) == null ? "" : 
"style=\"" //$NON-NLS-1$ //$NON-NLS-2$
-                            + styleProvider.styleStringOf(hasCell) + "\""; 
//$NON-NLS-1$
-            sb.appendHtmlConstant("<div id=\"" + id + "_" + i + "\" " + style 
+ ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            String cellId = id + "_" + i; //$NON-NLS-1$
+            String style = styleProvider.styleStringOf(hasCell) == null ? "" : 
styleProvider.styleStringOf(hasCell); //$NON-NLS-1$
+
+            sb.append(templates.div(cellId, style));
             render(context, value, sb, hasCell);
             sb.appendHtmlConstant("</div>"); //$NON-NLS-1$
             i++;
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/cell/CustomSelectionCell.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/cell/CustomSelectionCell.java
index 99cc193..7320344 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/cell/CustomSelectionCell.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/table/cell/CustomSelectionCell.java
@@ -28,6 +28,12 @@
 
         @Template("<option value=\"{0}\" selected=\"selected\">{0}</option>")
         SafeHtml selected(String option);
+
+        @Template("<select id=\"{0}\" class=\"{1}\" tabindex=\"-1\" >")
+        SafeHtml selectEnabled(String id, String classNames);
+
+        @Template("<select id=\"{0}\" class=\"{1}\" tabindex=\"-1\" disabled>")
+        SafeHtml selectDisabled(String id, String classNames);
     }
 
     private static CellTemplate template;
@@ -96,9 +102,15 @@
             viewData = null;
         }
 
-        int selectedIndex = getSelectedIndex(value);
-        sb.appendHtmlConstant("<select id=\"" + id + "\" class='" + style + "' 
tabindex=\"-1\" " + (isEnabled ? "" : "disabled") + ">"); //$NON-NLS-1$ 
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+        if (isEnabled) {
+            sb.append(template.selectEnabled(id, style));
+        }
+        else {
+            sb.append(template.selectDisabled(id, style));
+        }
+
         int index = 0;
+        int selectedIndex = getSelectedIndex(value);
         for (String option : options) {
             if (index++ == selectedIndex) {
                 sb.append(template.selected(option));


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab169b1daf5974655f90bab47e8ee5286c4f2e51
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