首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GWT CellList水平

GWT CellList水平
EN

Stack Overflow用户
提问于 2010-12-07 16:51:48
回答 5查看 1.2K关注 0票数 5

有人知道如何制作水平方向的CellList吗?如果可能,请使用UiBinder,但这不是必需的。

EN

回答 5

Stack Overflow用户

发布于 2014-08-29 20:13:30

遵循Thomas Broyer的建议on the google-web-toolkit groupHow to style GWT CellList?,我们可以向CellList构造函数注入一个新的CSS资源。

用于获取水平格式MyCellList.css的CSS

代码语言:javascript
复制
/* This file is based on the CSS for a GWT CellList:
 * https://gwt.googlesource.com/gwt/+/master/./user/src/com/google/gwt/user/cellview/client/CellList.css
 * The primary purpose is to arrange for the <div> elements that contain each cell to be laid out inline (horizontally).
 */

/* Using inline-block, following Thomas Broyer's recommendations (with link to justification) here:
 * https://groups.google.com/forum/#!topic/google-web-toolkit/rPfCO5H91Rk
 */
.cellListEvenItem {
    display: inline-block;
    padding: 5px;
}

.cellListOddItem {
    display: inline-block;
    padding: 5px;
}

像这样定义一个新资源:

代码语言:javascript
复制
public interface MyCellListResource extends CellList.Resources {
  public static MyCellListResource INSTANCE = GWT.create(MyCellListResource.class);
  interface MyCellListStyle extends CellList.Style {}

  @Override
  @Source({CellList.Style.DEFAULT_CSS, "MyCellList.css"})
  MyCellListStyle cellListStyle();
}

注入新样式,并将其传递给CellList的构造函数:

代码语言:javascript
复制
    MyCellListResource.INSTANCE.cellListStyle().ensureInjected();

    CellList<Fare> cellList = new CellList<Fare>(cell, MyCellListResource.INSTANCE);

请注意,新样式出现在CellList的默认样式之后的级联中,因此您只需将所需的修改放入MyCellList.css中。

票数 2
EN

Stack Overflow用户

发布于 2010-12-21 13:41:14

尝试重写CellList.renderRowValues方法。您必须能够创建水平演示模板。

票数 1
EN

Stack Overflow用户

发布于 2012-09-22 05:53:44

这个方法中有很多我不想重复的逻辑,但我的老生常谈的解决方案就是用span的div替换掉所有的div:

代码语言:javascript
复制
public class HorizontalCellList<T> extends CellList<T> {

  public HorizontalCellList(Cell<T> cell) {
    super(cell);
  }

  @Override
  protected void renderRowValues(
      SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel) {
    SafeHtmlBuilder filteredSB = new SafeHtmlBuilder();
    super.renderRowValues(filteredSB, values, start, selectionModel);
    SafeHtml safeHtml = filteredSB.toSafeHtml();
    String filtered = safeHtml.asString().replaceAll("<div", "<span").replaceAll("div>","span>");
    sb.append(SafeHtmlUtils.fromTrustedString(filtered));
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4374863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档