Interface Editor<T>

Type Parameters:
T - the type of the row/item being edited
All Superinterfaces:
Serializable
All Known Implementing Classes:
EditorImpl

public interface Editor<T> extends Serializable
An editor in a Grid.

This class contains methods for editor functionality: configure an editor Binder, open the editor, save and cancel a row editing.

Author:
Vaadin Ltd
  • Method Details

    • setBinder

      Editor<T> setBinder(Binder<T> binder)
      Sets the underlying Binder to this Editor.
      Parameters:
      binder - the binder for updating editor fields; not null
      Returns:
      this editor
    • getBinder

      Binder<T> getBinder()
      Returns the underlying Binder from Editor.
      Returns:
      the binder; not null
    • setBuffered

      Editor<T> setBuffered(boolean buffered)
      Sets the Editor buffered mode. When the editor is in buffered mode, edits are only committed when the user clicks the save button. In unbuffered mode valid changes are automatically committed.
      Parameters:
      buffered - true if editor should be buffered; false if not
      Returns:
      this editor
    • isBuffered

      boolean isBuffered()
      Returns whether Editor is buffered or not.
      Returns:
      true if editor is buffered; false if not
      See Also:
    • isOpen

      boolean isOpen()
      Returns whether Editor is open or not.
      Returns:
      true if editor is open; false if not
    • save

      boolean save()
      In buffered mode calling save will validate bean and will save any changes made to the Editor fields to the edited bean if all validators pass.

      A successful write will fire an EditorSaveEvent and close the editor that will fire an EditorCloseEvent.

      If the write fails then there will be no events and the editor will stay open.

      Note! For an unbuffered editor calling save will have no effect and always return false.

      Returns:
      true if save succeeded; false if not
    • cancel

      void cancel()
      Cancel will discard any changes made in editor fields for a buffered editor.

      Calling cancel will fire an EditorCancelEvent and close the editor that will fire an EditorCloseEvent if the edited item is not null.

    • closeEditor

      void closeEditor()
      Closes the editor when in unbuffered mode and fires an EditorCloseEvent if the edited item is not null.

      For buffered mode calling close editor will throw an UnsupportedOperationException as either save() or cancel() should be used.

      Throws:
      UnsupportedOperationException - thrown if trying to close editor in buffered mode
    • editItem

      void editItem(T item)
      Opens the editor component for the provided item and fires an EditorOpenEvent.

      In case there is an open editor an EditorCloseEvent will also be fired.

      Parameters:
      item - the edited item
      Throws:
      IllegalStateException - if already editing a different item in buffered mode
      IllegalArgumentException - if the item is not in the backing data provider
    • refresh

      void refresh()
      Refreshes the editor components for the current item being edited. It is a NO-OP if the editor is not opened.

      This is useful when the state of the item is changed while the editor is open.

      See Also:
    • getItem

      T getItem()
      Gets the current item being edited, if any.

      The item being edited is always null while the editor is closed. The item is not null during save() and cancel() operations, but become null as soon as the editor is closed.

      Returns:
      the item being edited, or null if none is being edited
      See Also:
    • getGrid

      Grid<T> getGrid()
      Gets the Grid instance which this editor belongs to.
      Returns:
      the grid which owns the editor
    • addSaveListener

      Registration addSaveListener(EditorSaveListener<T> listener)
      Adds an editor save listener. EditorSaveEvent is called when save() is called.
      Parameters:
      listener - save listener
      Returns:
      a registration object for removing the listener
    • addCancelListener

      Registration addCancelListener(EditorCancelListener<T> listener)
      Adds an editor cancel listener. EditorCancelEvent is fired when cancel() is called.
      Parameters:
      listener - cancel listener
      Returns:
      a registration object for removing the listener
    • addOpenListener

      Registration addOpenListener(EditorOpenListener<T> listener)
      Adds an editor open listener. EditorOpenEvent is fired when the editor is opened through editItem(java.lang.Object)
      Parameters:
      listener - open listener
      Returns:
      a registration object for removing the listener
    • addCloseListener

      Registration addCloseListener(EditorCloseListener<T> listener)
      Adds an editor close listener. Close events are sent every time the editor is closed, no matter if it is due to a close, save or to a cancel operation.

      When a successful save() operation is performed, two listeners are triggered: save and close listeners. Likewise, when a cancel() operation is performed, two listeners are triggered, cancel and close listeners.

      Parameters:
      listener - close listener
      Returns:
      a registration object for removing the listener