EditorImpl extends AbstractGridExtension<T> implements Editor<T> { @Override public void editItem(T item) { Objects.requireNonNull(item, "Editor can't edit null"); final T it = item; if (editItemRequest == null) { editItemRequest = context -> { requestEditItem(it); editItemRequest = null; }; getGrid().getElement().getNode().runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(getGrid().getElement().getNode(), editItemRequest)); } } EditorImpl(Grid<T> grid, PropertySet<T> propertySet); @Override Editor<T> setBinder(Binder<T> binder); @Override Binder<T> getBinder(); @Override Editor<T> setBuffered(boolean buffered); @Override boolean isBuffered(); @Override boolean isOpen(); @Override boolean save(); @Override void cancel(); @Override void closeEditor(); @Override void editItem(T item); @Override void refresh(); @Override T getItem(); @Override Grid<T> getGrid(); @Override void generateData(T item, JsonObject jsonObject); @Override Registration addSaveListener(EditorSaveListener<T> listener); @Override Registration addCancelListener(EditorCancelListener<T> listener); @Override Registration addOpenListener(EditorOpenListener<T> listener); @Override Registration addCloseListener(EditorCloseListener<T> listener);  }
@Test(expected = IllegalStateException.class) public void editItem_itemIsNotKnown_throw() { editor.editItem("foo"); fakeClientResponse(); }
@Test(expected = IllegalStateException.class) public void editItem_noBinder_throw() { editor = new TestEditor(grid); editor.editItem("bar"); fakeClientResponse(); }
@Test public void editItem_switchEditedItem_itemsAreRefreshed() { grid.getDataCommunicator().getKeyMapper().key("foo"); editor.editItem("bar"); fakeClientResponse(); editor.refreshedItems.clear(); editor.editItem("foo"); fakeClientResponse(); Assert.assertEquals(2, editor.refreshedItems.size()); Assert.assertEquals("bar", editor.refreshedItems.get(0)); Assert.assertEquals("foo", editor.refreshedItems.get(1)); }
@Test public void save_editorIsOpened_editorIsInNotBufferedMode_noEvents() { editor.editItem("bar"); fakeClientResponse(); editor.refreshedItems.clear(); AtomicReference<StatusChangeEvent> statusEventCapture = new AtomicReference<>(); AtomicReference<EditorEvent<String>> saveEventCapture = new AtomicReference<>(); AtomicReference<EditorEvent<String>> closeEventCapture = new AtomicReference<>(); assertNegativeSave(statusEventCapture, saveEventCapture, closeEventCapture); Assert.assertEquals(0, editor.refreshedItems.size()); Assert.assertNull(statusEventCapture.get()); Assert.assertNull(saveEventCapture.get()); Assert.assertNull(closeEventCapture.get()); }