Esempio n. 1
0
  public CommandListView() {
    super(new MenuItem(N3phele.n3pheleResource.commandIcon(), "Commands", null));
    cellTable = new CellTable<Command>();
    cellTable.setSize("455px", "");

    Column<Command, Hyperlink> nameColumn =
        new Column<Command, Hyperlink>(new HyperlinkCell()) {

          @Override
          public Hyperlink getValue(Command command) {
            if (command == null) return null;
            String name = command.getName();
            String historyToken = commandActivity.getToken(command);
            return new Hyperlink(name, historyToken);
          }
        };

    cellTable.addColumn(nameColumn, "Name");

    TextColumn<Command> descriptionColumn =
        new TextColumn<Command>() {
          @Override
          public String getValue(Command command) {
            String result = "";
            if (command != null) return command.getDescription();
            return result;
          }
        };
    cellTable.addColumn(descriptionColumn, "Description");
    //		 // Add a selection model to handle user selection.
    //	    final SingleSelectionModel<Command> selectionModel = new SingleSelectionModel<Command>();
    //	    cellTable.setSelectionModel(selectionModel);
    //	    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
    //	      public void onSelectionChange(SelectionChangeEvent event) {
    //	        Command selected = selectionModel.getSelectedObject();
    //	        if (selected != null) {
    //	          if(commandActivity != null) {
    //	        	 commandActivity.onSelect(selected);
    //	          }
    //	        }
    //	      }
    //	    });

    cellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    this.add(cellTable);
  }
  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;
  }