Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.save.client; import com.save.client.promodeals.PromoUI; import com.save.abstractclasses.AbstractDataGridProperties; import com.save.utilities.CommonUtilities; import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.filter.SimpleStringFilter; import com.vaadin.event.ItemClickEvent; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.TextField; import com.vaadin.ui.themes.ValoTheme; /** * * @author jetdario */ public class ClientsDataGridProperties extends AbstractDataGridProperties implements ItemClickEvent.ItemClickListener { IndexedContainer container = new ClientDataContainer(); private HorizontalSplitPanel hsplit; private String clientModuleType; public ClientsDataGridProperties(HorizontalSplitPanel hsplit, String clientModuleType) { this.hsplit = hsplit; this.clientModuleType = clientModuleType; setSelectionMode(SelectionMode.SINGLE); setSizeFull(); setContainerDataSource(container); addItemClickListener(this); // Create a header row to hold column filters HeaderRow filterRow = appendHeaderRow(); // Set up a filter for all columns getContainerDataSource().getContainerPropertyIds().stream().filter((pid) -> (pid.equals("name"))) .forEach((pid) -> { HeaderCell cell = filterRow.getCell(pid); // Have an input field to use for filter TextField filterField = new TextField(); filterField.setWidth("100%"); filterField.addStyleName(ValoTheme.TEXTFIELD_TINY); filterField.setInputPrompt("Filter"); // Update filter When the filter input is changed filterField.addTextChangeListener(change -> { // Can't modify filters so need to replace container.removeContainerFilters(pid); // (Re)create the filter if necessary if (!change.getText().isEmpty()) container.addContainerFilter(new SimpleStringFilter(pid, change.getText(), true, true)); recalculateColumnWidths(); }); cell.setComponent(filterField); }); getColumn("name").setWidth(280); removeColumn("id"); } private HorizontalSplitPanel getHsplit() { return hsplit; } private String getClientModuleType() { return clientModuleType; } @Override public void itemClick(ItemClickEvent event) { Object itemId = event.getItemId(); Item item = getContainerDataSource().getItem(itemId); switch (getClientModuleType()) { case "promo": { hsplit.setSecondComponent(new PromoUI((int) item.getItemProperty("id").getValue())); break; } default: { hsplit.setSecondComponent(new ClientInformationForm(getHsplit(), CommonUtilities.convertStringToInt(item.getItemProperty("id").getValue().toString()))); break; } } } @Override public void populateDataGrid() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void gridRenrderersAndGenerator() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }