Trace: • Vaadin UI code snippets
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vaadin:code_snippets [2018/02/12 06:59] admin [Checkbox in Table Header] |
vaadin:code_snippets [2020/02/05 21:20] (current) admin |
||
---|---|---|---|
Line 1: | Line 1: | ||
~~NOTRANS~~ | ~~NOTRANS~~ | ||
- | |||
~~Title: Vaadin UI code snippets~~ | ~~Title: Vaadin UI code snippets~~ | ||
Line 31: | Line 30: | ||
}); | }); | ||
</file> | </file> | ||
+ | |||
+ | ==== Checkbox in Grid Header ==== | ||
+ | |||
+ | If you want to show a checkbox in the header of a Grid: | ||
+ | |||
+ | {{:vaadin:grid_checkbox.png?nolink|}} | ||
+ | |||
+ | use following code: | ||
+ | |||
+ | <file java> | ||
+ | CheckBox cbx = new CheckBox(); | ||
+ | cbx.addValueChangeListener(new ValueChangeListener<Boolean>() | ||
+ | { | ||
+ | @Override | ||
+ | public void valueChange(ValueChangeEvent<Boolean> event) | ||
+ | { | ||
+ | System.out.println("Pressed!"); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | UIFactoryManager.getFactory().invokeLater(() -> | ||
+ | { | ||
+ | // Cast the resource to a Grid. | ||
+ | ((Grid)((VaadinGrid)navLoggings.getUIResource()).getResource()) | ||
+ | // Get the first (automatically added) row. | ||
+ | .getHeaderRow(0) | ||
+ | // Get the cell for the column we want. | ||
+ | .getCell("CHECK") | ||
+ | // Add the component. | ||
+ | .setComponent(cbx); | ||
+ | }); | ||
+ | </file> | ||
+ | |||
+ | ==== Disable autocomplete ==== | ||
+ | |||
+ | You have different options: | ||
+ | |||
+ | 1) Disable for a specific editor | ||
+ | |||
+ | <code java> | ||
+ | ((IAutoCompleteFeature)editCompanyHeadofdepartmentsurname.getUIResource()).setAutoComplete(false); | ||
+ | </code> | ||
+ | |||
+ | 2) Disable for the cell editor | ||
+ | |||
+ | <code java> | ||
+ | ICellEditor ced = UICellEditor.getCellEditor(book, "COLUMN"); | ||
+ | |||
+ | //if you set a custom cell editor | ||
+ | if (ced instanceof UICellEditor) | ||
+ | { | ||
+ | ced = (ICellEditor)((UICellEditor)ced).getUIResource(); | ||
+ | } | ||
+ | |||
+ | ((IAutoCompleteFeature)ced).setAutoComplete(false); | ||
+ | </code> | ||
+ | |||
+ | Be careful with cell editors, because if no custom cell editor was set, the default (global) cell editors will be used. If you change the autocomplete feature for the global text cell editor, all editors are affected. | ||
+ | |||
+ | It's a good idea to set a custom cell editor: | ||
+ | |||
+ | <code java> | ||
+ | book.getRowDefinition().getColumnDefinition("COLUMN").getDataType().setCellEditor(new UITextCellEditor()); | ||
+ | </code> |