@Test public void setIdentifierProvider_customIdentifier_keyMapperUsesIdentifier() { Item first = new Item(1L, "first"); Item second = new Item(2L, "middle"); List<Item> items = new ArrayList<>(Arrays.asList(first, second)); Grid<Item> component = new Grid<>(); DataProvider<Item, Void> dataProvider = new DataProvider<Item, Void>() { @Override public boolean isInMemory() { return true; } @Override public int size(Query<Item, Void> query) { return 2; } @Override public Stream<Item> fetch(Query<Item, Void> query) { return Stream.of(first, second); } @Override public void refreshItem(Item item) { } @Override public void refreshAll() { } @Override public Registration addDataProviderListener( DataProviderListener<Item> listener) { return null; } }; DataView<Item> dataView = component.setItems(dataProvider); DataKeyMapper<Item> keyMapper = component.getDataCommunicator() .getKeyMapper(); items.forEach(keyMapper::key); Assert.assertFalse(keyMapper.has(new Item(1L, "non-present"))); dataView.setIdentifierProvider(Item::getId); Assert.assertTrue(keyMapper.has(new Item(1L, "non-present"))); dataView.setIdentifierProvider(IdentifierProvider.identity()); Assert.assertFalse(keyMapper.has(new Item(1L, "non-present"))); dataView = component.setItems(DataProvider.ofCollection(items)); items.forEach(keyMapper::key); Assert.assertFalse(keyMapper.has(new Item(1L, "non-present"))); dataView.setIdentifierProvider(Item::getId); Assert.assertTrue(keyMapper.has(new Item(1L, "non-present"))); dataView.setIdentifierProvider(IdentifierProvider.identity()); Assert.assertFalse(keyMapper.has(new Item(1L, "non-present"))); }
@Override public void setIdentifierProvider( IdentifierProvider<T> identifierProvider) { super.setIdentifierProvider(identifierProvider); dataCommunicator.getKeyMapper().setIdentifierGetter(identifierProvider); }
GridDataView extends AbstractDataView<T> { @Override public void setIdentifierProvider( IdentifierProvider<T> identifierProvider) { super.setIdentifierProvider(identifierProvider); dataCommunicator.getKeyMapper().setIdentifierGetter(identifierProvider); } }
GridDataView extends AbstractDataView<T> { @Override public void setIdentifierProvider( IdentifierProvider<T> identifierProvider) { super.setIdentifierProvider(identifierProvider); dataCommunicator.getKeyMapper().setIdentifierGetter(identifierProvider); } GridDataView(DataCommunicator<T> dataCommunicator,
                        Grid<T> grid); }
GridDataView extends AbstractDataView<T> { @Override public void setIdentifierProvider( IdentifierProvider<T> identifierProvider) { super.setIdentifierProvider(identifierProvider); dataCommunicator.getKeyMapper().setIdentifierGetter(identifierProvider); } GridDataView(DataCommunicator<T> dataCommunicator,
                        Grid<T> grid); @Override T getItem(int index); @Override Stream<T> getItems(); @Override void setIdentifierProvider(
            IdentifierProvider<T> identifierProvider); }
GridDataView extends AbstractDataView<T> { @Override public void setIdentifierProvider( IdentifierProvider<T> identifierProvider) { super.setIdentifierProvider(identifierProvider); dataCommunicator.getKeyMapper().setIdentifierGetter(identifierProvider); } GridDataView(DataCommunicator<T> dataCommunicator,
                        Grid<T> grid); @Override T getItem(int index); @Override Stream<T> getItems(); @Override void setIdentifierProvider(
            IdentifierProvider<T> identifierProvider);  }