Interface Editor<T>
- Type Parameters:
T- the type of the row/item being edited
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
GroupDataGridEditor<T>
- All Known Implementing Classes:
EditorImpl,GroupDataGridEditorImpl
This class contains methods for editor functionality: configure an editor
Binder, open the editor, save and cancel a row editing.
-
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddCancelListener(EditorCancelListener<T> listener) Adds an editor cancellistener.com.vaadin.flow.shared.RegistrationaddCloseListener(EditorCloseListener<T> listener) Adds an editor closelistener.com.vaadin.flow.shared.RegistrationaddOpenListener(EditorOpenListener<T> listener) Adds an editor openlistener.com.vaadin.flow.shared.RegistrationaddSaveListener(EditorSaveListener<T> listener) Adds an editor savelistener.voidcancel()Cancel will discard any changes made in editor fields for a buffered editor.voidCloses the editor when in unbuffered mode and fires anEditorCloseEventif the edited item is notnull.voidOpens the editor component for the provided item and fires anEditorOpenEvent.com.vaadin.flow.data.binder.Binder<T>Returns the underlying Binder from Editor.getGrid()Gets the Grid instance which this editor belongs to.getItem()Gets the current item being edited, if any.booleanReturns whether Editor is buffered or not.booleanisOpen()Returns whether Editor is open or not.voidrefresh()Refreshes the editor components for the current item being edited.booleansave()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.Sets the underlying Binder to this Editor.setBuffered(boolean buffered) Sets the Editor buffered mode.
-
Method Details
-
setBinder
Sets the underlying Binder to this Editor.- Parameters:
binder- the binder for updating editor fields; notnull- Returns:
- this editor
-
getBinder
com.vaadin.flow.data.binder.Binder<T> getBinder()Returns the underlying Binder from Editor.- Returns:
- the binder; not
null
-
setBuffered
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-trueif editor should be buffered;falseif not- Returns:
- this editor
-
isBuffered
boolean isBuffered()Returns whether Editor is buffered or not.- Returns:
trueif editor is buffered;falseif not- See Also:
-
isOpen
boolean isOpen()Returns whether Editor is open or not.- Returns:
trueif editor is open;falseif 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
EditorSaveEventand close the editor that will fire anEditorCloseEvent.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:
trueif save succeeded;falseif not
-
cancel
void cancel()Cancel will discard any changes made in editor fields for a buffered editor.Calling cancel will fire an
EditorCancelEventand close the editor that will fire anEditorCloseEventif the edited item is notnull. -
closeEditor
void closeEditor()Closes the editor when in unbuffered mode and fires anEditorCloseEventif the edited item is notnull.For buffered mode calling close editor will throw an
UnsupportedOperationExceptionas eithersave()orcancel()should be used.- Throws:
UnsupportedOperationException- thrown if trying to close editor in buffered mode
-
editItem
Opens the editor component for the provided item and fires anEditorOpenEvent.In case there is an open editor an
EditorCloseEventwill also be fired.- Parameters:
item- the edited item- Throws:
IllegalStateException- if already editing a different item in buffered mode
-
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
nullwhile the editor is closed. The item is notnullduringsave()andcancel()operations, but becomenullas soon as the editor is closed.- Returns:
- the item being edited, or
nullif none is being edited - See Also:
-
getGrid
Gets the Grid instance which this editor belongs to.- Returns:
- the grid which owns the editor
-
addSaveListener
- Parameters:
listener- save listener- Returns:
- a registration object for removing the listener
-
addCancelListener
- Parameters:
listener- cancel listener- Returns:
- a registration object for removing the listener
-
addOpenListener
Adds an editor openlistener.EditorOpenEventis fired when the editor is opened througheditItem(java.lang.Object)- Parameters:
listener- open listener- Returns:
- a registration object for removing the listener
-
addCloseListener
Adds an editor closelistener. 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 acancel()operation is performed, two listeners are triggered, cancel and close listeners.- Parameters:
listener- close listener- Returns:
- a registration object for removing the listener
-