コード例 #1
0
  private CellTable<ShopItem> createResultTable() {
    CellTable<ShopItem> resultTable = new CellTable<ShopItem>();
    resultTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);

    dataProvider = new FilteredListDataProvider<ShopItem>(new ShopFilter());

    dataProvider.addDataDisplay(resultTable);
    updateTable();
    dataProvider.setFilter(filterString);

    Column<ShopItem, String> titleColumn =
        new Column<ShopItem, String>(new ClickableTextCell()) {
          @Override
          public String getValue(ShopItem object) {
            return object.getTitle();
          }
        };
    titleColumn.setFieldUpdater(
        new FieldUpdater<ShopItem, String>() {
          @Override
          public void update(int index, ShopItem object, String value) {
            if (object instanceof Movie) {
              MovieDetailView view = new MovieDetailView(layout, (Movie) object);
              view.initialize();
              view.show();
            } else if (object instanceof Series) {
              SeriesDetailView view = new SeriesDetailView(layout, (Series) object);
              view.initialize();
              view.show();
            }
          }
        });

    TextColumn<ShopItem> typeColumn =
        new TextColumn<ShopItem>() {
          @Override
          public String getValue(ShopItem object) {
            if (object instanceof Movie) {
              return "Movie";
            } else if (object instanceof Series) {
              return "Series";
            }
            return "";
          }
        };

    Column<ShopItem, SafeHtml> loanableColumn =
        new Column<ShopItem, SafeHtml>(new SafeHtmlCell()) {
          @Override
          public SafeHtml getValue(ShopItem object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            if (object.isLoanable()) {
              sb.appendHtmlConstant("<span style=\"color:green\">");
              sb.appendEscaped("available");
            } else {
              if (object.isLoaned()) {
                sb.appendHtmlConstant("<span style=\"color:blue\">");
                sb.appendEscaped("is loaned");

              } else {
                sb.appendHtmlConstant("<span style=\"color:red\">");
                sb.appendEscaped("not available");
              }
            }
            sb.appendHtmlConstant("</span>");
            return sb.toSafeHtml();
          }
        };

    resultTable.addColumn(titleColumn, "Title");
    resultTable.addColumn(typeColumn, "Type");
    resultTable.addColumn(loanableColumn, "Available");

    return resultTable;
  }
コード例 #2
0
 private void updateTable() {
   dataProvider.setList(resultsTableList);
   if (onlyLoanable) onlyLoanableButton.setText("show all");
   else onlyLoanableButton.setText("show only available");
 }