Package com.storedobject.ui
Class ListEditor<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.grid.Grid<T>
com.storedobject.vaadin.DataGrid<T>
com.storedobject.vaadin.ListGrid<T>
com.storedobject.ui.DataGrid<T>
com.storedobject.ui.AbstractEditableGrid<T>
com.storedobject.ui.EditableGrid<T>
com.storedobject.ui.ListEditor<T>
- Type Parameters:
T
- Type of objects to edit.
- All Implemented Interfaces:
Executable
,Reentrant
,HasLogic
,EditableDataGrid<T>
,Transactional
,ViewFilterSupport<T>
,ClickHandler
,ExecutableView
,HasColumns<T>
,SupportWindowMode
,ValueChangeHandler
,com.vaadin.flow.component.AttachNotifier
,com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.grid.Grid<T>>
,com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<? extends com.vaadin.flow.component.Component>>
,com.vaadin.flow.component.DetachNotifier
,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.grid.Grid<T>>
,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.grid.Grid<T>>
,com.vaadin.flow.component.HasElement
,com.vaadin.flow.component.HasEnabled
,com.vaadin.flow.component.HasSize
,com.vaadin.flow.component.HasStyle
,com.vaadin.flow.component.HasTheme
,com.vaadin.flow.component.HasValue.ValueChangeListener
,com.vaadin.flow.data.event.SortEvent.SortNotifier<com.vaadin.flow.component.grid.Grid<T>,
,com.vaadin.flow.component.grid.GridSortOrder<T>> com.vaadin.flow.data.provider.HasDataGenerators<T>
,com.vaadin.flow.data.provider.HasDataView<T,
,Void, com.vaadin.flow.component.grid.dataview.GridDataView<T>> com.vaadin.flow.data.provider.HasLazyDataView<T,
,Void, com.vaadin.flow.component.grid.dataview.GridLazyDataView<T>> com.vaadin.flow.data.provider.HasListDataView<T,
,com.vaadin.flow.component.grid.dataview.GridListDataView<T>> Serializable
,Iterable<T>
,Runnable
,Collection<T>
,EventListener
,List<T>
,SequencedCollection<T>
This class can be used to edit a list of any kind of Object instances. This may be used directly as a
View
(since it is a DataGrid
) or
it can be embedded in other layouts.- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.grid.Grid
com.vaadin.flow.component.grid.Grid.AbstractGridExtension<T>, com.vaadin.flow.component.grid.Grid.Column<T>, com.vaadin.flow.component.grid.Grid.DataCommunicatorBuilder<T,
U extends com.vaadin.flow.data.provider.ArrayUpdater>, com.vaadin.flow.component.grid.Grid.MultiSortPriority, com.vaadin.flow.component.grid.Grid.NestedNullBehavior, com.vaadin.flow.component.grid.Grid.SelectionMode, com.vaadin.flow.component.grid.Grid.UpdateQueue Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>
Nested classes/interfaces inherited from interface com.storedobject.vaadin.ClickHandler
ClickHandler.ModifiedClickEvent<C extends com.vaadin.flow.component.Component>
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>
Nested classes/interfaces inherited from interface com.storedobject.vaadin.HasColumns
HasColumns.SOGrid<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Button
"Add" button.protected final ButtonLayout
Button panel.protected final Button
"Delete" button.protected final Button
"Edit" button.protected final Button
"Save All" button. -
Constructor Summary
ConstructorsConstructorDescriptionListEditor
(Class<T> objectClass) Constructor.ListEditor
(Class<T> objectClass, Iterable<String> columns) Constructor.ListEditor
(Class<T> objectClass, Iterable<String> columns, BiFunction<T, Boolean, T> loader) Constructor.ListEditor
(Class<T> objectClass, BiFunction<T, Boolean, T> loader) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add()
Add a new instance.void
clear()
This method doesn't clear the items.void
Create extra header rows if required here by invokingHasColumns.prependHeader()
orHasColumns.appendHeader()
(typically useful for creating column grouping etc.).void
delete()
Delete a selected instance.void
edit()
Edit a selected instance.protected com.vaadin.flow.component.HasValue
<?, ?> getColumnField
(String columnName) Get the field for the column.final boolean
Can add new instances? (This will not affect the programmatic invocation of the methodadd()
).final boolean
Can delete instances?final boolean
Can edit instances? (This will not affect the programmatic invocation of the methodedit()
).boolean
Check if this editor is in an invalid state or not.void
save()
Save the currently accumulated changes.void
setAllowAdd
(boolean allowAdd) Enable/disable adding of new instances.void
setAllowDelete
(boolean allowDelete) Enable/disable deleting of instances.void
setAllowEdit
(boolean allowEdit) Enable/disable editing of instances.void
setAllowSaveAll
(boolean allowSaveAll) Enable/disable saving of all changes made.void
setNewObjectGenerator
(NewObject<T> newObjectGenerator) Set a "new object generator" so that theadd()
method can generate a customized instance when adding a new instance.void
setReadOnly
(boolean readOnly) Set read only.void
setSaver
(Function<EditableList<T>, Boolean> saver) Set a saver so that thesave()
method can be customized.void
This method is invoked by thesave()
method and if any exception is thrown, it will not carry out the real "save action".Methods inherited from class com.storedobject.ui.EditableGrid
addValueChangeTracker, cancelEdit, createListDataProvider, doDeleteAction, doInsertAction, doReloadAction, doReloadAllAction, doUndeleteAction, doUpdateAction, editItem, getEditingItem, getField, isColumnEditable, isReadOnly, isValid, saveEdited, setAutoSaveOnMove, streamEditableFields, validateFieldValues
Methods inherited from class com.storedobject.ui.AbstractEditableGrid
add, changed, createEditableList, createEditor, customizeColumn, delete, getColumnOrder, getEditableList, isAdded, isColumnSortable, isDeleted, isEdited, isFromClient, isSavePending, reload, reloadAll, setEditOnSingleClick, setFromClient, streamAdded, streamAll, streamDeleted, streamEdited, update
Methods inherited from class com.storedobject.ui.DataGrid
actionAllowed, append, canAllowAction, doAppendAction, getActionPrefix, getDataProvider, getObjectClass, itemAppended, itemDeleted, itemInserted, itemReloaded, itemUndeleted, itemUpdated, load, load, selected, selected, setItems, setItems, setItems, setItems, setItems, setItems, setItems, setItems, sort, sort, validateAppend, validateDelete, validateInsert, validateReload, validateUndelete, validateUpdate
Methods inherited from class com.storedobject.vaadin.ListGrid
add, addAll, addAll, addViewFilter, clearViewFilters, contains, containsAll, get, getData, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, onAttach, onDetach, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, setData, setViewFilter, size, subList, toArray, toArray
Methods inherited from class com.storedobject.vaadin.DataGrid
addConstructedListener, appendFooter, clearConstructedListeners, getColumnByKey, getColumns, getSOGrid, isColumnReorderingAllowed, setColumnReorderingAllowed, streamConstructedListeners
Methods inherited from class com.vaadin.flow.component.grid.Grid
addCellFocusListener, addColumn, addColumn, addColumn, addColumn, addColumn, addColumn, addColumn, addColumnReorderListener, addColumnResizeListener, addColumns, addComponentColumn, addContextMenu, addDataGenerator, addDragEndListener, addDragStartListener, addDropListener, addFirstHeaderRow, addItemClickListener, addItemDoubleClickListener, addSelectionListener, addSortListener, addThemeVariants, addValueProvider, appendFooterRow, appendHeaderRow, asMultiSelect, asSingleSelect, compareMaybeComparables, configureBeanType, createColumn, createColumnId, createDefaultArrayUpdater, createSortingComparator, deselect, deselectAll, getAriaLabel, getArrayUpdater, getBeanType, getClassNameGenerator, getColumnLayers, getColumnRendering, getDataCommunicator, getDefaultColumnFactory, getDefaultHeaderRow, getDragFilter, getDropFilter, getDropMode, getEditor, getEmptyStateComponent, getEmptyStateText, getFooterRows, getGenericDataView, getHeaderRows, getLazyDataView, getListDataView, getNestedNullBehavior, getPageSize, getPartNameGenerator, getPropertySet, getSelectedItems, getSelectionMode, getSelectionModel, getSelectionPreservationMode, getSortOrder, getUniqueKeyProperty, getUniqueKeyProvider, initConnector, insertColumnLayer, isAllRowsVisible, isDetailsVisible, isDetailsVisibleOnClick, isMultiSort, isRowsDraggable, onDataProviderChange, onEnabledStateChanged, prependFooterRow, prependHeaderRow, recalculateColumnWidths, removeAllColumns, removeAllFooterRows, removeAllHeaderRows, removeColumn, removeColumnByKey, removeColumnLayer, removeColumns, removeFooterRow, removeHeaderRow, removeThemeVariants, scrollToEnd, scrollToIndex, scrollToItem, scrollToStart, select, setAllRowsVisible, setAriaLabel, setClassNameGenerator, setColumnKey, setColumnOrder, setColumnOrder, setColumnRendering, setColumns, setDataProvider, setDefaultMultiSortPriority, setDetailsVisible, setDetailsVisibleOnClick, setDragDataGenerator, setDragFilter, setDropFilter, setDropMode, setEmptyStateComponent, setEmptyStateText, setItemDetailsRenderer, setItemSelectableProvider, setMultiSort, setMultiSort, setMultiSort, setMultiSort, setNestedNullBehavior, setPageSize, setPartNameGenerator, setRowsDraggable, setSelectionDragDetails, setSelectionMode, setSelectionModel, setSelectionPreservationMode, setSortableColumns, setTooltipGenerator, setUniqueKeyProperty, setUniqueKeyProvider, updateSelectionModeOnClient
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
Methods inherited from interface com.storedobject.vaadin.ClickHandler
clicked, doubleClicked, onComponentEvent, rightClicked
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.storedobject.ui.EditableDataGrid
canDelete, canEdit, canPostLedger, canViewLedger
Methods inherited from interface com.storedobject.common.Executable
act
Methods inherited from interface com.storedobject.vaadin.ExecutableView
abort, clean, clicked, close, createMenuItem, error, execute, execute, getMenuIconName, getMenuItem, getView, invoke, isCloseable, isFullScreen, isHomeView, log, log, message, returnedFrom, run, setClickable, speak, trackValueChange, tray, valueChanged, warning
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
Methods inherited from interface com.storedobject.vaadin.HasColumns
addItemSelectedListener, addItemsSelectedListener, appendHeader, clearAlerts, compact, configure, constructed, createColumn, createColumn, createColumn, createColumn, createColumn, createComponentColumn, createDecoratedWindow, createFooters, createHeader, createHierarchyColumn, createHTMLColumn, createHTMLHierarchyColumn, createView, customizeRenderer, deselect, deselect, executing, getApplication, getCaption, getColumn, getColumnCaption, getColumnCount, getColumnDetail, getColumnFunction, getColumnHeaderComponent, getColumnMethodName, getColumnNames, getColumnSorter, getColumnTemplate, getConfigureButton, getDataClass, getDefinedColumnCount, getFixedColumnWidth, getMenuItem, getObjectRendered, getObjectUnwrapped, getRelativeColumnWidth, getSelected, getTextAlign, getView, getViewComponent, ignoreCaseForColumnSorting, includeColumn, isColumnFrozen, isColumnResizable, isColumnVisible, prependFooter, prependHeader, refresh, refresh, refresh, removeItemSelectedListener, render, select, select, setCaption, setColumnFrozen, setColumnResizable, setColumnVisible, setMethodHandlerHost, sort, sort, sortOrder, sortOrder, unwrap
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
Methods inherited from interface java.util.List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, reversed, spliterator
Methods inherited from interface com.storedobject.common.Reentrant
isReentrant
Methods inherited from interface com.storedobject.vaadin.util.SupportWindowMode
createWindow
Methods inherited from interface com.storedobject.ui.Transactional
commit, execute, getLogic, getTransactionManager, run, setLogic, transact, transact, transactControl, transactControl
Methods inherited from interface com.storedobject.vaadin.ValueChangeHandler
valueChanged
Methods inherited from interface com.storedobject.ui.util.ViewFilterSupport
configure, configure, configure, configureMatch, filterView, getViewFilter
-
Field Details
-
buttonPanel
Button panel. -
add
"Add" button. -
edit
"Edit" button. -
delete
"Delete" button. -
saveAll
"Save All" button.
-
-
Constructor Details
-
ListEditor
-
ListEditor
-
ListEditor
-
ListEditor
-
-
Method Details
-
createHeaders
public void createHeaders()Description copied from interface:HasColumns
Create extra header rows if required here by invokingHasColumns.prependHeader()
orHasColumns.appendHeader()
(typically useful for creating column grouping etc.). Default implementation does nothing. This is invoked beforeHasColumns.createHeader()
. -
getColumnField
Description copied from class:EditableGrid
Get the field for the column. (Used while editing the row). In general, it is not required to override this. If this method returnsnull
, field will be created by inspecting the return value of the getXXX(T) method (where XXX is the name of the field) if such a method exists. If getXXX(T) method doesn't exist, it will try getXXX() method in the object class. If that also doesn't exist, no field will be created. (getXXX(T)/getXXX() methods and setXXX(T, value)/setXXX(value) methods are used to read from the object and write back to the object. If no setXXX method exists but a getXXX method exists, the field will be read-only).- Overrides:
getColumnField
in classEditableGrid<T>
- Parameters:
columnName
- Column name for which field needs to be obtained.- Returns:
- Default implementation returns
null
.
-
setNewObjectGenerator
-
add
public void add()Add a new instance. If no "new object generator"setNewObjectGenerator(NewObject)
is set, it will try to create an instance from a default constructor if available. -
edit
public void edit()Edit a selected instance. -
delete
public void delete()Delete a selected instance. -
setReadOnly
public void setReadOnly(boolean readOnly) Description copied from class:EditableGrid
Set read only.- Overrides:
setReadOnly
in classEditableGrid<T>
- Parameters:
readOnly
- If true, rows will not be editable.
-
clear
public void clear()Description copied from class:AbstractEditableGrid
This method doesn't clear the items. Instead, it just invokes theAbstractEditableGrid.fireChanged(Object, int)
method withnull
as the item value andEditorAction.ALL
as the "change action". Subclasses should implement the real "clear" functionality.- Specified by:
clear
in interfaceCollection<T>
- Specified by:
clear
in interfaceList<T>
- Overrides:
clear
in classAbstractEditableGrid<T>
-
isInvalid
public boolean isInvalid()Check if this editor is in an invalid state or not. (It will be in invalid state if the current row editor can not be closed because the data is invalid).- Returns:
- True or false.
-
isAllowAdd
public final boolean isAllowAdd()Can add new instances? (This will not affect the programmatic invocation of the methodadd()
).- Returns:
- True/false.
-
setAllowAdd
public void setAllowAdd(boolean allowAdd) Enable/disable adding of new instances.- Parameters:
allowAdd
- True/false
-
isAllowEdit
public final boolean isAllowEdit()Can edit instances? (This will not affect the programmatic invocation of the methodedit()
).- Returns:
- True/false.
-
setAllowEdit
public void setAllowEdit(boolean allowEdit) Enable/disable editing of instances.- Parameters:
allowEdit
- True/false.
-
isAllowDelete
public final boolean isAllowDelete()Can delete instances?- Returns:
- True/false.
-
setAllowDelete
public void setAllowDelete(boolean allowDelete) Enable/disable deleting of instances. (This will not affect the programmatic invocation of the methoddelete()
).- Parameters:
allowDelete
- True/false.
-
setAllowSaveAll
public void setAllowSaveAll(boolean allowSaveAll) Enable/disable saving of all changes made. (This will not affect the programmatic invocation of the methodsave()
).- Parameters:
allowSaveAll
- True/false.
-
validateData
This method is invoked by thesave()
method and if any exception is thrown, it will not carry out the real "save action". Exceptions will be displayed as warning messages on the UI. This method is typically overridden to raise user-friendly messages when data is not valid.- Throws:
Exception
- If any the data is not valid.
-
save
public void save()Save the currently accumulated changes. Errors if any will be displayed in the UI.If a saver is set via
setSaver(Function)
, that saver will be used for saving the changes. Otherwise, all values are updated in the internal list. -
setSaver
Set a saver so that thesave()
method can be customized.- Parameters:
saver
- Set a saver that will be invoked to save the changes made.
-