Package com.vaadin.client.widgets
Class Grid.Editor<T>
- java.lang.Object
-
- com.vaadin.client.widgets.Grid.Editor<T>
-
- Type Parameters:
T- the row type of the grid
- All Implemented Interfaces:
DeferredWorker
public static class Grid.Editor<T> extends Object implements DeferredWorker
An editor UI for Grid rows. A single Grid row at a time can be opened for editing.- Since:
- 7.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGrid.Editor.EventHandler<T>A handler for events related to the Grid editor.protected static classGrid.Editor.StateThe internal state options for the editor.
-
Field Summary
Fields Modifier and Type Field Description static intKEYCODE_HIDEDeprecated.useDefaultEditorEventHandler.KEYCODE_CLOSEinsteadstatic intKEYCODE_SHOWDeprecated.useDefaultEditorEventHandler.KEYCODE_OPENinstead
-
Constructor Summary
Constructors Constructor Description Editor()Constructs a newGrid.Editor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcancel()Cancels the currently active edit and hides the editor.voidclearEditorColumnErrors()Clears all editor error styles from the editor cells and clears the error column collection.protected com.google.gwt.dom.client.ElementcreateCell(com.google.gwt.dom.client.TableCellElement td)Creates an editor cell corresponding to the given table cell.voideditRow(int rowIndex)If a cell of this Grid had focus once this editRow call was triggered, the editor component at the previously focused column index will be focused.voideditRow(int rowIndex, int columnIndexDOM)Opens the editor over the row with the given index and attempts to focus the editor widget in the given column index.StringgetCancelCaption()Returns the caption of the cancel button.protected intgetElementColumn(com.google.gwt.dom.client.Element e)Returns the column index of the editor cell that contains the given element, or -1 if the element can't be found within the editor cells.Grid.Editor.EventHandler<T>getEventHandler()Returns the event handler of this Editor.EditorHandler<T>getHandler()Returns the handler responsible for binding data and editor widgets to this editor.intgetRow()Returns the index of the row that is currently assigned to the editor.StringgetSaveCaption()Returns the caption of the save button.protected Grid.Editor.StategetState()Returns the internal state of the editor.protected com.google.gwt.user.client.ui.WidgetgetWidget(Grid.Column<?,T> column)Returns the editor widget associated with the given column.protected voidhideOverlay()Hides the editor overlay and clears its contents.booleanisBuffered()Returns whether this editor is buffered or not.booleanisEditorColumnError(Grid.Column<?,T> column)Returns true if the column has been listed as containing an error.booleanisEnabled()Returns the enabled state of this editor.booleanisWorkPending()Checks whether there are operations pending for this widget or connector that must be executed before reaching a steady state.voidsave()Saves any unsaved changes to the data source and hides the editor.voidsetBuffered(boolean buffered)Sets the buffered mode.voidsetCancelCaption(String cancelCaption)Sets the caption of the cancel button.voidsetEditorColumnError(Grid.Column<?,T> column, boolean hasError)If the given column is indicated to have an error in the editor, sets the error styles to the corresponding editor cell and lists the column as having an error.voidsetEditorError(String errorMessage, Collection<Grid.Column<?,T>> errorColumns)Sets an error message for the editor, or removes it if the given message isnull.voidsetEnabled(boolean enabled)Sets the enabled state of this editor.voidsetEventHandler(Grid.Editor.EventHandler<T> handler)Sets the event handler for this Editor.protected voidsetGrid(Grid<T> grid)Sets the grid this editor belongs to.protected voidsetGridEnabled(boolean enabled)Sets the editor's buttons enabled.voidsetHandler(EditorHandler<T> rowHandler)Sets the handler responsible for binding data and editor widgets to this editor.voidsetSaveCaption(String saveCaption)Sets the caption of the save button.protected voidsetState(Grid.Editor.State state)Sets the internal state of the editor.protected voidsetStylePrimaryName(String primaryName)Sets the editor's primary style name and updates all dependent style names.protected voidshow(int rowIndex, int columnIndex)If the Editor is still activating, proceeds to the binding phase.protected voidshowOverlay()Opens the editor overlay over the grid row indicated bygetRow().protected voidshowOverlay(com.google.gwt.dom.client.TableRowElement unused)Deprecated.As of 7.5, useshowOverlay()instead.
-
-
-
Field Detail
-
KEYCODE_SHOW
@Deprecated public static final int KEYCODE_SHOW
Deprecated.useDefaultEditorEventHandler.KEYCODE_OPENinstead- See Also:
- Constant Field Values
-
KEYCODE_HIDE
@Deprecated public static final int KEYCODE_HIDE
Deprecated.useDefaultEditorEventHandler.KEYCODE_CLOSEinstead- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Editor
public Editor()
Constructs a newGrid.Editor.
-
-
Method Detail
-
setEditorError
public void setEditorError(String errorMessage, Collection<Grid.Column<?,T>> errorColumns)
Sets an error message for the editor, or removes it if the given message isnull. If the editor is in edit mode or currently processing a save operation, updates the editor cells to show error styles for the given columns and clears error styles from any other columns.- Parameters:
errorMessage- the message to set, ornullif no message should be shownerrorColumns- the columns that currently contain errors
-
getRow
public int getRow()
Returns the index of the row that is currently assigned to the editor. If the editor is open and in the edit mode, that row's contents can be edited via the editor cells. -1 if the editor is closed.- Returns:
- currently assigned row index, or -1 if not set
-
editRow
public void editRow(int rowIndex)
If a cell of this Grid had focus once this editRow call was triggered, the editor component at the previously focused column index will be focused. If a Grid cell was not focused prior to calling this method, it will be equivalent toeditRow(rowIndex, -1).- Parameters:
rowIndex- the index of the row to be edited- See Also:
editRow(int, int)
-
editRow
public void editRow(int rowIndex, int columnIndexDOM)Opens the editor over the row with the given index and attempts to focus the editor widget in the given column index. Does not move focus if the widget is not focusable or if the column index is -1.- Parameters:
rowIndex- the index of the row to be editedcolumnIndexDOM- the column index (excluding hidden columns) of the editor widget that should be initially focused or -1 to not set focus- Throws:
IllegalStateException- if this editor is not enabledIllegalStateException- if this editor is already in edit mode and in buffered mode- Since:
- 7.5
-
cancel
public void cancel()
Cancels the currently active edit and hides the editor. Any changes that are notsavedare lost.- Throws:
IllegalStateException- if this editor is not enabledIllegalStateException- if this editor is not in edit mode
-
save
public void save()
Saves any unsaved changes to the data source and hides the editor.- Throws:
IllegalStateException- if this editor is not enabledIllegalStateException- if this editor is not in edit mode
-
getHandler
public EditorHandler<T> getHandler()
Returns the handler responsible for binding data and editor widgets to this editor.- Returns:
- the editor handler or null if not set
-
setHandler
public void setHandler(EditorHandler<T> rowHandler)
Sets the handler responsible for binding data and editor widgets to this editor.- Parameters:
rowHandler- the new editor handler- Throws:
IllegalStateException- if this editor is currently in edit mode
-
isEnabled
public boolean isEnabled()
Returns the enabled state of this editor.- Returns:
trueif enabled,falseotherwise
-
setEnabled
public void setEnabled(boolean enabled)
Sets the enabled state of this editor.- Parameters:
enabled-trueif enabled,falseotherwise- Throws:
IllegalStateException- if in edit mode and trying to disableIllegalStateException- if the editor handler is not set
-
show
protected void show(int rowIndex, int columnIndex)If the Editor is still activating, proceeds to the binding phase. Otherwise does nothing.- Parameters:
rowIndex- the index of the row to be editedcolumnIndex- the column index (excluding hidden columns) of the editor widget that should be initially focused or -1 to not set focus
-
setGrid
protected void setGrid(Grid<T> grid)
Sets the grid this editor belongs to. Should not be null. Should only be called once.- Parameters:
grid- the parent grid
-
getState
protected Grid.Editor.State getState()
Returns the internal state of the editor.- Returns:
- the state
-
setState
protected void setState(Grid.Editor.State state)
Sets the internal state of the editor.- Parameters:
state- the state to set
-
getWidget
protected com.google.gwt.user.client.ui.Widget getWidget(Grid.Column<?,T> column)
Returns the editor widget associated with the given column. If the editor is not active or the column is noteditable, returns null.- Parameters:
column- the column- Returns:
- the widget if the editor is open and the column is editable, null otherwise
-
showOverlay
@Deprecated protected void showOverlay(com.google.gwt.dom.client.TableRowElement unused)
Deprecated.As of 7.5, useshowOverlay()instead.Equivalent toshowOverlay(). The argument is ignored.- Parameters:
unused- ignored argument
-
showOverlay
protected void showOverlay()
Opens the editor overlay over the grid row indicated bygetRow().- Since:
- 7.5
-
hideOverlay
protected void hideOverlay()
Hides the editor overlay and clears its contents.
-
setStylePrimaryName
protected void setStylePrimaryName(String primaryName)
Sets the editor's primary style name and updates all dependent style names.- Parameters:
primaryName- the new primary style name
-
createCell
protected com.google.gwt.dom.client.Element createCell(com.google.gwt.dom.client.TableCellElement td)
Creates an editor cell corresponding to the given table cell. The returned element is empty and has the same dimensions and position as the table cell.- Parameters:
td- the table cell used as a reference- Returns:
- an editor cell corresponding to the given cell
-
setGridEnabled
protected void setGridEnabled(boolean enabled)
Sets the editor's buttons enabled. Does not update the enabled status of the grid this editor belongs to, nor ask the enabled status from it.- Parameters:
enabled-trueto enable the buttons,falseto disable them
-
setSaveCaption
public void setSaveCaption(String saveCaption) throws IllegalArgumentException
Sets the caption of the save button. Should not benull.- Parameters:
saveCaption- the new caption text- Throws:
IllegalArgumentException- if the given text isnull
-
getSaveCaption
public String getSaveCaption()
Returns the caption of the save button.- Returns:
- the caption text
-
setCancelCaption
public void setCancelCaption(String cancelCaption) throws IllegalArgumentException
Sets the caption of the cancel button. Should not benull.- Parameters:
cancelCaption- the new caption text- Throws:
IllegalArgumentException- if the given text isnull
-
getCancelCaption
public String getCancelCaption()
Returns the caption of the cancel button.- Returns:
- the caption text
-
setEditorColumnError
public void setEditorColumnError(Grid.Column<?,T> column, boolean hasError)
If the given column is indicated to have an error in the editor, sets the error styles to the corresponding editor cell and lists the column as having an error. Otherwise removes the error styles from the cell and removes the column from the error collection.- Parameters:
column- the column which should have its editor error status updatedhasError-trueif the cell should get error styles,falseif the error styles should be removed from the cell
-
clearEditorColumnErrors
public void clearEditorColumnErrors()
Clears all editor error styles from the editor cells and clears the error column collection.
-
isEditorColumnError
public boolean isEditorColumnError(Grid.Column<?,T> column)
Returns true if the column has been listed as containing an error.- Parameters:
column- the column whose error status is checked- Returns:
trueif the column is listed as containing an error,falseotherwise
-
setBuffered
public void setBuffered(boolean buffered)
Sets the 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,falseotherwise
-
isBuffered
public boolean isBuffered()
Returns whether this editor is buffered or not.- Returns:
trueif editor is buffered,falseotherwise- See Also:
setBuffered(boolean)
-
setEventHandler
public void setEventHandler(Grid.Editor.EventHandler<T> handler)
Sets the event handler for this Editor.- Parameters:
handler- the new event handler- Since:
- 7.6
-
getEventHandler
public Grid.Editor.EventHandler<T> getEventHandler()
Returns the event handler of this Editor.- Returns:
- the current event handler
- Since:
- 7.6
-
isWorkPending
public boolean isWorkPending()
Description copied from interface:DeferredWorkerChecks whether there are operations pending for this widget or connector that must be executed before reaching a steady state.- Specified by:
isWorkPendingin interfaceDeferredWorker
-
getElementColumn
protected int getElementColumn(com.google.gwt.dom.client.Element e)
Returns the column index of the editor cell that contains the given element, or -1 if the element can't be found within the editor cells.- Parameters:
e- the element to be located- Returns:
- the column index of the associated editor cell, or -1 if not found
-
-