E
- the bean type@Tag(value="vaadin-crud") @HtmlImport(value="frontend://bower_components/vaadin-crud/src/vaadin-crud.html") @HtmlImport(value="frontend://bower_components/vaadin-crud/src/vaadin-crud-edit-column.html") public class Crud<E> extends Component implements HasSize, HasTheme
Basic usage
Crud<Person> crud = new Crud<>(Person.class, personEditor);
crud.setDataProvider(personDataProvider);
// Handle save and delete events.
crud.addSaveListener(e -> save(e.getItem()));
crud.addDeleteListener(e -> delete(e.getItem()));
Modifier and Type | Class and Description |
---|---|
static class |
Crud.CancelEvent<E>
Event fired when the user cancels the creation of a new item
or modifications to an existing item.
|
static class |
Crud.DeleteEvent<E>
Event fired when the user tries to delete an existing item.
|
static class |
Crud.EditEvent<E>
Event fired when the user starts to edit an existing item.
|
static class |
Crud.NewEvent<E>
Event fired when the user starts to create a new item.
|
static class |
Crud.SaveEvent<E>
Event fired when the user tries to save a new item or modifications to an existing item.
|
Constructor and Description |
---|
Crud()
Instantiates a new Crud with no grid, editor and runtime bean type information.
|
Crud(Class<E> beanType,
CrudEditor<E> editor)
Instantiates a new Crud for the given bean type and uses the supplied editor.
|
Crud(Class<E> beanType,
Grid<E> grid,
CrudEditor<E> editor)
Instantiates a new Crud using a custom grid.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addCancelListener(ComponentEventListener<Crud.CancelEvent<E>> listener)
Registers a listener to be notified when the user cancels a new item creation or existing item
modification in progress.
|
Registration |
addDeleteListener(ComponentEventListener<Crud.DeleteEvent<E>> listener)
Registers a listener to be notified when the user tries to delete an existing item.
|
static void |
addEditColumn(Grid grid)
A helper method to add an edit column to a grid.
|
static void |
addEditColumn(Grid grid,
CrudI18n crudI18n)
A helper method to add an edit column to a grid.
|
Registration |
addEditListener(ComponentEventListener<Crud.EditEvent<E>> listener)
Registers a listener to be notified when the user starts to edit an existing item.
|
Registration |
addNewListener(ComponentEventListener<Crud.NewEvent<E>> listener)
Registers a listener to be notified when the user starts to create a new item.
|
Registration |
addSaveListener(ComponentEventListener<Crud.SaveEvent<E>> listener)
Registers a listener to be notified when the user tries to save a new item
or modifications to an existing item.
|
void |
addThemeVariants(CrudVariant... variants)
Adds theme variants to the component.
|
Class<E> |
getBeanType()
Gets the runtime bean type information
|
DataProvider<E,?> |
getDataProvider()
Gets the data provider supplying the grid data.
|
CrudEditor<E> |
getEditor()
Gets the crud editor.
|
Grid<E> |
getGrid()
Gets the grid
|
static boolean |
hasEditColumn(Grid grid)
Checks if an edit column has been added to the Grid using
Crud.addEditColumn(Grid) |
static void |
removeEditColumn(Grid grid)
Removes the crud edit column from a grid
|
void |
removeThemeVariants(CrudVariant... variants)
Removes theme variants from the component.
|
void |
setBeanType(Class<E> beanType)
Sets the runtime bean type information.
|
void |
setDataProvider(DataProvider<E,?> provider)
Sets the data provider for the grid.
|
void |
setEditor(CrudEditor<E> editor)
Sets the editor.
|
void |
setGrid(Grid<E> grid)
Sets the grid
|
void |
setI18n(CrudI18n i18n)
Sets the internationalized messages to be used by this crud instance.
|
void |
setOpened(boolean opened)
Opens or closes the editor.
|
void |
setToolbar(Component... components)
Sets the content of the toolbar.
|
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHeight, getWidth, setHeight, setSizeFull, setSizeUndefined, setWidth
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
getElement
addAttachListener
addDetachListener
public Crud(Class<E> beanType, Grid<E> grid, CrudEditor<E> editor)
beanType
- the class of itemsgrid
- the grid with which the items listing should be displayededitor
- the editor for manipulating individual itemsCrud(Class, CrudEditor)
public Crud(Class<E> beanType, CrudEditor<E> editor)
beanType
- the class of itemseditor
- the editor for manipulating individual itemsCrudGrid
,
Crud(Class, Grid, CrudEditor)
public Crud()
Example:
@Id
Crud<Person> crud;
@Id
private TextField firstName;
@Id
private TextField lastName;
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
Binder<Person> binder = new Binder<>(Person.class);
binder.bind(firstName, Person::getFirstName, Person::setFirstName);
binder.bind(lastName, Person::getLastName, Person::setLastName);
crud.setEditor(new BinderCrudEditor<>(binder));
crud.setBeanType(Person.class);
crud.setDataProvider(new PersonCrudDataProvider());
}
setEditor(CrudEditor)
,
setBeanType(Class)
public void setOpened(boolean opened)
opened
- true to open or false to closepublic Class<E> getBeanType()
public void setBeanType(Class<E> beanType)
Crud
with @Id this method must be called
before the crud is put into use.beanType
- the bean typepublic CrudEditor<E> getEditor()
public void setEditor(CrudEditor<E> editor)
Crud
with @Id this method must be called
before the crud is put into use.editor
- the editorpublic void setToolbar(Component... components)
components
- the content to be setpublic void setI18n(CrudI18n i18n)
i18n
- the internationalized messagesCrudI18n.createDefault()
public void addThemeVariants(CrudVariant... variants)
variants
- theme variants to addpublic void removeThemeVariants(CrudVariant... variants)
variants
- theme variants to removepublic Registration addNewListener(ComponentEventListener<Crud.NewEvent<E>> listener)
listener
- a listener to be notifiedpublic Registration addEditListener(ComponentEventListener<Crud.EditEvent<E>> listener)
listener
- a listener to be notifiedpublic Registration addSaveListener(ComponentEventListener<Crud.SaveEvent<E>> listener)
listener
- a listener to be notifiedpublic Registration addCancelListener(ComponentEventListener<Crud.CancelEvent<E>> listener)
listener
- a listener to be notifiedpublic Registration addDeleteListener(ComponentEventListener<Crud.DeleteEvent<E>> listener)
listener
- a listener to be notifiedpublic DataProvider<E,?> getDataProvider()
public void setDataProvider(DataProvider<E,?> provider)
provider
- the data provider for the gridpublic static void addEditColumn(Grid grid)
grid
- the grid in which to add the edit columnaddEditColumn(Grid, CrudI18n)
,
removeEditColumn(Grid)
,
hasEditColumn(Grid)
public static void addEditColumn(Grid grid, CrudI18n crudI18n)
grid
- the grid in which to add the edit columncrudI18n
- the i18n object for localizing the accessibility of the edit columnpublic static void removeEditColumn(Grid grid)
grid
- the grid from which to remove the edit columnaddEditColumn(Grid)
,
hasEditColumn(Grid)
public static boolean hasEditColumn(Grid grid)
Crud.addEditColumn(Grid)
grid
- the grid to checkaddEditColumn(Grid)
Copyright © 2018. All rights reserved.