List of usage examples for com.vaadin.shared.ui.grid HeightMode UNDEFINED
HeightMode UNDEFINED
To view the source code for com.vaadin.shared.ui.grid HeightMode UNDEFINED.
Click Source Link
From source file:com.haulmont.cuba.web.gui.components.WebDataGrid.java
License:Apache License
protected void initComponent(CubaGrid component) { setSelectionMode(SelectionMode.SINGLE); component.setImmediate(true);/*from w w w . j a va 2 s . com*/ component.setColumnReorderingAllowed(true); containerWrapper = new GeneratedPropertyContainer(component.getContainerDataSource()); component.setContainerDataSource(containerWrapper); component.addSelectionListener(e -> { if (datasource == null) { return; } final Set<E> selected = getSelected(); if (selected.isEmpty()) { Entity dsItem = datasource.getItemIfValid(); //noinspection unchecked datasource.setItem(null); if (dsItem == null) { // in this case item change event will not be generated refreshActionsState(); } } else { // reset selection and select new item if (isMultiSelect()) { //noinspection unchecked datasource.setItem(null); } Entity newItem = selected.iterator().next(); Entity dsItem = datasource.getItemIfValid(); //noinspection unchecked datasource.setItem(newItem); if (Objects.equals(dsItem, newItem)) { // in this case item change event will not be generated refreshActionsState(); } } LookupSelectionChangeEvent selectionChangeEvent = new LookupSelectionChangeEvent(this); getEventRouter().fireEvent(LookupSelectionChangeListener.class, LookupSelectionChangeListener::lookupValueChanged, selectionChangeEvent); if (getEventRouter().hasListeners(SelectionListener.class)) { List<E> addedItems = getItemsByIds(e.getAdded()); List<E> removedItems = getItemsByIds(e.getRemoved()); List<E> selectedItems = getItemsByIds(e.getSelected()); SelectionEvent<E> event = new SelectionEvent<>(WebDataGrid.this, addedItems, removedItems, selectedItems); //noinspection unchecked getEventRouter().fireEvent(SelectionListener.class, SelectionListener::selected, event); } }); component.addShortcutListener(new ShortcutListener("dataGridEnter", KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { if (target == WebDataGrid.this.component) { if (WebDataGrid.this.isEditorEnabled()) { // Prevent custom actions on Enter if DataGrid editor is enabled // since it's the default shortcut to open editor return; } if (enterPressAction != null) { enterPressAction.actionPerform(WebDataGrid.this); } else { handleDoubleClickAction(); } } } }); component.addItemClickListener(e -> { if (e.isDoubleClick() && e.getItem() != null && !WebDataGrid.this.isEditorEnabled()) { // note: for now Grid doesn't send double click if editor is enabled, // but it's better to handle it manually handleDoubleClickAction(); } if (getEventRouter().hasListeners(ItemClickListener.class)) { MouseEventDetails mouseEventDetails = WebWrapperUtils.toMouseEventDetails(e); //noinspection unchecked E item = (E) datasource.getItem(e.getItemId()); if (item == null) { // this can happen if user clicked on an item which is removed from the // datasource, so we don't want to send such event because it's useless return; } Column column = getColumnByPropertyId(e.getPropertyId()); ItemClickEvent<E> event = new ItemClickEvent<>(WebDataGrid.this, mouseEventDetails, item, e.getItemId(), column != null ? column.getId() : null); //noinspection unchecked getEventRouter().fireEvent(ItemClickListener.class, ItemClickListener::onItemClick, event); } }); component.addColumnReorderListener(e -> { if (e.isUserOriginated()) { // Grid doesn't know about columns hidden by security permissions, // so we need to return them back to they previous positions columnsOrder = restoreColumnsOrder(getColumnsOrderInternal()); if (getEventRouter().hasListeners(ColumnReorderListener.class)) { ColumnReorderEvent event = new ColumnReorderEvent(WebDataGrid.this); getEventRouter().fireEvent(ColumnReorderListener.class, ColumnReorderListener::columnReordered, event); } } }); componentComposition = new GridComposition(); componentComposition.setPrimaryStyleName("c-data-grid-composition"); componentComposition.setGrid(component); componentComposition.addComponent(component); componentComposition.setWidthUndefined(); component.setSizeUndefined(); component.setHeightMode(HeightMode.UNDEFINED); component.setRowStyleGenerator(createRowStyleGenerator()); component.setCellStyleGenerator(createCellStyleGenerator()); }