Greg Sheremeta has uploaded a new change for review. Change subject: userportal, webadmin: cleanup ImageButtonCell ......................................................................
userportal, webadmin: cleanup ImageButtonCell Changed HTML generation in ImageButtonCell to use SafeHtmlTemplates. No functional changes -- just a refactor. Change-Id: Idb1ba16dc599eea5f8a5dc1876d3bbe7a8bf9577 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/ImageButtonCell.java 1 file changed, 14 insertions(+), 15 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/38730/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/ImageButtonCell.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/ImageButtonCell.java index 609d3d4..1cf9d96 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/ImageButtonCell.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/cell/ImageButtonCell.java @@ -3,11 +3,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; @@ -20,6 +22,13 @@ * The data type of the cell (the model) */ public abstract class ImageButtonCell<T> extends AbstractCell<T> { + + interface CellTemplate extends SafeHtmlTemplates { + @Template("<span id=\"{0}\" class=\"{1}\" title=\"{2}\">{3}</span>") + SafeHtml span(String id, String styleClass, String title, SafeHtml html); + } + + private static CellTemplate template = GWT.create(CellTemplate.class); private final SafeHtml enabledHtml; private final String enabledCss; @@ -53,21 +62,11 @@ @Override public void render(Context context, T value, SafeHtmlBuilder sb, String id) { - boolean isEnabled = isEnabled(value); - // TODO(vszocs) consider using SafeHtmlTemplates instead of building HTML manually - sb.appendHtmlConstant("<span id=\"" //$NON-NLS-1$ - + id - + "\" class=\"" //$NON-NLS-1$ - + (isEnabled ? enabledCss : disabledCss) - + "\" title=\"" //$NON-NLS-1$ - + SafeHtmlUtils.htmlEscape(getTitle(value)) - + "\">"); //$NON-NLS-1$ - if (isEnabled) { - sb.append(enabledHtml); - } else { - sb.append(disabledHtml); - } - sb.appendHtmlConstant("</span>"); //$NON-NLS-1$ + String css = isEnabled(value) ? enabledCss : disabledCss; + SafeHtml html = isEnabled(value) ? enabledHtml : disabledHtml; + String title = SafeHtmlUtils.htmlEscape(getTitle(value)); + + sb.append(template.span(id, css, title, html)); } /** -- To view, visit https://gerrit.ovirt.org/38730 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idb1ba16dc599eea5f8a5dc1876d3bbe7a8bf9577 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