@Test
  public void serverSideSelection_GridChangingSelectionModel_sendsUpdatedRowsToClient() {

    CustomSingleSelectionModel customModel = new CustomSingleSelectionModel();
    Grid<String> customGrid =
        new Grid<String>() {
          {
            setSelectionModel(customModel);
          }
        };
    customGrid.setItems("Foo", "Bar", "Baz");

    customGrid.getDataCommunicator().beforeClientResponse(true);

    Assert.assertFalse(
        "Item should have been updated as selected", customModel.generatedData.get("Foo"));
    Assert.assertFalse(
        "Item should have been updated as NOT selected", customModel.generatedData.get("Bar"));
    Assert.assertFalse(
        "Item should have been updated as NOT selected", customModel.generatedData.get("Baz"));

    customModel.generatedData.clear();

    customGrid.getSelectionModel().select("Foo");
    customGrid.getDataCommunicator().beforeClientResponse(false);

    Assert.assertTrue(
        "Item should have been updated as selected", customModel.generatedData.get("Foo"));
    Assert.assertFalse(
        "Item should have NOT been updated", customModel.generatedData.containsKey("Bar"));
    Assert.assertFalse(
        "Item should have NOT been updated", customModel.generatedData.containsKey("Baz"));

    // switch to another selection model to cause event
    customModel.generatedData.clear();
    customGrid.setSelectionMode(SelectionMode.MULTI);
    customGrid.getDataCommunicator().beforeClientResponse(false);

    // since the selection model has been removed, it is no longer a data
    // generator for the data communicator, would need to verify somehow
    // that row is not marked as selected anymore ? (done in UI tests)
    Assert.assertTrue(customModel.generatedData.isEmpty()); // at least
    // removed
    // selection
    // model is not
    // triggered
  }
Beispiel #2
0
  /**
   * Creates a new clickable renderer with the given presentation type and null representation.
   *
   * @param presentationType the data type that this renderer displays, not <code>null</code>
   * @param nullRepresentation a string that will be sent to the client instead of a regular value
   *     in case the actual cell value is <code>null</code>. May be <code>null</code>.
   */
  protected ClickableRenderer(Class<V> presentationType, String nullRepresentation) {
    super(presentationType, nullRepresentation);
    registerRpc(
        (RendererClickRpc)
            (String rowKey, String columnId, MouseEventDetails mouseDetails) -> {
              Grid<T> grid = getParentGrid();
              T item = grid.getDataCommunicator().getKeyMapper().get(rowKey);
              Column column = grid.getColumn(columnId);

              fireEvent(new RendererClickEvent<>(grid, item, column, mouseDetails));
            });
  }