GWT 单元列表水平

发布于 2024-10-06 13:11:03 字数 56 浏览 3 评论 0原文

有谁知道如何使 CellList 水平定向?如果可能的话,请使用UiBinder,但这不是必需的。

Does anybody know how to make a CellList oriented horizontally? If possible, please with UiBinder, but this is not necessary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

很糊涂小朋友 2024-10-13 13:11:03

遵循 Thomas Broyer google-web-toolkit 群组 和 如何设置 GWT CellList 样式?,我们可以注入一个新的 CSS 资源进入 CellList 构造函数。

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

/* 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;
}

定义一个新资源,如下所示:

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 的构造函数:

    MyCellListResource.INSTANCE.cellListStyle().ensureInjected();

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

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

Following Thomas Broyer's suggestion on the google-web-toolkit group, and How to style GWT CellList?, we can inject a new CSS resource into the CellList constructor.

The CSS for getting the horizonltal formatting MyCellList.css:

/* 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;
}

Define a new Resource like this:

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();
}

Inject the new style, and pass it CellList's constructor:

    MyCellListResource.INSTANCE.cellListStyle().ensureInjected();

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

Note that the new style appears in the cascade after the DEFAULT style for CellList, so you need only put the modifications you require into your MyCellList.css.

最偏执的依靠 2024-10-13 13:11:03

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

Try to override the CellList.renderRowValues method. You have to be able to create a horizontal presentation template.

老街孤人 2024-10-13 13:11:03

我不想重现该方法中有很多逻辑,但我用 span 替换所有 div 的黑客解决方案有效:

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));
  }
}

There is a lot of logic in that method I didn't want to reproduce, but my hacky solution of just replacing all div's with span's worked:

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));
  }
}
单身情人 2024-10-13 13:11:03

CSS 的变体 - 在单元格列表上设置 CSS 类名称

CellList<T> list = new CellList<T>(...);
list.addStyleName('myList');

,然后将 CSS 规则应用于单元格以使它们水平对齐:

.myList > div > div > div {
    display: inline;
}

A variant with CSS - set CSS class name on you cell list

CellList<T> list = new CellList<T>(...);
list.addStyleName('myList');

then apply CSS rule to the cells to make them align horizontally:

.myList > div > div > div {
    display: inline;
}
小梨窩很甜 2024-10-13 13:11:03

我可以通过扩展 CellList 并创建我自己的模板 + 覆盖 renderRowValues 方法来解决这个问题。简单地将 div 更改为 span 对我来说并没有什么效果,也许是因为我有自定义单元格(每个单元格都呈现为表格)。在 CSS 上添加 display:inline 对我来说也不起作用。

我的模板代码与原始代码几乎相同,除了我添加了“float:left;”样式:

    interface Template extends SafeHtmlTemplates {
    @Template("<div onclick=\"\" __idx=\"{0}\" style=\"float:left;\">{1}</div>")
    SafeHtml span(int idx, SafeHtml cellContents); ...

这是我的 renderRowValue 方法的片段:

    int length = values.size();
    int end = start + length;
    for (int i = start; i < end; i++) {
        SingleKeyValueModel value = values.get(i - start);

        //super.renderRowValues(sb, values, start, selectionModel);

        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        Context context = new Context(i, 0, getValueKey(value));
        cell.render(context, value, cellBuilder);


        sb.append(TEMPLATE.span(i, cellBuilder.toSafeHtml()));

    }

I'm able to solve this by extending CellList and creating my own template + overriding the renderRowValues method. Simply changing divs into spans didn't do the trick for me maybe it was because I have custom cells (each cell is rendered as table). Adding display:inline on the CSS didn't work for me also.

My template code is pretty much the same as the original except I added the "float:left;" style:

    interface Template extends SafeHtmlTemplates {
    @Template("<div onclick=\"\" __idx=\"{0}\" style=\"float:left;\">{1}</div>")
    SafeHtml span(int idx, SafeHtml cellContents); ...

Here's a snippet of my renderRowValue method:

    int length = values.size();
    int end = start + length;
    for (int i = start; i < end; i++) {
        SingleKeyValueModel value = values.get(i - start);

        //super.renderRowValues(sb, values, start, selectionModel);

        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        Context context = new Context(i, 0, getValueKey(value));
        cell.render(context, value, cellBuilder);


        sb.append(TEMPLATE.span(i, cellBuilder.toSafeHtml()));

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文